JoeGaggler
JoeGaggler

Reputation: 1236

Get pull request attached to work item

I would like to access information about all pull requests that are linked to a particular work item.

The relations on a work item result (e.g. https://.../_apis/wit/workItems/12345?$expand=all) shows links to the pull requests in this form:

vstfs:///Git/PullRequestId/...

How can I turn that relationship URI into the canonical URL for the pull request using the VSTS REST API? (e.g. https://.../_apis/git/repositories/.../pullRequests/1234)

Upvotes: 6

Views: 2282

Answers (1)

Marina Liu
Marina Liu

Reputation: 38106

To parse information of the GET Pull Request REST API from the response of GET work item REST API, you just need to get the pull request id.

From the response of the GET work item REST API, you can get the pull request URL as:

vstfs:///Git/PullRequestId/f7855e29-6f8d-429d-8c9b-41fd4d7e70a4%2Fe89075b8-d7bd-4c3f-b24c-23276d89e8ec%2F106

Then get the pull request, you can split the string with %2F, then the pull request id is the last part (as the pull request id is 106 in above example).

And to get the pull request detail by the rest api as below:

GET https://{account}.visualstudio.com/_apis/git/pullrequests/{pullrequestID}?api-version=4.1

Upvotes: 10

Related Questions