Giter VIP home page Giter VIP logo

enable-pull-request-automerge's Introduction

Enable Pull Request Auto-merge

CI GitHub Marketplace

A GitHub action to enable auto-merge on a pull request.

โš ๏ธ There are very specific conditions under which this action will work. See Conditions for details.

Usage

      - uses: peter-evans/enable-pull-request-automerge@v2
        with:
          token: ${{ secrets.PAT }}
          pull-request-number: 1

Action inputs

Name Description Default
token GITHUB_TOKEN (permissions pull_requests: write, contents: write) or a repo scoped Personal Access Token (PAT). GITHUB_TOKEN
repository The target GitHub repository containing the pull request. github.repository (Current repository)
pull-request-number (required) The number of the target pull request
merge-method The merge method to use. merge, rebase or squash. merge

Conditions

This action uses a GitHub API that only works under specific conditions. All of the following conditions must be true for this action to succeed.

  1. The target repository must have Allow auto-merge enabled in settings.
  2. The pull request base must have a branch protection rule with at least one requirement enabled.
  3. The pull request must be in a state where requirements have not yet been satisfied. If the pull request can already be merged, attempting to enable auto-merge will fail.

Dependabot example

The following example will automerge dependabot pull requests. Note that if you use the default GITHUB_TOKEN, as in the example, the merge will not trigger further workflow runs. If you want to trigger further workflow runs, you will need to use a repo scoped Personal Access Token (PAT).

name: Auto-merge Dependabot
on: pull_request

permissions:
  pull-requests: write
  contents: write

jobs:
  automerge:
    runs-on: ubuntu-latest
    if: github.actor == 'dependabot[bot]'
    steps:
      - uses: peter-evans/enable-pull-request-automerge@v2
        with:
          pull-request-number: ${{ github.event.pull_request.number }}
          merge-method: squash

Create pull request example

In the following example create-pull-request action is used to create a pull request containing some changes that we want to merge automatically once requirements have been satisfied.

      - uses: actions/checkout@v3

      # Make changes to pull request here

      - name: Create Pull Request
        id: cpr
        uses: peter-evans/create-pull-request@v3
        with:
          token: ${{ secrets.PAT }}

      - name: Enable Pull Request Automerge
        if: steps.cpr.outputs.pull-request-operation == 'created'
        uses: peter-evans/enable-pull-request-automerge@v2
        with:
          token: ${{ secrets.PAT }}
          pull-request-number: ${{ steps.cpr.outputs.pull-request-number }}
          merge-method: squash

If the "require pull request reviews" branch protection has been enabled we can optionally auto-approve the pull request by adding the following step to the example above. The if condition makes sure we don't approve multiple times if the workflow executes more than once before the pull request merges.

      - name: Auto approve
        if: steps.cpr.outputs.pull-request-operation == 'created'
        uses: juliangruber/approve-pull-request-action@v2
        with:
          github-token: ${{ secrets.GITHUB_TOKEN }}
          number: ${{ steps.cpr.outputs.pull-request-number }}

License

MIT

enable-pull-request-automerge's People

Contributors

peter-evans avatar dependabot[bot] avatar actions-bot avatar github-actions[bot] avatar randymarsh77 avatar williamboman avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.