Skip to content

GitHub action which enables the auto merge function when someone requests it through a comment

License

Notifications You must be signed in to change notification settings

paritytech/auto-merge-bot

Repository files navigation

Auto-Merge-Bot

Bot which enables or disable auto-merge in a repository.

Why?

This action was developed to help external parties merge their own Pull Requests.

If an external party makes a PR, and it is approved, they still cannot merge it. This bot gives them the ability to enable the auto-merge function so, once their PR gets approved, it is merged.

Configuration

Be sure that Allow auto-merge is enabled in the repository options.

Create a file named .github/workflows/auto-merge-bot.yml and add the following:

name: Auto Merge Bot

on:
  # GitHub considers PRs as issues
  issue_comment:
    types: [created]

jobs:
  set-auto-merge:
    runs-on: ubuntu-latest
    # Important! This forces the job to run only on comments on Pull Requests that starts with '/merge'
    if: ${{ github.event.issue.pull_request && startsWith(github.event.comment.body, '/merge') }}
    steps:
      - name: Set auto merge
        uses: paritytech/auto-merge-bot@main
        with:
          GITHUB_TOKEN: '${{ github.token }}'
          MERGE_METHOD: "SQUASH"
          ALLOW_UNSTABLE: true

Inputs

You can find all the inputs in the action file, but let's walk through each one of them:

  • GITHUB_TOKEN: Token to access to the repository.
    • required
    • This is provided by the repo, you can simply use ${{ github.token }}.
  • MERGE_METHOD: Type of merge to enable.
    • Optional: Defaults to SQUASH.
    • Available types are MERGE, REBASE and SQUASH.
      • Make sure that the type of merge you selected is available in the repository merge options.
  • SILENT: If the bot should be silent and not comment when enabling/disabling auto-merge.
    • Optional: Defaults to false.
  • ALLOWLIST: List of user accounts which are allowed to use the bot aside from the author and org members.
    • Optional
    • Must be a comma separated value: user-1,user-2,user-3.
  • ALLOW_UNSTABLE: If unstable, ready to merge, PRs can be merged
    • An unstable PR is a PR that can be merged, but a non required status check is failing.
      • This is only relevant once the PR can be merged. GitHub's auto-merge always merges unstable PRs
    • Optional: Defaults to true
  • UPDATE_BEFORE_MERGE: If the bot should try to update the PR to be up to date before enabling auto-merge
    • Optional: Defaults to false

Usage

To trigger the bot, you need to write a comment in a Pull Request where the action is installed. The available actions are:

  • /merge: Enables auto-merge for Pull Request
  • /merge cancel: Cancels auto-merge for Pull Request
  • /merge help: Shows this menu

The bot can only be triggered by the author of the PR or by users who publicly belongs to the organization of the repository.

By publicly, I refer to the members of an organization which can be seen by external parties. If you are not sure if you are part of an organization, simply open https://github.com/orgs/**your_organization**/people in a private window. If you don’t see your name there, you are not a public member.

Find related docs here: Publicizing or hiding organization membership.

Deployment

To deploy a new version you need to update two files:

  • package.json: Update the version number.
  • action.yml: Update the image number in runs.image. Important: Both versions must have the same number.

When a commit is pushed to the main branch and the versions have changed, the system will automatically tag the commit and release a new package with such version.

You can find all the available versions in the release section.

About

GitHub action which enables the auto merge function when someone requests it through a comment

Resources

License

Security policy

Stars

Watchers

Forks

Packages