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

如何通过RestAPI从Azure DevOps Services特定分支获取“必需审阅者”?

获取Azure DevOps分支策略中的必需审阅者信息
  • 调用分支策略列表API,指定组织、项目及所需参数:
    GET https://dev.azure.com/{organization}/{project}/_apis/policy/configurations?api-version=7.1-preview.1
    可通过repositoryId过滤特定仓库,或branch参数过滤目标分支的策略。

  • 在返回结果中定位type.id为e7e44c26-807d-472a-b121-4e58b65d3e9a的条目——这是“必需审阅者”策略的固定标识ID。

  • 该策略的settings字段包含审阅者核心信息:

    • requiredReviewerIds:存储用户或团队的ID列表
    • 要获取对应的姓名/团队名称,需调用身份查询API:
      • 查询用户信息:GET https://dev.azure.com/{organization}/_apis/identities?ids={userId}&api-version=7.1-preview.1
      • 查询团队信息:GET https://dev.azure.com/{organization}/{project}/_apis/teams/{teamId}?api-version=7.1-preview.3
  • 简单处理逻辑示例(伪代码):

    # 假设已获取分支策略响应数据
    for policy in policy_response["value"]:
        if policy["type"]["id"] == "e7e44c26-807d-472a-b121-4e58b65d3e9a":
            reviewer_ids = policy["settings"]["requiredReviewerIds"]
            for rid in reviewer_ids:
                # 调用身份API获取名称
                identity_info = call_azure_api(f"https://dev.azure.com/{org}/_apis/identities?ids={rid}&api-version=7.1-preview.1")
                print(identity_info["value"][0]["displayName"])
    

如果策略包含“允许请求者自我批准”“需要所有审阅者批准”等附加规则,这些配置也会在settings字段中给出,可按需提取。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.02 23:30:54