cli: PAT tokens unable to add to merge a PR with the merge queue

Describe the bug

gh version 2.39.1 (2023-11-14)

The following command gives strange behaviour when using a PAT (fine-grained) token:

gh pr merge --auto "$PR_URL"

The CLI takes you through normal merge steps as if there is no merge queue, and then fails at the end.

However, running the same command in Github Actions with a GITHUB_TOKEN, the command succeeds as expected and the PR gets added to the merge queue.

May be related to #7213, though not quite the same issue I don’t think

Steps to reproduce the behavior

  1. Auth with GH CLI with a PAT (fine-grained) token
  2. For a PR in a repository with a merge queue enforced, run gh pr merge --auto "$PR_URL"
  3. Rather than adding the PR to the merge queue, the CLI goes through the steps of: “What merge method would you like to use?”, “Delete the branch on GitHub?”, and “What’s next?”
  4. Go through these steps, and the following error is shown GraphQL: Changes must be made through the merge queue (mergePullRequest)

Expected vs actual behavior

As per the docs, the PR should be added to the merge queue. This works as expected when running in Github Actions with a GITHUB_TOKEN, but the above error happens with a PAT.

About this issue

  • Original URL
  • State: open
  • Created 7 months ago
  • Reactions: 2
  • Comments: 22 (11 by maintainers)

Commits related to this issue

Most upvoted comments

Definitely something funky about those requests and responses, they are missing fields relating to the merge queue which would result in the CLI determining the right course of action. Will look into this more tomorrow!

Thanks for the clarity @williammartin. If I learn anything relevant (one way or the other) I’ll post my findings here.

It’s also possible that the reverse is true and @mhemmings is overriding with a PAT that does happen to work. I intend to write this up tomorrow but the gist of it is that in past the CLI had merge queue support for actors that were feature flagged to use it. This feature flag gated both the merge queue functionality and all of the GQL API. However, not all of the GQL API was stabilised so now it’s possible to be using the merge queue without being in the feature flag for the unstable API. It’s a bit of a mess!

I have ideas on how to move this forward but being realistic, I don’t think it would happen before the holidays.

@mhemmings, I think I’ve found the issue in the platform that is causing this and seem to be able to reproduce it. Unfortunately, I don’t have a great workaround for you right now other than using the enqueue mutation directly.

I’m in discussion with the team that owns this feature to try and get this resolved on their side. As far as I’m concerned everything you’ve done is correct, the CLI is also doing what it is supposed to, and the platform has some incongruent behaviour.

Thanks, I know it feels like first line tech support help but given that it worked for me I really don’t want to go down a rabbit hole only to discover it was something simple. 🙏