Expediting Pull Request Merge with Reviewpad's Auto-Merge
Optimize your code review process with Reviewpad’s auto-merge feature. Focus on other vital things rather than waiting for merge requests to be accepted.
The Problem
Pull requests (PRs) are essential to the development process. They allow multiple people to collaborate and review code changes before they are merged into the target branch. However, this review process can take time and slow down the development cycle.
To speed things up, some organizations have turned to auto-merge. This article will look into a common use case for auto-merge. It automates the merge action after obtaining the approvals from specific users or teams that are required to merge a pull request. This can be extremely useful for changes to code that is not critical.
The Solution
Auto-merge triggers the merge process automatically as soon as the required approvals are received; bypassing manual merge and saving precious time. GitHub does not offer the ability to do this automatically.
To configure auto-merge on required approvals, we can use tools like Reviewpad.
In this case, we will configure Reviewpad to verify if a pull request has at least a specified number of approvals from a specific team. To better understand how auto-merge works, we will now look into a step-by-step guide for a use case of Reviewpad’s Auto-Merge feature.
Implementation
It is important to see a use case of auto-merge, so you can leverage this feature to its full potential to make the review process and the development cycle faster than before.
Consider a software development team working on a large-scale project with multiple branches and many developers. Here's how auto-merge can be used in this scenario:
- Code review and approval: All pull requests must undergo a thorough code review by designated team members to ensure that the changes align with the project's coding standards and do not introduce any bugs or errors. Usually this means that after the necessary reviews and approvals pull requests will sit still until someone reacts to a notification, or browses GitHub, and merges the pull request. Auto-merge can skip entirely this waiting time and merge the pull request as soon as the required reviews and approvals are in.
- Continuous Integration and Continuous Deployment (CI/CD): The team uses a CI/CD pipeline to automate the build, test, and deployment process. Auto-merge can be integrated into the pipeline to ensure that approved pull requests are automatically merged into the main code repository.
- Branches and merge policies: The team has multiple branches, such as development, staging, and production. To ensure that only stable and tested code is merged into each branch, the team has established a set of merge policies. Auto-merge can enforce these policies and ensure that only approved changes are merged into the appropriate branch.
In this tutorial, we will learn how a code review and approval process can be implemented with auto-merge using Reviewpad. As an example, we will consider a hypothetical organization that requires at least two approvals from a core team before merging critical changes into the codebase.
We will now create a workflow that checks if the Pull Request has critical code and is approved by two approvers before being merged automatically. This practice helps to reduce the risk of unintended consequences and ensures that multiple individuals thoroughly review important changes.
Step 1. Install the Reviewpad GitHub App and initialize Reviewpad.
Click here: Install Reviewpad ↗︎. If you need help please check the Installation guide ↗︎.
Step 2. Configure the Reviewpad workflow for auto-merge.
Add a Reviewpad workflow for the auto-merge feature, based on the use case discussed earlier, to the reviewpad.yml
file.
1workflows:2 - name: auto-merge-on-required-approvals3 description: Automerge after required approvals if no changes were made critical code4 always-run: true5 if:6 - '!$hasAnnotation("critical") && $hasRequiredApprovals(2, $team("core"))'7 then:8 - $merge()
This workflow then verifies if the pull request doesn't have changes to critical code, and if it has at least two approvals from the core team with the check $hasRequiredApprovals(2, $team("core"))
. If these conditions are met, Reviewpad automatically merges the pull request.
Now you can identify pieces of code that are critical to the project by adding the @reviewpad-an: critical
annotation, so when changes are proposed to critical code, the auto-merge-on-required-approvals
workflow is not triggered.
The Result
Once a pull request is made, the auto-merge-on-required-approvals
workflow is triggered.
As soon as the checks are passed by Reviewpad and the required approval is received the staging branch is merged into the main branch of the repository as seen below.
To learn more about Reviewpad, you can check out our documentation ↗︎.
Final Thoughts
Auto-merge on required approvals is a powerful feature for streamlining the pull request review process. Organizations can save time and resources by automating the merge process based on specific conditions and speeding up their development cycle. Reviewpad allows developers to focus on coding while Reviewpad merges approved pull requests. As such, it should be considered as an essential part of any organization’s development toolkit when conducting code reviews.