Skip to content

fix: pass branch positional to gh pr view when --repo is set - #32

Merged
swinney merged 1 commit into
mainfrom
fix/issue-83-pr-view-branch-positional
Aug 10, 2026
Merged

fix: pass branch positional to gh pr view when --repo is set#32
swinney merged 1 commit into
mainfrom
fix/issue-83-pr-view-branch-positional

Conversation

@swinney

@swinney swinney commented Aug 10, 2026

Copy link
Copy Markdown
Owner

Summary

  • Pass the working branch as a positional argument to gh pr view in ensure_pr(), fixing the review-gate's inability to find or create PRs when --repo is set
  • Add test case 21 verifying the branch positional appears alongside --repo

Fixes fasrc/archi#83.

Root cause

gh pr view --repo owner/name --json number cannot infer the current PR from the local checkout when --repo is passed — it requires an explicit branch, number, or URL as a positional. The runner was calling gh pr view "${repo_args[@]}" --json number without one, so every call errored when RALPH_REPO or GH_REPO was set. The error was caught by ensure_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): both gh pr view calls (initial check at the top and post-create confirmation) now pass $branch as the positional. Also switched gh pr create --head and --title from $(working_branch) to the already-captured $branch to avoid redundant subshell forks.

base/tests/test_review_gate.sh: new case 21 — with RALPH_REPO=acme/widgets, asserts that gh pr view ... --json number calls include feat (the fixture's working branch) alongside --repo.

Release

Base image onlybase/scripts/ changed, so a make build-base rebuild 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)
  • Case 21 fails on the parent commit, passes after the fix
  • Live smoke: a make loop with RALPH_REPO set should create/find the PR

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>

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread base/scripts/ralph.sh
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.$$)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Badge 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 👍 / 👎.

@swinney
swinney merged commit 1eb78c3 into main Aug 10, 2026
1 of 2 checks passed
@swinney
swinney deleted the fix/issue-83-pr-view-branch-positional branch August 10, 2026 23:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Ralph runner review-gate can't open a PR when GH_REPO is set (gh pr view --repo missing branch positional)

1 participant