【问题标题】:How to call PullRequestQuery Azure Git API?如何调用 PullRequestQuery Azure Git API?
【发布时间】:2021-11-03 19:37:06
【问题描述】:

我很难调用 PullRequestQuery API,有人可以帮忙吗? 我的目标是让 PR 与提交哈希相关联。 为此,我正在使用以下 API。

PullRequestQuery API

POST https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequestquery?api-version=6.0

有身体:

{
    "queries": [
        {
            "type": "commit",
            "items": [
                "d59420dc1d42d54ba89ddc8731800244c351f75b",
                "e093410f49dded0c6e9703a61aca0fa0f668a78e",
                "8e3eb7f090a75cc36c9d6e649993dcd0ac6bd232",
                "c9eda1e777aec0226185b766f8d680489f2f6119",
                "73d2986aba3c9e4c44ee265765299f1dfec20c95"
            ]
        }
    ],
    "results": [
        {}
    ]
}

每当我使用上述主体调用此 API 时,我都会得到与主体相同的响应。而且,它的状态显示为“201 created”。

【问题讨论】:

    标签: azure api rest azure-devops azure-devops-rest-api


    【解决方案1】:

    如何调用 PullRequestQuery Azure Git API?

    要使用这个REST API,我们需要注意以下三点

    1. 请求正文中的提交 ID 需要来自 已完成 PR。换句话说,我们只能使用此 REST API 来查询与提交哈希关联的已完成 PR。

    2. 当您选择合并类型Squash 合并时,此 REST API不起作用,请尝试选择选项Merge (no fast forward)

    3. 提交项不能包含合并提交。

      比如PR有3个commit,最新的一个e9bff8e1是merge commit:

    我的测试结果(上图中的提交 id 为 2 3d0cfa96):

    【讨论】:

    • 感谢您查看我的查询并传递宝贵的意见,Leo。我已经发布了这个特定问题的答案。
    【解决方案2】:

    “Leo Liu”传递的信息非常有用。但是,问题出在 API 调用期间的正文中。如果我将 type 作为 lastMergeCommit 而不是 commit,它会起作用。

    {
        "queries": [
            {
                "type": "lastMergeCommit",
                "items": [
                    "d59420dc1d42d54ba89ddc8731800244c351f75b",
                    "e093410f49dded0c6e9703a61aca0fa0f668a78e",
                    "8e3eb7f090a75cc36c9d6e649993dcd0ac6bd232",
                    "c9eda1e777aec0226185b766f8d680489f2f6119",
                    "73d2986aba3c9e4c44ee265765299f1dfec20c95"
                ]
            }
        ],
        "results": [
            {}
        ]
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-04
      • 1970-01-01
      • 2021-10-20
      • 1970-01-01
      相关资源
      最近更新 更多