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

Use gh to automerge and cleanup branches on bump* PRs. #15784

Closed
wants to merge 1 commit into from
Closed

Use gh to automerge and cleanup branches on bump* PRs. #15784

wants to merge 1 commit into from

Conversation

MikeMcQuaid
Copy link
Member

This should allow reducing the mass PR creation flow by a few clicks.

Fixes #14538.

This should allow reducing the mass PR creation flow by a few clicks.

Fixes #14538.
issyl0
issyl0 previously approved these changes Jul 28, 2023
@@ -58,6 +61,7 @@ def bump_cask_pr_args
conflicts "--no-audit", "--online"
conflicts "--version=", "--version-arm="
conflicts "--version=", "--version-intel="
conflicts "--"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
conflicts "--"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops, needs updated.

rescue *API::ERRORS => e
odie "Unable to open pull request: #{e.message}!"
end

# Attempt to enable automerge on the created PR if requested.
GitHub::API.run_gh_cli(args: ["pr", "merge", "--auto", "--merge", "--delete-branch", url]) if args.automerge?
Copy link
Member

@Bo98 Bo98 Jul 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason we do this rather than call the API directly like we do everywhere else?

This sounds like this would not work with HOMEBREW_GITHUB_API_TOKEN.


Code using the GraphQL directly (untested but should work in theory if no typos):

pr = create_pull_request(...)
url = pr["html_url"]

# ...

if args.automerge?
  API.open_graphql(<<~EOS, variables: { pullRequestId: pr["node_id"] })
    mutation($pullRequestId: ID!) {
      enablePullRequestAutoMerge(input: {pullRequestId: $pullRequestId, mergeMethod: MERGE}) {
        clientMutationId
      }
    }
  EOS
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Bo98 pretty much because:

  • we already have code to shell out to gh
  • we already rely on gh for homebrew/core
  • honestly for anything that's not performance-critical: I'd rather we pushed more of our code into gh calls than doing direct API access.

If you don't consider this a hard blocker: would rather land this as-is to validate the idea/workflow and anyone who wants to can move to GraphQL later if that's desired.

Copy link
Member

@Bo98 Bo98 Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we already have code to shell out to gh

This appears to be the first beyond token fetching?

I'm not entirely convinced it'll work in Homebrew/core CI as is given how our tokens appear to be used over there (plus that additional issue Carlo pointed out), but have of course not tested it. Maybe Homebrew/core CI is a non-concern anyway judging by the original issue.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appears to be the first beyond token fetching?

Yes.

I'm not entirely convinced it'll work in Homebrew/core CI as is given how our tokens appear to be used over there

Yes, may require extra wrangling for the bump job(s).

Maybe Homebrew/core CI is a non-concern anyway judging by the original issue.

Indeed, this may be rescoped to cask only.

Comment on lines +51 to +53
switch "--automerge",
env: :bump_automerge,
description: "Open pull requests with automerge and branch cleanup enabled."
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure this works as-is yet, since bump-formula-pr PRs will still need a bottle commit pushed, so I'm not sure we want to enable automerge on them. In theory doing so should do nothing given the bottle checks in the merge queue though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@carlocab Oops, I've misunderstood the workflow. Does this make this PR basically pointless for homebrew/core (and/or homebrew/core)?

Copy link
Member

@carlocab carlocab Jul 31, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At the moment, it is pretty pointless for Homebrew/core. I can see this being useful if/when PRs are blocked from being queued to merge if they are still missing a bottle commit (and require one).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Homebrew/cask would this be useful for homebrew/cask?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cask has automation for this I believe

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, homebrew/cask* already auto-enables automerge for all maintainer-authored PRs labelled bump-cask-pr: https://github.com/Homebrew/homebrew-cask/blob/master/.github/workflows/automerge.yml.

Example: Homebrew/homebrew-cask#152038

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool, problem solved then, thanks all.

@MikeMcQuaid MikeMcQuaid closed this Aug 2, 2023
@github-actions github-actions bot added the outdated PR was locked due to age label Sep 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 2, 2023
@MikeMcQuaid MikeMcQuaid deleted the gh_automerge_bump branch September 27, 2023 12:58
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

brew bump* commands should enable auto-merge
5 participants