From 31dad4cd8a786fef0c34af3bb1315982b3202930 Mon Sep 17 00:00:00 2001 From: Kevin Longe <273747162+kvlonge@users.noreply.github.com> Date: Wed, 11 Nov 2026 23:16:22 +0000 Subject: [PATCH] fix: request auto-merge without --delete-branch under a merge queue gh refuses --delete-branch when the base branch has a merge queue, so the workflow failed on every new sqlbuild pull request. Ask for branch deletion only when there is no queue; with one, the repository's delete-on-merge setting removes the branch. --- .github/workflows/auto-merge.yml | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/.github/workflows/auto-merge.yml b/.github/workflows/auto-merge.yml index 138c34e..33145e6 100644 --- a/.github/workflows/auto-merge.yml +++ b/.github/workflows/auto-merge.yml @@ -40,10 +40,17 @@ jobs: GH_TOKEN: ${{ steps.delivery-token.outputs.token }} PR_HEAD_SHA: ${{ github.event.pull_request.head.sha }} PR_URL: ${{ github.event.pull_request.html_url }} - run: >- - gh pr merge "$PR_URL" - --repo "$GITHUB_REPOSITORY" - --auto - --squash - --delete-branch - --match-head-commit "$PR_HEAD_SHA" + BASE_REF: ${{ github.event.pull_request.base.ref }} + # gh refuses --delete-branch when the base branch has a merge queue, so ask for it only + # where there is none. With a queue, the repository's delete-on-merge setting removes it. + run: | + args=(--repo "$GITHUB_REPOSITORY" --auto --squash --match-head-commit "$PR_HEAD_SHA") + queue=$(gh api graphql \ + -f query='query($owner: String!, $name: String!, $branch: String!) { + repository(owner: $owner, name: $name) { mergeQueue(branch: $branch) { id } } }' \ + -f owner="${GITHUB_REPOSITORY%%/*}" -f name="${GITHUB_REPOSITORY#*/}" -f branch="$BASE_REF" \ + --jq '.data.repository.mergeQueue.id // ""') + if [ -z "$queue" ]; then + args+=(--delete-branch) + fi + gh pr merge "$PR_URL" "${args[@]}"