5

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

enter image description here

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
riQQ
  • 9,878
  • 7
  • 49
  • 66
Zam
  • 1,121
  • 10
  • 27

1 Answers1

10

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:

enter image description here

Mengdi Liang
  • 17,577
  • 2
  • 28
  • 35
  • 1
    I'm adding this comment because I came in a little differently, and Google didn't get me here. This approach is also how you would get associated pull requests and related work items. They are just different relation types. – drdwilcox Jul 28 '20 at 18:19