Merging Pull Requests on Requested Reviewers Approvals
A few weeks ago, a Mergify user came to us with the following problem:
When a pull request is opened, we usually assign a few reviewers to it using GitHub user interface. What we’d like, is the pull request to be merged as soon as those reviewers approved the pull request.
That sounds interesting! There are plenty of cases where you know who should review some code that has been sent and you want those people to approve, comment or reject the change.
With Mergify, it’s actually pretty easy to implement this condition, though it can appear to be a little tricky. Let me explain.
When you request a review in the GitHub UI, the requested reviewer gets stored in the review-requested variable. As soon as the user reviews the pull request, it gets removed from this variable.
That means that when review-requested is empty, we know that all the requested reviews has been done. The next condition to check is that we have at least one approving review, and no review requesting changes.
Let’s write this:
pull_request_rules:
- name: merge when all requested reviewers approved
conditions:
- "#approved-reviews-by>=1"
- "#review-requested=0"
- "#changes-requested-reviews-by=0"
- "#commented-reviews-by=0"
actions:
merge:
method: merge
And voilà, as long as there is no comment, no request for changes, no review requested and at least one approving review, the pull request will be merged!
If you have any other fancy workflow for automatic merges, feel free to share them here. We’ll add the best ones to the documentation examples!