Skip to content

fix: gh pr/issue/run view drops flags when no identifier given#217

Open
shadowofdoom wants to merge 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-view-passthrough-flags
Open

fix: gh pr/issue/run view drops flags when no identifier given#217
shadowofdoom wants to merge 1 commit intortk-ai:masterfrom
shadowofdoom:fix/gh-view-passthrough-flags

Conversation

@shadowofdoom
Copy link
Contributor

Problem

view_pr(), view_issue(), and view_run() all assume args[0] is an identifier (PR number, issue number, run ID). But gh allows calling view without an identifier — it defaults to the current branch.

When users run gh pr view --json number,title,... (no PR number), the rtk-rewrite hook transforms it to rtk gh pr view --json number,title,.... Then view_pr() takes "--json" as the PR number and appends its own --json fields:

gh pr view --json --json number,title,state,author,body,...
           ^^^^^^
           treated as PR number, then rtk adds its own --json

Result: Unknown JSON field: "--json" — gh interprets the double --json as a field name.

Same pattern breaks:

  • gh pr view --json fieldsUnknown JSON field: "--json"
  • gh issue view --json fields → same error
  • gh pr view 42 --json custom,fields → rtk's hardcoded fields override user's

This is a generalization of the view_run fix from PR #159, which only handled --log-failed/--log/--json after a run ID but not the no-identifier case.

Fix

Replace the narrow should_passthrough_run_view() with a generic should_passthrough_gh_view() that detects:

  1. First arg is a flag (--json, --web, etc.) — no identifier given, gh will default to current branch
  2. Any arg is --json, --log, or --log-failed — output incompatible with rtk's summary filter

Applied to all three functions: view_pr(), view_issue(), view_run().

Also simplifies the passthrough plumbing: removes run_passthrough_with_extra() in favor of reusing the existing run_passthrough() with a small prepend_arg() helper.

Test plan

  • 7 unit tests for should_passthrough_gh_view():
    • --json as first arg (no identifier) → passthrough
    • --json after identifier → passthrough
    • --log-failed after identifier → passthrough
    • --log after identifier → passthrough
    • --web as first arg (no identifier) → passthrough
    • identifier only → no passthrough (use filter)
    • empty args → no passthrough
  • All 414 tests pass (cargo test)
  • cargo fmt and cargo clippy clean
  • Manual: rtk gh pr view --json number,title returns JSON (no error)
  • Manual: rtk gh pr view 42 --json number,title returns user-requested JSON

🤖 Generated with Claude Code

view_pr(), view_issue(), and view_run() all assumed args[0] is an
identifier (PR number, issue number, run ID). When users omit the
identifier (relying on gh's current-branch default), flags like
--json get treated as the identifier, producing broken commands
like `gh pr view --json --json fields...`.

Replace narrow should_passthrough_run_view() with generic
should_passthrough_gh_view() that detects:
- First arg is a flag (no identifier given)
- Any arg is --json, --log, or --log-failed (output incompatible
  with rtk's summary filter)

Also removes run_passthrough_with_extra() in favor of reusing
existing run_passthrough() with prepend_arg() helper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
heAdz0r added a commit to heAdz0r/rtk that referenced this pull request Feb 28, 2026
…tk-ai#217, rtk-ai#196, rtk-ai#248, rtk-ai#211, rtk-ai#200, rtk-ai#192, rtk-ai#268)

Wave 1 (critical bugs):
- fix(registry): fi/done moved to IGNORED_EXACT — find no longer shadowed (rtk-ai#246)
- fix(playwright): f64 duration, specs[] structure, --reporter=json after subcmd (rtk-ai#193)
- fix(gh): should_passthrough_gh_view for --json/--jq/--template/--web in view_pr/issue/run (rtk-ai#217+196)

Wave 2 (reliability):
- fix(git): is_blob_show_arg — blob show passthrough without trailing-newline trim (rtk-ai#248)
- fix(find): parse_find_args with native -name/-type/-maxdepth/-iname support (rtk-ai#211)
- fix(main): graceful Clap fallback + parse_failures SQLite table + rtk gain --failures (rtk-ai#200)

Wave 3 (UX):
- feat(git): global options -C/-c/--git-dir/--work-tree/--no-pager/--no-optional-locks/--bare/--literal-pathspecs (rtk-ai#192)
- feat(proxy): streaming output via spawn()+threads instead of buffered output() (rtk-ai#268)

Tests: 1091 → 1117 (+26), 0 regressions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

pszymkowiak commented Mar 2, 2026

Tested locally — pr view works correctly but found two inconsistencies:

  • rtk gh pr view (no identifier) → delegates to gh ✅
  • rtk gh pr view --json number → passthrough ✅
  • rtk gh pr view 217 → still filtered normally ✅
  • rtk gh issue view (no identifier) → Error: Issue number required
  • rtk gh run view (no identifier) → Error: Run ID required

view_issue() and view_run() still return an error on empty args instead of delegating like view_pr() does. Could you apply the same fix to those two functions?

@FlorianBruniaux
Copy link
Collaborator

Hi @shadowofdoom! We have multiple gh flag passthrough PRs open (#196, #217, #319, #325, #328). They all conflict with each other. Could you rebase both PRs on latest master first to fix the CI failures, then we'll coordinate which approach to take? Alternatively, feel free to consolidate your two PRs into one — that would help.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants