Skip to content

ci: fix existing-PR detection for cross-fork promotion#37

Merged
herikwebb merged 1 commit into
mainfrom
automation/fix-promote-existing-detection
Jul 4, 2026
Merged

ci: fix existing-PR detection for cross-fork promotion#37
herikwebb merged 1 commit into
mainfrom
automation/fix-promote-existing-detection

Conversation

@herikwebb

Copy link
Copy Markdown
Owner

Bug

The re-run of Promote to upstream failed with a pull request for branch "…" into branch "main" already exists … Error: exit code 1. The idempotency check used gh pr list --repo <upstream> --head <owner:branch>, which does not reliably match a cross-fork head on the base repo — so existing came back empty, the job fell through to gh pr create, and GitHub rejected the duplicate.

Fix

Query the REST pulls head filter directly (GET /repos/{upstream}/pulls?head=user:branch&state=open), and gh pr edit the matched PR number. This correctly detects the open cross-fork PR (plmbr#386) and refreshes its title/body instead of trying to recreate it.


Generated by Claude Code

gh pr list --head does not reliably match a cross-fork head on the base repo,
so a re-run fell through to gh pr create and failed with 'already exists'. Query
the REST pulls head filter (user:branch) directly and gh pr edit the matched PR.
@herikwebb herikwebb added the bug Something isn't working label Jul 4, 2026 — with Claude
@herikwebb herikwebb merged commit 2a82aaa into main Jul 4, 2026
4 of 5 checks passed
@github-actions

github-actions Bot commented Jul 4, 2026

Copy link
Copy Markdown

Automated PR Review

Model: gpt-5.5
Verdict: CHANGES_REQUESTED

Changed files:

.github/workflows/promote-upstream.yml

Review result:

Findings

Medium — .github/workflows/promote-upstream.yml — Existing PR lookup no longer scopes by requested base branch

The new REST lookup checks only:

-f head="${head_ref}" -f state=open

but no longer includes the requested BASE. This can match an open PR from the same fork branch targeting a different upstream base branch. In that case the workflow will edit that unrelated PR and exit successfully instead of creating/updating the PR for the requested base branch.

This is especially relevant because base is a workflow input and the previous implementation explicitly scoped by --base "${BASE}".

Suggested fix:

existing_num="$(gh api -X GET "repos/${UPSTREAM}/pulls" \
  -f head="${head_ref}" -f base="${BASE}" -f state=open --jq '.[0].number // ""')"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant