您可以使用下面的Rest api 来获取 PR 审稿人。
1、首先调用build rest api下面的buildId。在响应中,您将从构建的 sourceVersion 和存储库 id 中获取提交 id。
GET https://dev.azure.com/{organization}/{project}/_apis/build/builds/{buildId}?api-version=5.1
2,在获得提交ID和存储库ID之后。您可以调用 commit rest api 从响应中的 cmets 获取关联的 PR id。
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.1
3、然后调用pullrequest reviewer rest api获取Reviewers。
GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/reviewers?api-version=5.1
以下是 powershell 中的示例脚本。请参阅this link 以获取个人访问令牌
$buildId= " "
$burl =" https://dev.azure.com/OrgName/ProjName/_apis/build/builds/$($buildId)?api-version=5.1"
$PAT="personel access token"
$base64AuthInfo= [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes(":$($PAT)"))
$buildInfo = Invoke-RestMethod -Uri $curl -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo1)} -Method get -ContentType "application/json"
#get CommitId and repoId
$commitId = $buildInfo.sourceVersion
$repoId=$buildInfo.repository.id
#commit rest api
$curl = "https://dev.azure.com/OrgName/ProjName/_apis/git/repositories/$($repoId)/commits/$($commitId)?api-version=5.1"
$commitInfo = Invoke-RestMethod -Uri $curl -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo1)} -Method get -ContentType "application/json"
#get PR id
$prId = $commitInfo.comment.split(" ")[2].TrimEnd(":")
$prurl = "https://dev.azure.com/OrgName/ProjName/_apis/git/repositories/$($repoId)/pullRequests/$($prId)/reviewers?api-version=5.1"
Invoke-RestMethod -Uri $prurl -Headers @{Authorization = ("Basic {0}" -f $base64AuthInfo1)} -Method get -ContentType "application/json"
如果您可以使用给定的 buildId 从 UI 页面中的管道运行历史记录中找到构建。这会容易得多。您可以直接从标题中获取 PR id。见下图。
您也可以单击上面屏幕截图中显示的提交 ID,查看提交的详细信息,您将在其中获得相关的 PR。