gpt4 book ai didi

azure - 如何检索链接到特定提交的工作项 - Azure Devops REST API

转载 作者:行者123 更新时间:2023-12-02 06:43:41 24 4
gpt4 key购买 nike

我需要能够检索任何给定特定提交的链接工作项。我当前正在使用以下 api 调用

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits/{commitId}?api-version=5.0

响应如下

{
"parents": [],
"treeId": "7fa1a3523ffef51c525ea476bffff7d648b8cb3d",
"push": {
"pushedBy": {
"id": "8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"displayName": "Chuck Reinhart",
"uniqueName": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="7f191e1d0d16141e1219161d1a0d4c3f17100b121e1613511c1012" rel="noreferrer noopener nofollow">[email protected]</a>",
"url": "https://vssps.dev.azure.com/fabrikam/_apis/Identities/8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d",
"imageUrl": "https://dev.azure.com/fabrikam/_api/_common/identityImage?id=8c8c7d32-6b1b-47f4-b2e9-30b477b5ab3d"
},
"pushId": 1,
"date": "2014-01-29T23:33:15.2434002Z"
},
"commitId": "be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"author": {
"name": "Chuck Reinhart",
"email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="25434447574c4e4448434c47405716654d4a5148444c490b464a48" rel="noreferrer noopener nofollow">[email protected]</a>",
"date": "2014-01-29T23:32:09Z"
},
"committer": {
"name": "Chuck Reinhart",
"email": "<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="45232427372c2e2428232c27203776052d2a3128242c296b262a28" rel="noreferrer noopener nofollow">[email protected]</a>",
"date": "2014-01-29T23:32:09Z"
},
"comment": "First cut\n",
"url": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"remoteUrl": "https://dev.azure.com/fabrikam/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4",
"_links": {
"self": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"repository": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249"
},
"changes": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/commits/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4/changes"
},
"web": {
"href": "https://dev.azure.com/fabrikam/_git/Fabrikam-Fiber-Git/commit/be67f8871a4d2c75f13a51c1d3c30ac0d74d4ef4"
},
"tree": {
"href": "https://dev.azure.com/fabrikam/_apis/git/repositories/278d5cd2-584d-4b63-824a-2ba458937249/trees/7fa1a3523ffef51c525ea476bffff7d648b8cb3d"
}
}
}

来自 https://learn.microsoft.com/en-us/rest/api/azure/devops/git/commits/get?view=azure-devops-rest-5.0并且缺少查看其链接到哪个工作项或是否已链接的方法。有谁知道如何获取此信息?谢谢

最佳答案

您可以使用获取提交 API,docs here 。基本请求如下所示:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?api-version=5.0

然后您可以添加以下参数:

  • fromCommitId - 字符串 - 如果提供,则按字母顺序过滤提交的下限
  • toCommitId - 字符串 - 如果提供,则按字母顺序过滤提交的上限
  • includeWorkItems - bool 值 - 是否包含链接的工作项

这样你的最终查询看起来就像这样,你的 toCommitId 和 fromCommitId 参数是你之后的提交 ID(文档没有具体说明这些是包含的还是排除的,所以你可能需要稍微调整一下):

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?includeWorkItems=true&.toCommitId={searchCriteria.toCommitId}&fromCommitId={searchCriteria.fromCommitId}&api-version=5.0

结果应根据 this documentation 在响应的每个提交对象内包含一个 workItems 属性.

注意:

Parameters that use the searchCriteria prefix in their name can be specified without it as query parameters, e.g. searchCriteria.$top -> $top

<小时/>

还有:

  • ids - 数组 - 如果提供,则指定要获取的提交的确切提交 ID。不得与其他参数结合使用。

可以允许您放弃传入和传出提交 ID,但文档指出它不能与其他参数组合 - 即使示例请求确实将其与其他参数结合起来。我自己还没有尝试过,所以当您发现您是否使用 from-to id 还是仅使用 id 时,请发表评论。

<小时/>

OP 操作

OP 最终使用了以下请求,因为他们不介意返回所有提交:

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/commits?includeWorkItems=true&api-version=5.0

关于azure - 如何检索链接到特定提交的工作项 - Azure Devops REST API,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56716598/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com