Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Auto-merge support with "restrict who can push to this branch" #86

Closed
nesl247 opened this issue Jul 12, 2018 · 45 comments
Closed

Auto-merge support with "restrict who can push to this branch" #86

nesl247 opened this issue Jul 12, 2018 · 45 comments

Comments

@nesl247
Copy link

nesl247 commented Jul 12, 2018

Currently auto-merge is not possible for any branch that has "restrict who can push to this branch" enabled in branch protections.

Unfortunately GitHub does not currently allow adding bots to the list.

Is there any way to communicate with GitHub, especially since Dependabot is a Marketplace app?

@greysteil
Copy link
Contributor

There's an issue on the GitHub platform forum, which is their preferred way to receive app-related feedback. Adding your voice there might help:

https://platform.github.community/t/repositories-which-have-protected-branches-with-push-restrictions-have-no-ability-to-grant-push-rights-to-integrations/1376/48

@nesl247
Copy link
Author

nesl247 commented Jul 12, 2018

I've gone ahead and replied and asked for an update. Unfortunately GitHub is slow as can be to do the most basic of things.

@kimadactyl
Copy link

Plus one, is it possible for us to add dependabot-bot as a user on the protected branch? It would require the bot responding to "add to team" requests. That's how Rultor does it :)

@greysteil
Copy link
Contributor

Good question. Sadly not at the moment - we'd need to build a bunch of automation around dependabot-bot to make that work. It doesn't sound too hard, though, and is definitely the best workaround I've heard so far. I'm a little underwater with other requests, but will try to come back to this - ping me if I don't (and if there's no progress from GitHub - we're still pushing them).

@cihati
Copy link

cihati commented Jan 23, 2019

Any progress on this one @greysteil ?

@greysteil
Copy link
Contributor

This one's still with GitHub support. I chased them about it last week and just got another "it's on our roadmap" email. I know they're very busy, but hope this will become a priority eventually. In the meantime, the best way to help is probably emailing support@github.com.

@simlu
Copy link

simlu commented Feb 18, 2019

We'd be very interested in a proper solution as well... Basically we want human prs to be reviewed before merging into our dev branch. However dependabot prs should be ok to auto merge. We could solve this independently from dependabot, however ideally it's solved by dependabot (if possible).

@greysteil What would be a appropriate request for the email you provided? If you post a template here more people might be tempted to sent that.

@greysteil
Copy link
Contributor

I'd go for something like this:

To support@github.com:

Hi team,

I've got a feature request: we use Dependabot to create pull requests on repo-name and would like it to be able to automatically merge the PRs it creates, whilst continuing to require pull request reviews for PRs created by humans.

Currently, it looks like that's not possible under the branch-protection rules, particularly as Dependabot acts as a GitHub app (its username is dependabot[bot]). Are there any plans to add support?

Many thanks,

your-name

@simlu
Copy link

simlu commented Feb 19, 2019

@greysteil Thanks!

We've solved this now in circleci using gally (disclaimer I'm the author) and a separate "bot" github user. Not as clean as I'd like it to be (oh circle why do you make our life so hard), but works great.

Excerpt (job):

  gally-auto-merge:
    docker:
      - image: 'circleci/node:10'
    steps:
      - run:
          name: Set PR number because circle :(
          command: |
            echo 'export CIRCLE_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}"' >> $BASH_ENV
            source $BASH_ENV
            echo $CIRCLE_PR_NUMBER
      - checkout
      - run: sudo npm i -g gally
      - run: ga approve $CIRCLE_PR_NUMBER --condition "base.ref=dev&state=open&user.login=dependabot[bot]"
      - run: ga merge $CIRCLE_PR_NUMBER --condition "base.ref=dev&state=open&user.login=dependabot[bot]"

If you don't need approval you can skip that step in the job. Note that this requires the $GH_TOKEN environment variable to be set and contain the api key for the bot user.

@jodastephen
Copy link

I've played with this bot, and with some hacking managed to get it to auto-approve dependabot PRs so they then can be merged.

@greysteil, Ideally, this would be a new config option in dependabot, but I'm not sure if it is as simple as that. You can't normally approve your own PR, but maybe you can through the API? Otherwise, how about a new bot - approvabot ?

@greysteil
Copy link
Contributor

We can't approve our own PRs, but a GitHub action to automatically approve them ought to work. I think @hmarr had something basic thrown together.

@hmarr
Copy link
Contributor

hmarr commented Feb 19, 2019

I've just fixed up the auto-approval action I threw together a while ago and made the repo open source.

If you have access to GitHub Actions (and are using a private repo, as I gather they're not yet enabled for open source repos), this should do the trick for you.

https://github.com/hmarr/actions/#auto-approve

@AzureMarker
Copy link

@hmarr That bot does not seem to solve the issue.

For clarification, this issue is about the "Restrict who can push to matching branches" option, which only allows the specified users or teams to push to the branch. What your Action solves for is when "Require pull request reviews before merging" is enabled, which is not the point of this issue.

@nicolasrouanne
Copy link

Any workaround without GitHub Actions (I'm not yet into the beta 😢)?

@greysteil
Copy link
Contributor

We're working on a general fix for this in GitHub right now (i.e., allowing you to specify bots as actors that are allowed to push to protected branches).

@nicolasrouanne
Copy link

For those who don't have GitHub Actions yet the autoapproval bot is working great. You can self host it (source code) or add the GitHub app (that's what I did).

Here is my .github/autoapproval.yml settings file:

from_owner:
  - dependabot-preview[bot]
required_labels:
  - dependencies
apply_labels:
  - autoapproved

Screenshot 2019-06-24 at 11 15 16

So basically:

  • autoapproval approves dependabot PRs automatically
  • dependabot auto-merges its PRs since they are approved
  • me: ☕️

@AzureMarker
Copy link

@nicolasrouanne that kind of fix is unrelated to this issue, as I previously mentioned:

For clarification, this issue is about the "Restrict who can push to matching branches" option, which only allows the specified users or teams to push to the branch. What your Action solves for is when "Require pull request reviews before merging" is enabled, which is not the point of this issue.

#86 (comment)

@greysteil
Copy link
Contributor

@Mcat12 we'll have a fix for that direct in GitHub (and usable for other apps, not just Dependabot) in the next few days. @feelepxyz is working on it right now 🙂

@AzureMarker
Copy link

@greysteil Can you update this issue when the feature has been released?

@greysteil
Copy link
Contributor

For sure. The whole of GitHub is at a big offsite this week so it won't happen in the next 7 days, but the code is almost ready and should be deployed next week.

@karltaylor
Copy link

@greysteil enjoy your offsite

@StephanBijzitter
Copy link

Perhaps it should be an issue of its own, but for several of our repositories we do not trust our test coverage enough to go full automatic.

One of our repositories now uses autoapprove + dependabot and that's working nicely, but for two other repositories we'd prefer to manually approve pull requests from dependabot and have dependabot merge them as soon as all other status checks have come back positive. That way we don't have to wait for the build to complete.

I may have been rambling a bit, so maybe this could summarise the option I'd also like to see (next to the fully automatic solution):

  • Dependabot creates PR
  • Developer approves while build is in progress
  • Build finishes
  • Dependabot merges PR

And

  • Dependabot creates PR
  • Build finishes
  • Developer approves
  • Dependabot merges PR

Currently we get:

Dependabot tried to automerge this PR, but received the following error from GitHub:

At least 1 approving review is required by reviewers with write access.

As a result, we've disabled automerging on this repo (you can re-enable it in your Dependabot settings).

Which is preventing us from doing that while we're working on our test coverage

@greysteil
Copy link
Contributor

greysteil commented Aug 1, 2019 via email

@NargiT
Copy link

NargiT commented Aug 20, 2019

You could use policy-bot from palantir that replace and enhance the branch protection by adding a status check to the pull request. If you configure your repo with branch protection for status check. Then you should be able to merge even if it is a bot. https://github.com/palantir/policy-bot

@feelepxyz
Copy link
Contributor

👋 We've just shipped the UI to allow installed GitHub Apps to push to protected branches, you can add installed apps from the repository settings for the protected branch:

Screenshot 2019-08-22 at 11 30 40

Short video walkthrough: https://drive.google.com/open?id=1i15psbTl7LhSMhNCi9tom-OdgybM9slQ

If you've got required pull request reviews set Dependabot will still fail to merge the pull request until it's approved. You can get around this with a GitHub action to auto approve these pull requests: https://github.com/hmarr/auto-approve-action

We're still working on the corresponding APIs to query/update apps as allowed actors on protected branches (GraphQL v4 and Rest v3). Planning on publishing these by next week.

There's also a bug when using git auth (e.g. git push with credentials) preventing apps from pushing to protected branches even though it's been authorized. Should be fixed by next week.

🎉

@simlu
Copy link

simlu commented Aug 27, 2019

@feelepxyz Can you please update this ticket when this is supported through the api? Cheers!

@feelepxyz
Copy link
Contributor

@simlu the APIs are now live 🎉

Updated GraphQL API:

Updated Rest API: https://developer.github.com/changes/2019-09-05-apps-protected-branches-api/

@localheinz
Copy link

Any news on this one?

@feelepxyz
Copy link
Contributor

@localheinz this should be working now if you add Dependabot Preview to the list of actors with push access on the protected branch. What's not working?

@localheinz
Copy link

localheinz commented Dec 16, 2019

@feelepxyz

The actor Dependabot Preview (or any other Dependabot actor) does not show up:

Screen Shot 2019-12-16 at 11 38 36

What do I need to do to make this happen?

@philsturgeon
Copy link

I'm also not seeing the name show up.

Screen Shot 2019-12-16 at 11 49 49

@feelepxyz
Copy link
Contributor

@philsturgeon @localheinz oh looks like this is broken. Will investigate!

@feelepxyz
Copy link
Contributor

@localheinz @philsturgeon workong on a fix in github but going to take some time to get this out amidst the holidays. You can work around it by explicitly selecting the repos that Dependabot Preview has access to instad of All repositories on the installation.

@localheinz
Copy link

@feelepxyz

Can confirm that selecting repositories manually allows to select @dependabot-preview!

Screen Shot 2019-12-21 at 09 52 16

@localheinz
Copy link

localheinz commented Dec 22, 2019

@feelepxyz

Not sure if this is a different issue, but I still do not see Dependabot automatically merge pull requests.

Apps allowed to push to matching branches

@dependabot-preview is on the list of apps allowed to push to matching branches (in this case, master)

Screen Shot 2019-12-22 at 16 45 10

.dependabot/config.yml

.dependabot/config.yml hopefully has the appropriate configuration:

# https://dependabot.com/docs/config-file/

version: 1

update_configs:
  - automerged_updates:
      - match:
          dependency_type: "development"
    default_assignees:
      - "localheinz"
    default_labels:
      - "dependency"
    default_reviewers:
      - "localheinz"
    directory: "/"
    ignored_updates:
      - match:
          dependency_name: "composer-plugin-api"
      - match:
          dependency_name: "composer/composer"
    package_manager: "php:composer"
    update_schedule: "live"
    version_requirement_updates: "increase_versions"

CODEOWNERS

I also have CODEOWNERS configured on the organization level and enabled on the repository level.

Screen Shot 2019-12-22 at 17 15 56

Example

I would have expected ergebnis/composer-normalize#283 to be merged automatically.

However, this has not happened.

Modifications required?

Do I need to remove the default_reviewers configuration?

diff --git a/.dependabot/config.yml b/.dependabot/config.yml
index 26a20fe..0778a1b 100644
--- a/.dependabot/config.yml
+++ b/.dependabot/config.yml
@@ -10,8 +10,6 @@ update_configs:
       - "localheinz"
     default_labels:
       - "dependency"
-    default_reviewers:
-      - "localheinz"
     directory: "/"
     ignored_updates:
       - match:

Should I stop using CODEOWNERS or configure it differently to exclude composer.json and composer.lock?

@romrell4
Copy link

romrell4 commented Jan 3, 2020

I'm still not seeing the option to add dependabot-preview (or any other dependabot users) to my list of people with push access. Is this bug not completely fixed? I am also unable to manually select all repositories (since we have thousands, and need our bot to automatically have access to new ones). Any updates on this bug?

@feelepxyz
Copy link
Contributor

@romrell4 this should be fixed now. Was on hold over the break.

@localheinz yeah looks like the required reviewers settings are preventing the automerge: ergebnis/composer-normalize#283 (comment) there's an option to treat a PR approval as a request to merge in your dependabot dashboard settings:

Screen Shot 2020-01-06 at 12 48 00

@localheinz
Copy link

Thank you, @feelepxyz!

@chris48s
Copy link

Just to clarify my understanding on this issue, is this summary of the situation correct?

Dependabot can now be added with permissions to push to protected branches, but it can't approve its own PRs. In order to trigger the merge, you still need either a manual approval, or another bot/action (other than dependabot) to approve the PR, even if a PR matches rules in automerged_updates.

@feelepxyz
Copy link
Contributor

Dependabot can now be added with permissions to push to protected branches, but it can't approve its own PRs. In order to trigger the merge, you still need either a manual approval, or another bot/action (other than dependabot) to approve the PR, even if a PR matches rules in automerged_updates.

Yep, that's correct! Here's an example GH Action to auto-approve: https://github.com/hmarr/auto-approve-action (going to lock this issue)

@dependabot dependabot locked as resolved and limited conversation to collaborators Jan 20, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests