Giter VIP home page Giter VIP logo

merge-bot's Introduction

PR Merge Bot

This action manages pull request integrations by allowing a structured workflow to be defined.

The workflow can use required labels, blocking labels, and require that reviewers sign-off for determining if a pull request should be integrated. By default the pull request will be blocked by incomplete/failing checks.

Once conditions are met the pull request will be integrated and branch deleted.

merged GitHub pull request and deleted branch

Inputs

test

Runs in test mode and will comment rather than merge. This allows you to experiment with the settings without integrating a pull request. Default is false.

test mode comment left by the bot

reviewers

Reviewers required, and reviewers must all approve. This enforces a reviewer mode where there cannot be any pending reviews and the submitted reviews must be in an "approved" state. Default is true.

reviewer has signed-off on pull request

labels

One or more labels required for integration. Default is "ready".

merge and sign-off GitHub labels

blocking_labels

One or more labels that block the integration. Default is "do not merge".

do not merge GitHub label

checks_enabled

All checks must be completed to be eligible to integrate (this does not include the currently running Action). Note, if triggering multiple runs simultaneously (like adding two labels) this will not pass -- USE WITH CAUTION. Default is false.

method

Merge method to use. Possible values are merge, squash or rebase. Default is merge.

delete_source_branch

Delete the source branch of the pull request after merging. Set to false when "Automatically delete head branches" is enabled on your repo. Default is true.

NOTE: if enabled, merge-bot is unable to delete a branch from a fork.

Automatically delete head branches enabled

Example usage

You can use PR Merge Bot by configuring a YAML-based workflow file, e.g. .github/workflows/merge-bot.yml.

name: Merge Bot

on:
  pull_request:
    types:
      - labeled
      - ready_for_review
      - review_request_removed
      - review_requested
      - synchronize
      - unlabeled
  pull_request_review:
    types:
      - dismissed
      - submitted

jobs:
  merge:
    runs-on: ubuntu-latest
    name: Merge
    steps:
    - name: Integration check
      uses: squalrus/[email protected]
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        test: true
        reviewers: true
        labels: ready, merge
        blocking_labels: do not merge
        checks_enabled: true
        method: squash
        delete_source_branch: true

merge-bot's People

Contributors

aaron-trout avatar dependabot[bot] avatar ignusg avatar marisbest2 avatar squalrus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

merge-bot's Issues

Error: Cannot read properties of undefined (reading 'labels')

Describe the bug
In a single-author repo using merge-bot to merge because I'm too lazy/forgetful to go back and check, I'm getting the error message at subject: Error: Cannot read properties of undefined (reading 'labels')

I've successfully used merge-bot for organizations, but in this case, it's just me, forgetful me, copying a functional config and I can't see how to debug this. FWIW, I can see the value of labels in the JSON dump.

To Reproduce
Steps to reproduce the behavior:

.github/workflows/build-and-merge.yml:

on:
  pull_request:
    types:
      - opened
      - reopened
  push:

jobs:
  build:
    ...
  merge:
    runs-on: ubuntu-latest
    permissions:
      # checked with all "write"
    steps:
      - name: Merge Workflow for tagged PRs
        uses: squalrus/[email protected]
        with:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          blocking_labels: do not merge, invalid
          checks_enabled: true
          # settings, "Pull Requests" section, "[x] Automatically delete head branches"
          delete_source_branch: false
          labels: automerge
          method: squash
          # reviewers: true  -- don't actually want my own review, just a tag
          reviewers: false
          test: true
  1. push a PR, label it "automerge"
  2. watch the action fail with Error: Cannot read properties of undefined (reading 'labels')

Expected behavior
A tagged PR that builds should merge

Desktop (please complete the following information):

  • OS: MacOS (intel) with 13.5
  • Browser Safari 16.6

Additional context

$ gh pr view 19 --json labels
{
  "labels": [
    {
      "id": "LA_kwDOKFf69c8AAAABXivleg",
      "name": "automerge",
      "description": "",
      "color": "42EA5A"
    }
  ]
}

Not detecting reviews?

Describe the bug
Hi again @squalrus, sorry to bombard you with PR's and issues ๐Ÿ˜…

Seeing a weird behaviour and was hoping you could help me figure out what is happening? I had this PR where reviewers were auto assigned from CODEOWNERS, but once all the conditions were met the auto merge didn't happen.

Before approvals it said Waiting on code owner review from limejump/platform and/or limejump/sig-kubernetes.

After approvals I see this in the logs:

pull: {"labels":["automerge","ready"],"owner":"limejump","pull_number":1375,"reviews":[],"ref":"heads/automerge-fixes","repo":"k8s-gitops","requested_reviewers":[],"checks":{}}

Notice how reviews and requested_reviewers are just an empty list! So all the jobs passed, but it didn't merge.

Screenshot 2020-09-03 at 14 21 04

Any ideas / extra things to check?

merge-bot failing with error on pull request

Hi @squalrus,

thank you for this handy bot. Great stuff.

I just set up an action on one of my repositories that is for now private and only worked on by me.

When running the action in "live" mode I get the following error message:

[data] pull (checks + reviews): {"labels":["merge"],"owner":"ChrisRBe","pull_number":6,"reviews":{},"ref":"11d02790cec54a9b1bbfe445d164e4c7fb0af1b1","repo":"kitcheneer","requested_reviewers":[],"checks":{"total":5,"completed":4,"success":4}}
merge: true
Error: Reference does not exist

Do you have an idea what is happening here?

Remove `node_modules`

Its a very bad practice to upload the node_modules folder to github. You have the complete source-code of hundreds dependencies in your repo.

Update from base branch before merging.

Is your feature request related to a problem? Please describe.
merge queues are most useful in workflows that take time.
For instance... running the CI pipeline for unit and e2e tests might take 20 minutes or more. In this case, the risk that some other team member manages to merge their branch before your PRs CI run is done, is high, forcing you to start over by updating the PR with the latest HEAD of master. This is the primary case for a merge bot. The bot should then watch a repo for changes, see if it becomes ready to merge, and check if it's behind master, if it's behind master, it should trigger a branch update, and when the CI system reports done, it should try again.

Describe the solution you'd like
check if current branch is behind target branch, and then update current branch with current head. notifying the user incase of merge conflict for manual resolution.
https://octokit.github.io/rest.js/#octokit-routes-pulls-update-branch

Describe alternatives you've considered
well manual handling .. since one of the checks to see if you are allowed to merge, is that the branch is behind master, it would still be blocked... But then the user still needs to check in to see if the branch have been merged or if they need to update the branch again. This would only be a semi automatic system... I would prefer a fire and forget solution.. where if you mark a branch as ready to merge, you can trust that the bot will merge it as long as there aren't any merge conflicts, even if another merge gets in between.

Allow merges even if the base branch changes

Is your feature request related to a problem? Please describe.
I am using merge-bot to merge Dependabot pull requests and often I want to mark several of them as ready simultaneously. Unfortunately, labeling multiple PRs as ready at the same time results in the first one succeeding and the remaining ones failing because of the changes to the base branch. I have tried the turnstyle Github Action to avoid concurrent workflows but that doesn't seem to matter so I'm guessing that the base branch for the merge is determined before the merge-bot action runs.

Describe the solution you'd like
Ideally, merge-bot would be able to execute a merge of the PR even if the base branch changes since the workflow was kicked off. Perhaps this should be an option that needs to be enabled since some users might prefer that the merge fails if the base changes since the PR was marked as ready.

Describe alternatives you've considered
One way to avoid my problem above is to mark PRs as ready one-at-a-time and wait some time between each label, but then the amount of manual effort required to merge each PR begins to approach where I was when I merged each PR manually anyways.

Additional context
Here is an example of me running into this issue:
Successful merge: Link
Failing merges (at the same time as the successful merge above): Link 1 Link 2

GITHUB_TOKEN is unknown as a parameter

When running the action it outputs:

##[warning]Unexpected input 'GITHUB_TOKEN', valid inputs are ['test', 'labels', 'blocking-labels', 'reviewers', 'checks_enabled', 'method']

To Reproduce
Configure the action workflow:

name: Merge Bot

on:
  pull_request:
    types: [labeled, unlabeled, ready_for_review, review_request_removed, review_requested, synchronize]
  pull_request_review:
    types: [dismissed, submitted]

jobs:
  merge:
    runs-on: ubuntu-latest
    name: Merge
    steps:
    - name: Integration check
      uses: squalrus/[email protected]
      with:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        test: true
        reviewers: true
        labels: "pr:merge-on-approval"        
        checks_enabled: true
        method: merge

Expected behavior
That it not spit out warnings. I think you should change

        const token = core.getInput('GITHUB_TOKEN');

to:

        const token = process.env['GITHUB_TOKEN'] || '';

And change your configuration example to:

      env:
        GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        test: true
        reviewers: true

etc.

Don't merge until checks complete

Is your feature request related to a problem? Please describe.

From the docs it's not clear that the merge-bot will wait till PR checks all pass prior to merging. It talks about reviewers, labels, etc., but not the PR checks.

Describe the solution you'd like

I'd like this merge bot to wait for checks to all pass prior to merging.

Describe alternatives you've considered

Writing my own github action. ๐Ÿ˜›

Is there a way to merge without labeling?

My team doesn't use labels. Currently bot doesn't want to merge PRs without labels.

What i want to achieve:

In our repo if we have at least one approve on a PR it is considered ready to merge. Can I configure this bot to automatically update and merge PR after any approval from any reviewer? Without using labels of course.

Time based allow/block of merges

I would like to have a crontab style rule that we can use to specify time intervals where merging is allowed/prohibited. It seems that the framework of this bot would fit for something like that?

##[warning]Unexpected input 'GITHUB_TOKEN'

Describe the bug
The GITHUB_TOKEN is not recognized as input.

To Reproduce
Steps to reproduce the behavior:

  1. Use action
  2. Set:
- uses: squalrus/[email protected]
   with:
      GITHUB_TOKEN: ${{ secrets.REPO_ACCESS_TOKEN }}
      method: merge
      labels: version-ready

Expected behavior
Uses GITHUB_TOKEN as auth.

Screenshots
image

The input is being read here:

const token = core.getInput('GITHUB_TOKEN');

But needs to be specified in action.yml for github to recognize it here:

merge-bot/action.yml

Lines 7 to 30 in 1083cc7

test:
description: 'Runs in test mode and will comment rather than merge'
required: false
default: false
labels:
description: 'Labels required for integration'
required: true
default: 'ready'
blocking-labels:
description: 'Labels that block the integration'
required: false
default: 'do not merge'
reviewers:
description: 'Reviewers required and reviewers must all approve'
required: false
default: true
checks_enabled:
description: 'All checks must be completed to be eligible to integrate (except the current Action)'
required: false
default: false
method:
description: 'Merge method to use. Possible values are `merge`, `squash` or `rebase`. Default is `merge`.'
required: false
default: 'merge'

Re-trigger Action when checks complete

Is your feature request related to a problem? Please describe.

When validating checks is enabled (default), the Action is not re-run when the checks complete.

Describe the solution you'd like

Once the checks complete, re-trigger the Action to determine mergability.

Describe alternatives you've considered

N/A

follow the configured required review count

Is your feature request related to a problem? Please describe.
Right now, merge-bot requires all assigned reviewers to approve a PR before merging it.
Github let's you configure how many reviewers are required, merge-bot should follow that configuration.

Describe the solution you'd like
for merge-bot to follow the configured number of approvals.

Describe alternatives you've considered
Forking merge-bot...

README is out of date.

Your README's configuration is out of date with your codebase. The README has the configuration as checks: true when the code expects checks_enabled: true.

Unable to perform integration check

Describe the bug
I just installed via the config available here: https://github.com/elninotech/uppload/blob/master/.github/workflows/merge-pr.yml

None of the merge checks are working, with this error:

##[error]Cannot read property 'head' of undefined
Run squalrus/[email protected]
  with:
    GITHUB_TOKEN: ***
    test: true
    reviewers: true
    blocking-labels: do not merge
    checks: true
    method: squash
    labels: ready
test mode: true
required reviewers: true
required labels: ["ready"]
blocking labels: ["do not merge"]
merge method: squash
##[error]Cannot read property 'head' of undefined

Here are the logs: https://github.com/elninotech/uppload/commit/20acfb19cd21f074dee8d0618ba2688c6da29c41/checks?check_suite_id=480268098

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.