Skip to content

Comments

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

1 participant