All Projects → pascalgn → Automerge Action

pascalgn / Automerge Action

Licence: mit
GitHub action to automatically merge pull requests that are ready

Programming Languages

javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to Automerge Action

Simonw
https://simonwillison.net/2020/Jul/10/self-updating-profile-readme/
Stars: ✭ 297 (-33.41%)
Mutual labels:  github-api
Leethub
Automatically sync your leetcode solutions to your github account - top 5 trending GitHub repository
Stars: ✭ 316 (-29.15%)
Mutual labels:  github-api
Hukum
An NPM module that displays Github Action progress in the terminal and aims to improve your development experience by printing status in realtime.
Stars: ✭ 375 (-15.92%)
Mutual labels:  github-api
Github Wrapped
Take a look back at all the contributions you as an individual made to the open-source community
Stars: ✭ 304 (-31.84%)
Mutual labels:  github-api
Kafka Connect Github Source
Get a stream of issues and pull requests for your chosen GitHub repository
Stars: ✭ 327 (-26.68%)
Mutual labels:  github-api
Gitter
Gitter for GitHub - 可能是目前颜值最高的GitHub微信小程序客户端
Stars: ✭ 3,498 (+684.3%)
Mutual labels:  github-api
Ghcrawler
Crawl GitHub APIs and store the discovered orgs, repos, commits, ...
Stars: ✭ 293 (-34.3%)
Mutual labels:  github-api
Octokat.js
Github API Client using Promises or callbacks. Intended for the browser or NodeJS.
Stars: ✭ 401 (-10.09%)
Mutual labels:  github-api
Octokit.swift
A Swift API Client for GitHub and GitHub Enterprise
Stars: ✭ 325 (-27.13%)
Mutual labels:  github-api
Ok.sh
A Bourne shell GitHub API client library focused on interfacing with shell scripts
Stars: ✭ 365 (-18.16%)
Mutual labels:  github-api
Gitify
GitHub notifications on your menu bar. Available on macOS, Windows & Linux.
Stars: ✭ 3,543 (+694.39%)
Mutual labels:  github-api
Astronomer
A tool to detect illegitimate stars from bot accounts on GitHub projects
Stars: ✭ 323 (-27.58%)
Mutual labels:  github-api
This Repo Has 350 Stars
Yes, it's true 💕 This repository has 350 stars.
Stars: ✭ 350 (-21.52%)
Mutual labels:  github-api
Github Rs
Pure Rust bindings to the Github API
Stars: ✭ 298 (-33.18%)
Mutual labels:  github-api
Profile Summary For Github
Tool for visualizing GitHub profiles
Stars: ✭ 19,489 (+4269.73%)
Mutual labels:  github-api
Shhgit
Ah shhgit! Find secrets in your code. Secrets detection for your GitHub, GitLab and Bitbucket repositories: www.shhgit.com
Stars: ✭ 3,316 (+643.5%)
Mutual labels:  github-api
Octokit.rb
Ruby toolkit for the GitHub API
Stars: ✭ 3,522 (+689.69%)
Mutual labels:  github-api
Pygithub
Typed interactions with the GitHub API v3
Stars: ✭ 4,825 (+981.84%)
Mutual labels:  github-api
Gittrends
A iOS and Android app to monitor the views and clones of your GitHub repos
Stars: ✭ 388 (-13%)
Mutual labels:  github-api
Github Stats
Better GitHub statistics images for your profile, no external server required
Stars: ✭ 338 (-24.22%)
Mutual labels:  github-api

automerge-action

GitHub action to automatically merge pull requests when they are ready.

When added, this action will run the following tasks on pull requests with the automerge label:

  • Changes from the base branch will automatically be merged into the pull request (only when "Require branches to be up to date before merging" is enabled in the branch protection rules)
  • When the pull request is ready, it will automatically be merged. The action will only wait for status checks that are marked as required in the branch protection rules
  • Pull requests without any configured labels will be ignored

Labels, merge and update strategies are configurable, see Configuration.

A pull request is considered ready when:

  1. the required number of review approvals has been given (if enabled in the branch protection rules) and
  2. the required checks have passed (if enabled in the branch protection rules) and
  3. the pull request is up to date (if enabled in the branch protection rules)

After the pull request has been merged successfully, the branch will not be deleted. To delete branches after they are merged, see automatic deletion of branches.


This functionality is now available directly in GitHub as auto-merge. The automerge-action project will still be maintained, but users are encouraged to switch to auto-merge for simple workflows, as it offers a faster and more stable experience.

Usage

Create a new .github/workflows/automerge.yml file:

name: automerge
on:
  pull_request:
    types:
      - labeled
      - unlabeled
      - synchronize
      - opened
      - edited
      - ready_for_review
      - reopened
      - unlocked
  pull_request_review:
    types:
      - submitted
  check_suite:
    types:
      - completed
  status: {}
jobs:
  automerge:
    runs-on: ubuntu-latest
    steps:
      - name: automerge
        uses: "pascalgn/[email protected]"
        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"

For the latest version, see the list of releases.

Configuration

The following merge options are supported:

  • MERGE_LABELS: The labels that need to be present for a pull request to be merged (using MERGE_METHOD). The default value is automerge.

    This option can be a comma-separated list of labels that will be checked. All labels in the list need to be present, otherwise the pull request will be skipped (until all labels are present). Labels prefixed with an exclamation mark (!) will block a pull request from being merged, when present.

    For example, when automerge,!wip,!work in progress is given, any pull requests with the labels wip or work in progress and any pull requests without the label automerge will not be merged. Blocking labels take precedence, so if a pull request has both labels wip and automerge, it will not be merged.

    When an empty string ("") is given, all pull requests will be merged.

  • MERGE_REMOVE_LABELS: The labels to automatically remove from a pull request once it has been merged by the action. The default value is "".

    This option can be a comma-separated list of labels that will be removed.

    When an empty string ("") is given, no labels will be removed.

  • MERGE_METHOD: Which method to use when merging the pull request into the base branch. Possible values are merge (create a merge commit), rebase (rebase all commits of the branch onto the base branch) or squash (squash all commits into a single commit). The default option is merge.

  • MERGE_METHOD_LABELS: Set to allow labels to determine the merge method (see MERGE_METHOD for possible values). For example, automerge=merge,autosquash=squash. If no such label is present, the method set by MERGE_METHOD will be used. The default value is "".

  • MERGE_METHOD_LABEL_REQUIRED: Set to true to require one of the MERGE_METHOD_LABELS to be set. The default value is false.

  • MERGE_COMMIT_MESSAGE: The commit message to use when merging the pull request into the base branch. Possible values are automatic (use GitHub's default message), pull-request-title (use the pull request's title), pull-request-description (use the pull request's description), pull-request-title-and-description or a literal value with optional placeholders (for example Auto merge {pullRequest.number}). The default value is automatic.

  • MERGE_COMMIT_MESSAGE_REGEX: When using a commit message containing the PR's body, use the first capturing subgroup from this regex as the commit message. Can be used to separate content that should go with the commit into the code base's history from boilerplate associated with the PR (licensing notices, check lists, etc). For example, (.*)^--- would keep everything up until the first 3-dash line (horizontal rule in MarkDown) from the commit message. The default value is empty, which disables this feature.

  • MERGE_FILTER_AUTHOR: When set, only pull requests raised by this author will be merged automatically.

  • MERGE_FORKS: Whether merging from external repositories is enabled or not. By default, pull requests with branches from forked repositories will be merged the same way as pull requests with branches from the main repository. Set this option to false to disable merging of pull requests from forked repositories. The default value is true.

  • MERGE_RETRIES and MERGE_RETRY_SLEEP: Sometimes, the pull request check runs haven't finished yet, so the action will retry the merge after some time. The number of retries can be set with MERGE_RETRIES. The default number of retries is 6 and setting it to 0 disables the retry logic. MERGE_RETRY_SLEEP sets the time to sleep between retries, in milliseconds. The default is 5000 (5 seconds) and setting it to 0 disables sleeping between retries.

  • MERGE_DELETE_BRANCH: Automatic deletion of branches does not work for all repositories. Set this option to true to automatically delete branches after they have been merged. The default value is false.

The following update options are supported:

  • UPDATE_LABELS: The labels that need to be present for a pull request to be updated (using UPDATE_METHOD). The default value is automerge.

    Note that updating will only happen when the option "Require branches to be up to date before merging" is enabled in the branch protection rules.

    This option can be a comma-separated list of labels, see the MERGE_LABELS option for more information.

  • UPDATE_METHOD: Which method to use when updating the pull request to the base branch. Possible values are merge (create a merge commit) or rebase (rebase the branch onto the head of the base branch). The default option is merge.

    When the option is rebase and the rebasing failed, the action will exit with error code 1. This will also be visible in the pull request page, with a message like "this branch has conflicts that must be resolved" and a list of conflicting files.

  • UPDATE_RETRIES and UPDATE_RETRY_SLEEP: Sometimes, the pull request check runs haven't finished yet and the action doesn't know if an update is necessary. To query the pull request state multiple times, the number of retries can be set with UPDATE_RETRIES. The default number of retries is 1 and setting it to 0 disables the retry logic. UPDATE_RETRY_SLEEP sets the time to sleep between retries, in milliseconds. The default is 5000 (5 seconds) and setting it to 0 disables sleeping between retries.

Also, the following general options are supported:

  • GITHUB_TOKEN: This should always be "${{ secrets.GITHUB_TOKEN }}". However, in some cases it can be useful to run this action as a certain user (by default, it will run as github-actions). This can be useful if you want to use the "Restrict who can push to matching branches" option in the branch protection rules, for example.

    To use this setting for manually providing a token, you need to create a personal access token for the user (make sure to check public_repo when it's a public repository or repo when it's a private repository). All API requests (merge/rebase) will then be executed as the specified user. The token should be kept secret, so make sure to add it as secret, not as environment variable, in the GitHub workflow file!

You can configure the environment variables in the workflow file like this:

        env:
          GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
          MERGE_LABELS: "automerge,!work in progress"
          MERGE_REMOVE_LABELS: "automerge"
          MERGE_METHOD: "squash"
          MERGE_COMMIT_MESSAGE: "pull-request-description"
          MERGE_FORKS: "false"
          MERGE_RETRIES: "6"
          MERGE_RETRY_SLEEP: "10000"
          UPDATE_LABELS: ""
          UPDATE_METHOD: "rebase"

Supported Events

Automerge can be configured to run for these events:

  • check_run
  • check_suite
  • issue_comment
  • pull_request_review
  • pull_request_target
  • pull_request
  • push
  • repository_dispatch
  • schedule
  • status
  • workflow_dispatch

For more information on when these occur, see the Github documentation on events that trigger workflows and their payloads.

Limitations

Debugging

To run the action with full debug logging, update your workflow file as follows:

      - name: automerge
        uses: pascalgn/[email protected]
        with:
          args: "--trace"

If you need to further debug the action, you can run it locally.

You will need a personal access token.

Then clone this repository, create a file .env in the repository, such as:

GITHUB_TOKEN="123abc..."
URL="https://github.com/pascalgn/repository-name/pull/123"

Install dependencies with yarn, and finally run yarn it (or npm run it).

License

MIT

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].