VSTS REST API-GIT-获取分支策略

时间:2018-10-31 12:53:37

标签: rest azure-devops

是否可以使用具有策略的VSTS中的REST API获取(git)分支的列表?

https://docs.microsoft.com/en-us/rest/api/vsts/git/refs/list

如果分支被锁定,则返回响应,但如果分支包含策略则返回。

1 个答案:

答案 0 :(得分:0)

您可以使用Policy API并获取包含所有分支以及策略的列表。

  

获取项目中策略配置的列表。

GET https://dev.azure.com/{organization}/{project}/_apis/policy/configurations?api-version=4.1

示例响应:

{
  "count": 3,
  "value": [
    {
      "createdBy": {
        "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
        "displayName": "Normal Paulk",
        "uniqueName": "fabrikamfiber16@hotmail.com",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
      },
      "createdDate": "2015-02-23T12:51:06.85754Z",
      "isEnabled": true,
      "isBlocking": true,
      "isDeleted": false,
      "settings": {
        "requiredReviewerIds": [
          "1d1dad71-f27c-4370-810d-838ec41efd41",
          "13272ea3-92ef-46d1-b77e-608ebbf3428b"
        ],
        "filenamePatterns": [
          "*/API*.cs",
          "sql/tables/*"
        ],
        "addedFilesOnly": false,
        "message": null,
        "scope": [
          {
            "refName": "refs/heads/master",
            "matchKind": "Exact",
            "repositoryId": null
          },
          {
            "refName": "refs/heads/releases/",
            "matchKind": "Prefix",
            "repositoryId": null
          },
          {
            "refName": "refs/heads/adventureworks",
            "matchKind": "Exact",
            "repositoryId": "49c1d4d0-be28-4f20-9e0a-4ecfafc39257"
          }
        ]
      },
      "_links": {
        "self": {
          "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17"
        },
        "policyType": {
          "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fd2167ab-b0be-447a-8ec8-39368250530e"
        }
      },
      "revision": 2,
      "id": 17,
      "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/17",
      "type": {
        "id": "fd2167ab-b0be-447a-8ec8-39368250530e",
        "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fd2167ab-b0be-447a-8ec8-39368250530e",
        "displayName": "Required reviewers"
      }
    },
    {
      "createdBy": {
        "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
        "displayName": "Normal Paulk",
        "uniqueName": "fabrikamfiber16@hotmail.com",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
      },
      "createdDate": "2015-02-23T12:51:06.8887894Z",
      "isEnabled": true,
      "isBlocking": false,
      "settings": {
        "minimumApproverCount": 1,
        "creatorVoteCounts": false,
        "scope": [
          {
            "refName": "refs/heads/master",
            "matchKind": "Exact",
            "repositoryId": null
          }
        ]
      },
      "_links": {
        "self": {
          "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/18"
        },
        "policyType": {
          "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd"
        }
      },
      "revision": 1,
      "id": 18,
      "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/18",
      "type": {
        "id": "fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
        "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/fa4e907d-c16b-4a4c-9dfa-4906e5d171dd",
        "displayName": "Minimum approval count"
      }
    },
    {
      "createdBy": {
        "id": "d6245f20-2af8-44f4-9451-8107cb2767db",
        "displayName": "Normal Paulk",
        "uniqueName": "fabrikamfiber16@hotmail.com",
        "url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/d6245f20-2af8-44f4-9451-8107cb2767db",
        "imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=d6245f20-2af8-44f4-9451-8107cb2767db"
      },
      "createdDate": "2015-02-23T12:51:06.935666Z",
      "isEnabled": true,
      "isBlocking": false,
      "settings": {
        "buildDefinitionId": 5,
        "scope": [
          {
            "refName": "refs/heads/features/",
            "matchKind": "Prefix",
            "repositoryId": null
          }
        ]
      },
      "_links": {
        "self": {
          "href": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19"
        },
        "policyType": {
          "href": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/0609b952-1397-4640-95ec-e00a01b2c241"
        }
      },
      "revision": 1,
      "id": 19,
      "url": "https://dev.azure.com/fabrikam/_apis/policy/configurations/19",
      "type": {
        "id": "0609b952-1397-4640-95ec-e00a01b2c241",
        "url": "https://dev.azure.com/fabrikam/1be3fc5b-c58c-4173-8fd7-6647d11eccd1/_apis/policy/types/0609b952-1397-4640-95ec-e00a01b2c241",
        "displayName": "Build"
      }
    }
  ]
}

refName部分的scope中,您可以看到带有策略的分支名称,在policyType中,您具有要获取的链接

策略类型描述。