Issue
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.
Solution
This is possible. There are couple of steps you should take to enable this feature.
- Configure some of your branches (typically it's
master
or/anddevelop
, depends on your workflow) asprotected
. - Using Statuses API you can send
Pending
,Success
,Error
andFailure
statuses.Pending
,Error
andFailed
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/reporting/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:
Protected branches and required status checks
Answered By - Anton Sizikov Answer Checked By - Timothy Miller (WPSolving Admin)