Skip to content

gh pr merge doesn't exempt actor from rule. #13458

Description

@marcusber

Describe the bug

I guess this does is not to the gh-tool itself but the api it works against. Please advice if it should be moved somewhere.

gh merge does not let a bot actor to be exempted from a rule that enforces linear history.

Affected version

Run gh version
  gh version
  shell: /usr/bin/bash -e {0}
gh version 2.92.0 (2026-04-28)
https://github.com/cli/cli/releases/tag/v2.92.0

Steps to reproduce the behavior

I have actions to set up merging between two branches. Push occurs on branch source, actions set up a PR to branch target on behalf of the bot. Once a PR is created another actions is executed and sets up auto-merge and then approves it as github actions.
Rules exists for a) At least one approve. b) Critical CI passes.

I have auto merge enabled in the repo. Everything worked just fine and the PR is merged once critical CI passes.

However, I wanted to encourage developers to squash PRs. I introduced the rule Suggest Squash:

  • Require linear history

All developers are always allowed to bypass it.
My bot is marked as Exempt.

This causes my CI to break whenever the merge commit from branch source to branch target is setup for the PR:

Run gh pr merge --merge --auto $PR_NUMBER
GraphQL: Merge method merge commits are not allowed on this repository (enablePullRequestAutoMerge)
Error: Process completed with exit code 1.

If I set up the bot to allow bypass, the command is executed but since rules are not met it is not auto-merged. This could perhaps be solved by #13388.

    steps:
    - name: Generate a token
      id: generate-token
      uses: actions/create-github-app-token@v3
      with:
        client-id: ${{ vars.ROBOT_CLIENT_ID }}
        private-key: ${{ secrets.ROBOT_PRIVATE_KEY }}
        owner: ${{ github.repository_owner }}

    - name: git checkout
      uses: actions/checkout@v6
      with:
        token: ${{ steps.generate-token.outputs.token }}

    - run: gh pr merge --merge --auto $PR_NUMBER
      name: Enable auto-merge for PR
      env:
        GH_TOKEN: ${{ steps.generate-token.outputs.token }}
        PR_NUMBER: ${{ github.event.pull_request.number }}

Expected vs actual behavior

I expect the linear history rule to be ignored when the bot is responsible for the PR (since exempted) and let the PR be marked as auto-merge.

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    gh-prrelating to the gh pr command

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions