Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Option for disabling automerge #74

Closed
alfieyfc opened this issue Apr 13, 2021 · 7 comments
Closed

Option for disabling automerge #74

alfieyfc opened this issue Apr 13, 2021 · 7 comments

Comments

@alfieyfc
Copy link

alfieyfc commented Apr 13, 2021

This could be totally up to another action project, but still posting here for now just to raise the idea, though I don't know if it's implementable.

I'm proposing adding an input such as mode, which is default to enable, and ignores the merge-method input when set to disable. The purpose is to allow this action to disable automerge in desired conditions. An example scenario would be something like below, triggered when the base of PR is edited (I bet there's a better way to trigger this).

name: PR Edited
on:
  pull_request:
    types: [edited]
jobs:
  enable-automerge:
    if: ${{ github.event.pull_request.base.ref != 'main' }}
    runs-on: ubuntu-latest
    steps:
      - uses: peter-evans/enable-pull-request-automerge@v1
        with:
          token: ${{ secrets.MY_PAT }}
          pull-request-number: ${{ github.event.pull_request.number }}
  disable-automerge:
    if: ${{ github.event.pull_request.base.ref == 'main' }}
    runs-on: ubuntu-latest
    steps:
      - uses: peter-evans/enable-pull-request-automerge@v1
        with:
          token: ${{ secrets.MY_PAT }}
          pull-request-number: ${{ github.event.pull_request.number }}
          mode: disable

I'm struggling with finding another action that disables automerge in marketplace and thought it would be nice if this action has such addition.

@peter-evans
Copy link
Owner

@alfieyfc The documentation suggests that it is automatically disabled when the base of the PR is changed. I don't think you need to explicitly disable it in a workflow.

After you enable auto-merge for a pull request, if someone who does not have write permissions to the repository pushes new changes to the head branch or switches the base branch of the pull request, auto-merge will be disabled. For example, if a maintainer enables auto-merge for a pull request from a fork, auto-merge will be disabled after a contributor pushes new changes to the pull request.

ref: https://docs.github.com/en/github/collaborating-with-issues-and-pull-requests/automatically-merging-a-pull-request

@peter-evans
Copy link
Owner

There is a GraphQL mutation for disable, though. So if for some reason the automated disable outlined in the documentation doesn't work for your use case I think I can add it to the action.

https://docs.github.com/en/graphql/reference/mutations#disablepullrequestautomerge

@alfieyfc
Copy link
Author

someone who does not have write permissions to the repository

I misread this bit of context! It's not acting as I was expecting because I am the repo owner. @peter-evans Thanks for the clarification!

Though having a disable option could be handy, for now I'm accepting it as a limitation where maintainers have to manually disable automerge when they make changes themselves. To me this issue can be considered resolved then. But I'll leave it for you to close in case you wanna decide if mutation for disable is worth your time implementing. :)

@peter-evans
Copy link
Owner

I'll close it for now then. It can always be reopened if there is a need for it in future.

@alfieyfc
Copy link
Author

alfieyfc commented May 6, 2022

@peter-evans Hello there 👋 I'm back thinking of reopening this feature request since auto_merge_enabled had become a pull_request event type.

The scenario would be someone carelessly enabling auto-merge for a PR that has a base branch we don't want to allow auto-merging. So the action would quickly check if base branch is valid for auto-merge. Then, if not, the action will disable it.

I tried searching for other actions that can disable auto-merge but didn't find anything suitable. Any suggestions?

@peter-evans
Copy link
Owner

After thinking a bit more about this, I'm not sure that adding it to this action makes sense since "enable" is in the title of the action.

I would recommend using github-script to call the disable API. The query should look very similar to the code I have here to enable.

@alfieyfc
Copy link
Author

alfieyfc commented May 9, 2022

@peter-evans Makes sense! I'll try to set it up for my workflow. Thanks for the reply! 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants