如何使用REST Api在Azure DevOps中获取与Git提交相关的工作项?

时间:2019-01-15 18:33:50

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

我的问题与年龄超过1岁的Get latest Associated Work Items for Git Commit using TFS REST API有关。

我也想获得与Git Commit相关的所有工作项。找不到相应的API。但是1年是很多时间,也许现在已经存在了?

1 个答案:

答案 0 :(得分:0)

您可以将Get Commits API与可选参数searchCriteria.includeWorkItems=true一起使用,您将获得所有提交及其关联的工作项。

例如:

https://dev.azure.com/{org}/{project}/_apis/git/repositories/{repoId}/commits?searchCriteria.includeWorkItems=true&?api-version=5.0-preview.1

结果(您将获得所有提交,可以使用PowerShell过滤结果):

  "commitId": "60a69554c80839d631e77ea0exxxxxxxxxxx",
  "author": {
    "name": "Shayki Abramczyk",
    "email": "email@gmail.com",
    "date": "2018-10-11T14:27:55Z"
  },
  "committer": {
    "name": "Shayki Abramczyk",
    "email": "email@gmail.com",
    "date": "2018-10-11T14:27:55Z"
  },
  "comment": "Updated README.md",
  "changeCounts": {
    "Add": 0,
    "Edit": 1,
    "Delete": 0
  },
  "url": "https://dev.azure.com/shaykia/7fcdafd5-b891-4fe5-b2fe-xxxxxxxxxx/_apis/git/repositories/815cc0c7-5f3e-404b-8fd7-xxxxxx/commits/60a69554c80839d631e77eaxxxxxxxx",
  "remoteUrl": "https://dev.azure.com/shaykia/xxxxxxx/_git/GitSample/commit/60a69554c80839d631e77ea0ed8bxxxxxxxx",
  "workItems": [
    {
      "id": "18",
      "url": "https://dev.azure.com/shaykia/_apis/wit/workItems/18"
    }
  ]
},

很遗憾,Get (one) Commit API中不存在此选项。