'Get the status of a pull request's checks

How can I programmatically get the following information? (1 required check)

One required check

I've looked at the response for getting a Pull Request by Id but there's nothing in there from what I can see. I've tried getting a Pull Request Status but that just returns an empty array.



Solution 1:[1]

You can get it by retrieving a list of all the policy evaluation statuses for a specific pull request.

https://docs.microsoft.com/en-us/rest/api/azure/devops/policy/evaluations/list?view=azure-devops-rest-7.1

Solution 2:[2]

You actually need to get the information off the protected branch, not off the check itself. Here are some API details: https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch.

So the flow to solve this is:

  1. Check if the base branch for the PR is protected, and if so;
  2. Use the above endpoint to determine which checks are required;
  3. Compare the checks on the latest PR commit to the required checks determined in step 2.

You can also retrieve all pull requests matching a specified criteria.

GET https://dev.azure.com/{organization}/{project}/_apis/git/repositories/{repositoryId}/pullrequests?api-version=6.0

In addition, to get Pull Requests by Project is a good way for a try.

GET https://dev.azure.com/{organization}/{project}/_apis/git/pullrequests?api-version=6.0

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 eorll
Solution 2 Kangcheng Jin-MSFT