Azure DevOps Rest API - 按 tag/label 列出拉取请求
Azure DevOps Rest API - List pull requests by tag/label
有什么方法可以查询 Azure DevOps 的 REST API 以 return 给我一个带有特定标签/标签的拉取请求列表?
在没有太多帮助的情况下一直在查看此处的文档:https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/get%20pull%20requests?view=azure-devops-rest-6.0
根据 Get Pull Requests documentation, we can add some search criteria in the URI Parameters, but currently label is not available. If you would like that feature, please use this link 并为此功能创建请求。这将允许您直接与相应的产品组进行交互,并使产品组更方便地收集和分类您的建议。
作为解决方法,我们可以过滤 API 的结果。请检查以下 powershell 脚本是否满足您的需求。我在示例中使用了 Get Pull Requests api and Get Pull Request By Id api(请更改注释值):
$organization = "{organization name}" // organization name
$project = "{project name}" // project name
$repo = "{repo name}" // repo name
$pat = "{PAT}" //PAT
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
$baseUrl = "https://dev.azure.com/$organization/$project/_apis/git/repositories/$repo /pullrequests?&api-version=6.0"
$pullrequestlist = Invoke-RestMethod -Uri $baseUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
$pullrequestid = @()
foreach($prid in $pullrequestlist.value){
$childprid = $prid.labels | Where-Object{$_.name -eq "{label name}" } | select $prid.url //label name
$pullrequestid += $childprid | foreach{$prid.url.split("/")[-1]}
}
foreach($prid2 in $pullrequestid){
write-host $prid2
$baseUrl2 = "https://dev.azure.com/$organization/$project/_apis/git/pullrequests/$($prid2)?api-version=6.0"
$pullrequestlist2 = Invoke-RestMethod -Uri $baseUrl2 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
write-host $pullrequestlist2
}
这是我的结果:
有什么方法可以查询 Azure DevOps 的 REST API 以 return 给我一个带有特定标签/标签的拉取请求列表?
在没有太多帮助的情况下一直在查看此处的文档:https://docs.microsoft.com/en-us/rest/api/azure/devops/git/pull%20requests/get%20pull%20requests?view=azure-devops-rest-6.0
根据 Get Pull Requests documentation, we can add some search criteria in the URI Parameters, but currently label is not available. If you would like that feature, please use this link 并为此功能创建请求。这将允许您直接与相应的产品组进行交互,并使产品组更方便地收集和分类您的建议。
作为解决方法,我们可以过滤 API 的结果。请检查以下 powershell 脚本是否满足您的需求。我在示例中使用了 Get Pull Requests api and Get Pull Request By Id api(请更改注释值):
$organization = "{organization name}" // organization name
$project = "{project name}" // project name
$repo = "{repo name}" // repo name
$pat = "{PAT}" //PAT
$base64AuthInfo = [Convert]::ToBase64String([Text.Encoding]::ASCII.GetBytes(("{0}:{1}" -f "", $pat)))
$baseUrl = "https://dev.azure.com/$organization/$project/_apis/git/repositories/$repo /pullrequests?&api-version=6.0"
$pullrequestlist = Invoke-RestMethod -Uri $baseUrl -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
$pullrequestid = @()
foreach($prid in $pullrequestlist.value){
$childprid = $prid.labels | Where-Object{$_.name -eq "{label name}" } | select $prid.url //label name
$pullrequestid += $childprid | foreach{$prid.url.split("/")[-1]}
}
foreach($prid2 in $pullrequestid){
write-host $prid2
$baseUrl2 = "https://dev.azure.com/$organization/$project/_apis/git/pullrequests/$($prid2)?api-version=6.0"
$pullrequestlist2 = Invoke-RestMethod -Uri $baseUrl2 -Headers @{Authorization=("Basic {0}" -f $base64AuthInfo)} -Method GET
write-host $pullrequestlist2
}
这是我的结果: