6

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)

1 Answer 1

10

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
1
  • A regular expression to get the id in the first group of the response would be: PullRequestId\/.*%2F(\d+)",
    – Joniale
    Apr 5, 2023 at 13:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.