Skip to content

fix(gh): rewrite gh search commands#1518

Open
season179 wants to merge 2 commits into
rtk-ai:developfrom
season179:fix/gh-search-rewrite
Open

fix(gh): rewrite gh search commands#1518
season179 wants to merge 2 commits into
rtk-ai:developfrom
season179:fix/gh-search-rewrite

Conversation

@season179

Copy link
Copy Markdown

Summary

  • Rewrite gh search ... commands through rtk gh so hook-based integrations no longer leave GitHub search output raw.
  • Require a real gh subcommand boundary so lookalikes like gh searching or gh repository do not get rewritten.
  • Add regression coverage for gh search repos/issues/prs/code/commits, structured-output passthrough flags, and false-positive subcommand prefixes.

Fixes #1484

Test plan

  • rtk cargo +1.92.0 test test_rewrite_gh_search -- --nocapture
  • rtk cargo +1.92.0 test test_rewrite_gh_search_structured_output_skipped -- --nocapture
  • rtk cargo +1.92.0 test test_rewrite_gh_subcommands_require_word_boundary -- --nocapture
  • rtk cargo +1.92.0 test test_classify_gh_search -- --nocapture
  • rtk cargo +1.92.0 test test_all_patterns_are_valid_regex -- --nocapture
  • rtk cargo +1.92.0 fmt --all -- --check
  • rtk cargo +1.92.0 clippy --all-targets (passes with existing warnings)
  • rtk git diff --check
  • Manual: rtk cargo +1.92.0 run --quiet -- rewrite 'gh search repos foo --limit 5' rewrites to rtk gh search repos foo --limit 5
  • Manual: gh search structured output flags (--json) do not rewrite
  • Manual: false positives like gh searching foo do not rewrite

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 25, 2026
@pszymkowiak

Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟢 Risk low

Summary

Adds support for rewriting gh search subcommands (repos, issues, prs, code, commits) through rtk gh by extending the existing regex pattern. Introduces a word boundary check ((?:\s|$)) to prevent false positives on similar-looking subcommands like gh searching. Structured output flags (--json, --template) are correctly skipped from rewriting.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

Linked issues: #1484


Analyzed automatically by wshm · This is an automated analysis, not a human review.

@aeppling

aeppling commented Jun 7, 2026

Copy link
Copy Markdown
Contributor

Hello, and thanks for the contribution.

One issue before merge: routing without an output filter creates a false savings claim.

gh_cmd.rs::run() has no "search" arm, so rtk gh search repos rust falls through to run_passthrough (0 bytes saved). But the inherited savings_pct: 82.0 in rules.rs means rtk gain will report 82% on every gh search call.

Quickest fix: add ("search", 0.0) to subcmd_savings so the dashboard reflects reality. A real filter + fixture can come as a follow-up.

The (?:\s|$) boundary addition is a nice side-benefit — it also fixes gh release-notes and gh repository view getting wrongly matched by the old pattern.

gh search routes through rtk gh but has no output filter (gh_cmd.rs
passes it straight through), so it was inheriting the rule's 82%
savings_pct in the discover projection — overstating the gain on a
command that filters nothing.

Add a ("search", 0.0) subcmd_savings override and mark it
RtkStatus::Passthrough so the projection and status badge reflect
reality, matching the cargo fmt passthrough convention. Tighten
test_classify_gh_search to pin the 0% savings and Passthrough status.
@season179

Copy link
Copy Markdown
Author

Hi, added the fix

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

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

gh search subcommand still unhandled by hook in 0.37.2 — appears related to #446

3 participants