Automatically merge verified and tested GitHub Pull Requests

前端 未结 6 1214
醉话见心
醉话见心 2021-02-04 11:42

I\'d like to automatically (i.e. from Jenkins) merge a GitHub pull request that has been approved by a person and has been tested successfully; in other words, when all THREE of

相关标签:
6条回答
  • 2021-02-04 11:48

    I wrote an app that does this. It responds to the review, labelled, and commit status/checks events, and merges when the merge button is green.

    The fact that it merges when the merge button is green means that you can configure the requirements for a mergeable PR in the GitHub settings, there's no need to write separate configuration for the app.

    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.
    0 讨论(0)
  • 2021-02-04 11:49

    You can use Mergify to do exactly this, since this is what it has been created for. Just set up a minimal .mergify.yml file in your repository:

    rules:
      default:
        protection:
          required_status_checks:
            context:
              - continuous-integration/travis/pr
          required_pull_request_reviews:
            required_approving_review_count: 1
    

    And you'll be good to go.

    (disclaimer: I'm one of the Mergify founders)

    0 讨论(0)
  • 2021-02-04 12:01

    That is now (Dec. 2020, 4 years later) available:

    Pull request auto-merge public beta

    Pull request auto-merge is now rolling out as a public beta!

    With auto-merge, pull requests can be automatically merged when all requirements for merging are met. No more waiting for long checks to finish just so you can press the merge button!

    To use auto-merge, a repository maintainer or admin must first toggle on the repository setting to allow auto-merge (see steps).
    Then any user with write permission can enable or disable auto-merge by navigating to the pull request page.

    Keep in mind that auto-merge is only available for pull requests targeting a branch with required reviews or required status checks, and therefore is only available on public repositories and private repositories on Team and GitHub Enterprise Cloud plans.

    Learn more about pull request auto-merge.

    0 讨论(0)
  • 2021-02-04 12:03

    Using github actions which is one of the new ways, this can be done. I have written a blog about auto approving and auto merging PRs using github actions. However, if the intent is to just merge the PRs only, then then the second job in this work flow would be enough to do it.

    0 讨论(0)
  • 2021-02-04 12:06

    https://github.com/bobvanderlinden/probot-auto-merge is a free GitHub app that does the job. It's configurable in .github/auto-merge.yml.

    0 讨论(0)
  • 2021-02-04 12:11

    There is a new PullRequestReviewEvent webhook that is triggered when a review is submitted in a non-pending state. The body of the webhook contains the ["review"]["state"] field, which will be approved when all reviewers have approved the changes (i.e. when you get the green "changes approved" tick in the UI).

    Combine this with the StatusEvent for the head SHA of your pull request to get the status checks from CI and so on, then finally check the "merge-ability" of the pull by requesting the pull request from the API:

    GET /repos/:owner/:repo/pulls/:number
    

    Once you have all three things, you can merge the pull request with:

    PUT /repos/:owner/:repo/pulls/:number/merge
    

    and appropriate payload parameters. Note you'll need the Accept: application/vnd.github.polaris-preview+json for some of the payload parameters as they are in a preview period.

    0 讨论(0)
提交回复
热议问题