Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use Github API to disable the merge button on a pull request and reenable it using REST

I have developed my own web server that does automation on my android app. If there are issues when the automation runs, I want to programmatically disable the "merge" button on a github pull request using a cURL REST command. I cannot find out the proper way to do this but it seems that many people would benefit from this functionality.

The api for github pull requests can be found here: https://developer.github.com/v3/pulls/

I know that this is possible because if you have merge conflicts on your branch, the button gets grayed out and you cannot click/merge it. That is the exact functionality I am looking for. Any help would be much appreciated.

like image 620
Scott B Avatar asked Oct 30 '15 18:10

Scott B


1 Answers

This is possible. There are couple of steps you should take to enable this feature.

  1. Configure some of your branches (typically it's master or/and develop, depends on your workflow) as protected.
  2. Using Statuses API you can send Pending, Success, Error and Failure statuses. Pending,Error and Failed statuses will block Merge button.

Once it's done you can POST statuses based on your business rules.

POST /repos/:owner/:repo/statuses/:sha

:sha is the hash of the latest commit in the Pull Request

With payload like this one:

{
  "state": "success",
  "target_url": "https://link.to/some/repotring/page",
  "description": "Automation tests passed!",
  "context": "continuous-integration/automation-tests"
}

One thing is worth mentioning. When you have posted at least one status, the value from context filed will be shown on the protected branch settings page. Don't forget to mark this status as required:

Require status checks to pass before merging

Protected branches and required status checks

like image 104
Anton Sizikov Avatar answered Sep 26 '22 23:09

Anton Sizikov