fix: pass branch positional to gh pr view when --repo is set - #32
Conversation
gh pr view --repo owner/name cannot infer the PR from the local checkout — it requires a branch/number/URL positional. the runner was omitting it, so ensure_pr failed on every call when RALPH_REPO or GH_REPO was set, making the review gate skip every turn. Fixes fasrc/archi#83. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: c7075a1412
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| num=$(gh pr view "${repo_args[@]}" --json number --jq .number 2>/tmp/.ralph_prview.$$) | ||
| local branch | ||
| branch=$(working_branch) | ||
| num=$(gh pr view "$branch" "${repo_args[@]}" --json number --jq .number 2>/tmp/.ralph_prview.$$) |
There was a problem hiding this comment.
Disambiguate numeric branch names from PR numbers
When the working branch is numeric (for example, 123, which is a valid Git branch name), this positional is parsed as PR number 123 rather than as the branch: the installed gh 2.96.0 help defines the selector as <number> | <url> | <branch> (official manual), and its API debug output uses PullRequestByNumber for gh pr view 123. The gate can consequently request review and run checks against unrelated PR #123—and merge it when auto-merge is enabled—instead of creating or locating the branch's PR. Use an unambiguous branch-specific lookup such as gh pr list --head "$branch" rather than passing the raw branch as this overloaded positional.
Useful? React with 👍 / 👎.
Summary
gh pr viewinensure_pr(), fixing the review-gate's inability to find or create PRs when--repois set--repoFixes fasrc/archi#83.
Root cause
gh pr view --repo owner/name --json numbercannot infer the current PR from the local checkout when--repois passed — it requires an explicit branch, number, or URL as a positional. The runner was callinggh pr view "${repo_args[@]}" --json numberwithout one, so every call errored whenRALPH_REPOorGH_REPOwas set. The error was caught byensure_pr's error handling, but classified as "gh errored" and narrated rather than falling through to create — so the gate skipped every turn.What changed
base/scripts/ralph.sh(ensure_pr): bothgh pr viewcalls (initial check at the top and post-create confirmation) now pass$branchas the positional. Also switchedgh pr create --headand--titlefrom$(working_branch)to the already-captured$branchto avoid redundant subshell forks.base/tests/test_review_gate.sh: new case 21 — withRALPH_REPO=acme/widgets, asserts thatgh pr view ... --json numbercalls includefeat(the fixture's working branch) alongside--repo.Release
Base image only —
base/scripts/changed, so amake build-baserebuild is needed on each loop machine. No skill/template change, so no plugin version bump.Test plan
make test— all suites pass (33 review-gate tests including new case 21)make loopwithRALPH_REPOset should create/find the PR