Azure DevOps get commits linked to a work item via the REST API

ⅰ亾dé卋堺 提交于 2021-01-27 06:36:49

问题


Is there a way to get Git Commits that are linked to a work item given only the work item ID?

I'm using PowerShell and this URI to get work items, but I don't see any of the linked commits on the returned object. I also don't see any documentation on how to get these links.

$Results = Invoke-RestMethod -Uri "http://azuredevops/azuredevops/Collection/Project/_apis/wit/workitems?api-version=5.1&ids=1" -Method "GET" -UseDefaultCredentials | Select-Object -ExpandProperty Value
$Results.fields

回答1:


You are very close to the correct solution.

The commits which linked to the work item is relation of work item. So, here, you need to specify $expand in API to get the corresponding commits content.

Get https://dev.azure.com/{org name}/{project name}/_apis/wit/workitems/{id}?$expand=relations&api-version=5.1

Then you would see the commits in relations part of the response body:



来源:https://stackoverflow.com/questions/59275593/azure-devops-get-commits-linked-to-a-work-item-via-the-rest-api

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!