SvanBoxel / auto-merge

A nifty little app that automatically merges your PRs when everything is green so you don't have to. 🎳

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Build Status codecov SonarCloud Greenkeeper badge

Auto Merge PRs

A nifty little app built with Probot that automatically merges your PRs when everything is green so you don't have to.

How it works

Code reviews often rely on three aspects: The submitter of the PR, the reviewers, and CI. Writing the code, submitting the PR, and reviewing the PR is a manual process that needs human eyes and brains. The process of CI, however, is something we automate for a reason. It is the place where we do sanity checks and make sure nothing terrible happens to our beautiful software projects. And for a good reason.

Because of this, the following situation can arise: You as a developer developed a new feature and submitted a PR. After some back-and-forth with your team members, the PR gets approved. The only dependency now is the not-so-fast CI, which is still running on your PR. This forces you to revisit your PR later that day to check if CI is green so that you can click the merge button.

This app does exactly that for you. As soon as your PR is approved, and CI passes, the PR gets merged automatically.

The current iteration of the app also auto-merges when CI already is green and a reviewer approves your PR after that. The bottem-line is that the moment everything turns green (Status checks, reviewers and other enforced branch protection rules), this app merges your PR.

This app also adheres to your branch (protection) settings. e.g., if you require at least two reviewers, it won't auto-merge the PR if only one reviewer approves it.

Configuration

In 3 steps this app can be used in your project.

  1. Go to GitHub Apps and install this ProBot app.
  2. (optional but recommended) create a .github/auto-merge-settings.yml file. (see template below) This config file supports two options:
    • merge_method merge/squash/rebase, default: merge, more info
    • strategy: all/label, default: label, apply this auto-merge functionality to all PRs, or only the PR with a auto-merge label
  3. Open a pull request and add the auto-merge label to your PR. (not needed if strategy is all)
merge_method: 'squash' # merge/squash/rebase
strategy: 'label' # all/label

Running it locally

  1. First, follow these instructions for making your own GitHub app.

Give your app the following permissions:

Category Permission Why
Repository contents Read & Write to perform merges
Repository metadata Read to read config file
Pull Requests Read to read labels
Commit Statuses Read to read status checks
  1. Then, clone the repo:
git clone git@github.com:SvanBoxel/auto-merge.git
  1. Copy .env.example to .env and set the right environment variables as here

  2. Now, install app dependencies and run it:

# Install dependencies
npm install

# Run the bot
npm start

Contributing

If you have suggestions for how auto-merge could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

License

ISC © 2018 Sebass van Boxel hello@svboxel.com

About

A nifty little app that automatically merges your PRs when everything is green so you don't have to. 🎳

License:ISC License


Languages

Language:JavaScript 100.0%