forge pr find-by-head and branch resolution ignore the head filter, returning the wrong PR #83
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
User story: So that I can submit and manage pull requests by branch name without risking changes to the wrong PR,
forgemust resolve branch heads from actual PR metadata rather than an ignored server filter.Part of the "Forge / workspace CLI tooling" arc.
forge pr find-by-head <branch>returns a PR number even when no PR exists for that branch, and returns the wrong PR whenever any other open PR exists. The root cause is thatpr_find_by_head— andresolve_pr_target, which resolves a branch-name target forpr edit/pr comment/pr close— query the Forgejo pulls list with ahead=filter the API does not honor:Forgejo/Gitea's
GET /repos/{owner}/{repo}/pullsendpoint does not support aheadquery-parameter filter (unlike GitHub's API, from which this pattern was likely ported). The unrecognizedhead=param is silently ignored, so the endpoint returns every open PR andfirst(.[] | .number)yields the first open PR's number regardless of the branch asked for.Reproduction
With exactly one open PR, whose head branch is
agent/rotation-vmssh-suite(say #78):Expected: the second call prints nothing, since no open PR has that head.
Impact
allod change submitcallsforge pr find-by-head "$branch"to guard against duplicate PRs. Because it returns the first open PR for any branch, submitting a second (e.g. stacked) PR while another PR is open dies withPR #N already exists for '<branch>'and blocks the workflow. Observed while stacking two PRs onvnprc/nexus; worked around by creating the second PR withforge pr create -H <branch> -B <base>directly.resolve_pr_targetresolves a branch-name target the same way, soforge pr edit <branch>,forge pr comment <branch>, andforge pr close <branch>can act on the wrong PR (the first open one) instead of the one for that branch.Suggested fix
Filter client-side on
.head.refrather than trusting the serverhead=param:Both
pr_find_by_headandresolve_pr_targetshare the pattern and should be fixed together. Consider paginating instead of a fixedlimit=50so a branch's PR is not missed once more than 50 PRs are open.