Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automatically merge verified and tested GitHub Pull Requests

I'd like to automatically (i.e. from Jenkins) merge a GitHub pull request that has been approved by a person and has been tested successfully; in other words, when all THREE of these checkmarks are green:

Is this possible? I haven't found any documentation on an API for GitHub's new "changes approved" code review functionality.

like image 978
dgmltn Avatar asked Nov 02 '16 23:11

dgmltn


1 Answers

There is a new PullRequestReviewEvent webhook that is triggered when a review is submitted in a non-pending state. The body of the webhook contains the ["review"]["state"] field, which will be approved when all reviewers have approved the changes (i.e. when you get the green "changes approved" tick in the UI).

Combine this with the StatusEvent for the head SHA of your pull request to get the status checks from CI and so on, then finally check the "merge-ability" of the pull by requesting the pull request from the API:

GET /repos/:owner/:repo/pulls/:number

Once you have all three things, you can merge the pull request with:

PUT /repos/:owner/:repo/pulls/:number/merge

and appropriate payload parameters. Note you'll need the Accept: application/vnd.github.polaris-preview+json for some of the payload parameters as they are in a preview period.

like image 149
kfb Avatar answered Sep 23 '22 21:09

kfb