Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get if pull request passed all required status checks using GitHub API

I need to check via GitHub API if a pull request passed all required status checks. I use GitHub Enterprise 2.8 at this moment.

I know that I can get all status checks for last commit (following statuses_url in pull request). However, I don't know which status checks are set up to be required in a given repository. This is my main problem.

I also need to aggregate these status checks, group them by context and take latest in each context. It's ok, but seems to be reimplementation of logic, that GitHub performs internally when decides if a pull request can be merged.

For my case, it would be ideal to have something like can_be_merged in pull request fields, which meaning is mergeable && all required status checks passed && approved, but as far as I know there is no such field.

like image 712
algebraic Avatar asked Jun 28 '26 21:06

algebraic


1 Answers

Finally solved this! 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.
like image 76
moustachio Avatar answered Jun 30 '26 16:06

moustachio