How to auto merge pull request on github?
Asked Answered
C

5

12

Is it possible to merge pull request automaticaly to master branch on github after success of travis test webhook?

Coveney answered 12/3, 2015 at 16:40 Comment(1)
S
4

You can most probably add an after_success action to your .travis.yml that would merge the PR using GitHub API. I do not know of any ready to use script for this, but there is no reason for it to be hard. Special care needed for authentication ...

Soap answered 30/3, 2015 at 18:18 Comment(0)
S
5

You can use Mergify to do this.

It allows to configure rules and define criteria for your pull request to be automatically merged. In your case, setting something like "Travis check is OK and one reviewer approved the PR" would allow the PR to be automatically merged.

(Disclosure: I'm part of the Mergify team.)

Supplementary answered 27/7, 2018 at 8:17 Comment(0)
S
4

You can most probably add an after_success action to your .travis.yml that would merge the PR using GitHub API. I do not know of any ready to use script for this, but there is no reason for it to be hard. Special care needed for authentication ...

Soap answered 30/3, 2015 at 18:18 Comment(0)
B
3

GitHub recently shipped this auto-merge feature in beta. To use this, you can enable it in the repo settings. Just keep in mind you will need to add branch protection rules as well.

See the documentation for more info.

https://docs.github.com/en/free-pro-team@latest/github/collaborating-with-issues-and-pull-requests/automatically-merging-a-pull-request

Blanketing answered 6/1, 2021 at 19:25 Comment(0)
R
2

I recently wrote a blog post describing how to automatically merge trusted pull requests on GitHub.

Essentially, after enabling the required settings on your repository, you can use the following GitHub Actions workflow to tell GitHub to merge the PR automatically after required status checks pass.

name: Auto-merge Dependabot PRs

on: pull_request

permissions:
  contents: write
  pull-requests: write

jobs:
  dependabot:
    runs-on: ubuntu-latest
    if: ${{ github.actor == 'dependabot[bot]' }}
    steps:
      - name: Approve a PR
        run: gh pr review --approve "$PR_URL"
        env:
          PR_URL: ${{github.event.pull_request.html_url}}
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
      - name: Enable auto-merge for Dependabot PRs
        run: gh pr merge --auto --rebase "$PR_URL"
        env:
          PR_URL: ${{github.event.pull_request.html_url}}
          GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

If you want to allow auto-merging PRs from users other than dependabot, change the if condition to use a list of trusted author names:

if: ${{ contains(fromJson('["dependabot[bot]", "octocat"]'), github.actor) }}

P.S. I recognize that the OP asked specifically about Travis CI, but this was the top Google Search result when I started figuring out how to auto merge PRs on GitHub. Hopefully my answer helps others in my same shoes.

Robber answered 6/12, 2023 at 23:33 Comment(0)
S
0

I run a bot that does this.

Mergery is:

  • Free, including for private repositories.
  • Fast. It's event-driven, it doesn't run on a schedule.
  • Simple. No configuration required. Just label your PRs with automerge.
Steib answered 24/5, 2020 at 6:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.