You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Azure DevOps:如何获取Pull Request的statusID以调用指定API?

获取Azure DevOps PR状态API所需的statusID方法

你调用的这个API是用来查询单个特定状态的,而statusId并非预先固定的参数,需要先通过以下方式获取:

  • 先调用不带statusId的PR状态列表API,获取该拉取请求下的所有状态条目:
    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/statuses?api-version=7.1-preview.1
    
  • 响应结果里的每个状态条目都会包含id字段,这个就是你需要的statusId。不同的id对应不同类型的状态(比如CI构建状态、代码检查状态等)。

如果已知状态的名称或上下文,还可以给列表API加过滤参数缩小范围:

  • 按名称过滤:
    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/statuses?api-version=7.1-preview.1&name={statusName}
    
  • 按上下文过滤:
    GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullRequests/{pullRequestId}/statuses?api-version=7.1-preview.1&context={contextValue}
    

举个例子,返回的单个状态条目结构大致如下,其中id就是目标statusId:

{
  "id": "123456",
  "name": "Continuous Integration",
  "context": {
    "name": "CI",
    "genre": "vsts-ci"
  },
  "state": "succeeded",
  // 其他相关字段
}

内容的提问来源于stack exchange,提问作者Salman

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 17:19:50