Skip to content

feat(zsh): complete PR numbers for gh pr view/update-branch - #367

Merged
laurigates merged 2 commits into
mainfrom
feat/gh-pr-number-completion
Aug 19, 2026
Merged

laurigates merged 2 commits into
mainfrom
feat/gh-pr-number-completion

Conversation

@laurigates

Copy link
Copy Markdown
Owner

What

Adds _gh_pr_numbers, a zsh completion wrapper that offers open PR numbers at
the first positional of gh pr view, gh pr update-branch, and the eleven
sibling subcommands that take [<number> | <url> | <branch>]. Everything else
— subcommands, flags, other command trees — is handed straight back to gh's
own cobra-generated _gh.

Ships with tests/test-gh-completion.sh.

Why

gh registers no completion for that positional:

$ gh __complete pr view ""
:0
Completion ended with directive: ShellCompDirectiveDefault

Zero candidates with directive 0 tells the shell to fall back to file
completion, so gh pr view <TAB> currently offers the working directory.

Upstream tracks this as cli/cli#360, open since 2020-02-12 with 42 👍. A
working ValidArgsFunction patch for pr/view sits in that thread from 2022
and was never turned into a PR; maintainers have twice said the mechanism is
right but that they want a caching foundation for API-powered completions
first. The issue picked up the pitch label ("pitched internally for
prioritisation") on 2026-03-10 and lost help wanted on 2025-04-10 — so it is
alive, unbuilt, and not soliciting outside patches. Local workaround until it
lands. Related: cli/cli#360, cli/cli#11406.

How

Same wrap-and-delegate shape as _chezmoi_edit_managed directly above it:

  • _gh_pr_at_number_arg walks $words, skipping flags and the values of the
    ones that take an argument (-R, --jq, …), and fires only when exactly two
    positionals (pr, <sub>) precede the cursor. gh pr view 123 <TAB> and
    gh pr list <TAB> fall through.
  • Candidates use _describe's number:description pair form, which splits at
    the first colon — so only the bare number is inserted while branch, title and
    author stay in the description column and the fzf-tab preview. The gh*
    wrapper completions below use a number[branch] title form and strip the
    suffix in _gh_pick_arg; that is not available here, since the real gh
    consumes the word verbatim.

Uncached, matching the existing gh* wrapper completions: each TAB at that
position costs one gh pr list (~0.5–1 s). Outside a GitHub repo the candidate
list comes back empty and completion falls through to _gh.

Testing

tests/test-gh-completion.sh — 18 assertions, all passing:

  • 11 unit assertions on position detection, driving _gh_pr_at_number_arg
    directly over synthetic $words/$CURRENT (gh -R o/r pr view fires,
    gh pr view 123 does not, gh issue view does not, …).
  • 4 end-to-end checks over a real interactive zsh on a pty (zsh/zpty),
    reading back what TAB actually inserted: gh pr view <TAB> and
    gh pr update-branch <TAB> insert the PR numbers; gh pr vie<TAB> still
    completes to view and gh pr view --w<TAB> to --web, proving delegation
    survives.
  • 1 control run with the hook not loaded, which requires the file-completion
    fallback to appear. Without it a green suite would prove nothing about the
    hook.

The completion code under test is extracted from chezmoi cat ~/.zshrc rather
than retyped into the harness, so the test exercises the text that reaches
~/.zshrc. The control repo is chosen at runtime from repos that actually have
open PRs, and the suite SKIPs loudly rather than passing vacuously when none is
reachable.

gh registers no completion for the `[<number> | <url> | <branch>]` positional:
`gh __complete pr view ""` returns zero candidates with directive 0
(ShellCompDirectiveDefault), which tells the shell to fall back to file
completion. `gh pr view <TAB>` therefore offers the working directory.

Add `_gh_pr_numbers`, which supplies open PR numbers at that position for the
thirteen `gh pr` subcommands that take it and delegates everything else to the
cobra-generated `_gh` — the same wrap-and-delegate shape as
`_chezmoi_edit_managed` directly above it. Candidates use `_describe`'s
`number:description` pair form so only the bare number is inserted, since the
real gh consumes the word verbatim and cannot strip a suffix the way
`_gh_pick_arg` does for the `gh*` wrappers.

Uncached, matching those wrappers: one `gh pr list` per TAB at that position.

Upstream has this as cli/cli#360, open since 2020 and labelled `pitch` in
2026-03 (pitched internally, `help wanted` removed), gated on a caching
foundation for API-powered completions.

Covered by tests/test-gh-completion.sh: 11 unit assertions on position
detection plus 4 pty-driven end-to-end checks, and a control run with the hook
unloaded that requires the file-completion fallback to reappear.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HjMHsjiYriW362KrsuwV2N
Every script in tests/ has a matching `test:*` mise task; without one the
gh-completion suite is orphaned and would only run when someone invokes it by
path. Same wrapper shape as test:shell-precedence.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01HjMHsjiYriW362KrsuwV2N
@laurigates
laurigates merged commit c2bb331 into main Aug 19, 2026
8 checks passed
@laurigates
laurigates deleted the feat/gh-pr-number-completion branch August 19, 2026 11:03
laurigates added a commit that referenced this pull request Aug 19, 2026
…368)

## What

ADR-0017 records the decision to test macOS alongside Ubuntu in CI,
replacing
the Ubuntu-only status quo that has held since 2025-09-15. Docs only —
the
workflow change lands separately.

Also updates the ADR index and the count in `CLAUDE.md`.

## Why

`a264a61` ("ci: simplify smoke test workflow", #78) removed `lint-macos`
and
`build-macos`, giving as its reason *"reduce CI complexity and runtime"*
— in
the same commit that swapped individual linters for pre-commit and moved
shell
testing from zsh to fish. Two beliefs accumulated afterwards and were
repeated
when the decision came up again: that macOS runners are expensive, and
that
they are slow. Both were checked; neither holds here.

**Cost.** Public repositories bill standard runners at zero, macOS
included.
Measured rather than inferred, against a sibling public repo that does
run
macOS jobs:

```
$ gh api repos/laurigates/kicad-mcp/actions/runs/30608467472/timing --jq .billable
MACOS:  jobs=3  total_ms=0
UBUNTU: jobs=7  total_ms=0
```

The 10× macOS multiplier applies to private repositories and paid
minutes.
GitHub's billing docs are ambiguous about whether `macos-latest` counts
as a
"larger runner", which is where the belief came from; the billing API is
not.

**Runtime.** Same run: macOS queued 2–3 s against Ubuntu's 2–4 s and ran
25–33 s against Ubuntu's 22–27 s — ~20% slower, not an order of
magnitude.
This repo's `smoke.yml` currently runs Linters 92 s + Build (Ubuntu) 46
s.

**Coverage.** `Build (Ubuntu)` runs `chezmoi apply` under
Homebrew-on-Linux. It
catches template and source-tree errors, and it usefully guards against
macOS-only assumptions leaking into cross-platform paths — but it cannot
exercise zsh startup, macOS formula availability, completion generation,
or
launchd. That is the surface this repo exists to configure.

## What the ADR does not claim

The 2025-09 removal also cited *complexity*, and this ADR does not
disprove
that — only the cost and runtime claims were measured. The ADR says so,
and
records that if the macOS job proves flaky the response should be moving
it to
a schedule rather than deleting it, so the coverage question stays
visible.

The daily-driver counter-argument is recorded rather than dismissed:
macOS
breakage does surface within hours anyway, which makes this a
convenience. The
ADR's position is that it is a convenience that catches regressions
before they
reach the machine the author depends on.

## Scope limit worth flagging

`tests/test-gh-completion.sh` (added in #367) is explicitly kept out of
CI. It
drives a pty against whatever PRs happen to be open, so its candidate
set is
live remote state — it would be green or skipped depending on the day.
CI runs
tests whose inputs live in the repository.

## Follow-ups

Four separate PRs, each independent:

- restore the macOS job in `smoke.yml` (implements this ADR; also
corrects the
  now-false "Multi-platform (Ubuntu/macOS)" line in `CLAUDE.md`)
- migrate the four drifted workflows to their `laurigates/.github`
counterparts
- workflow-level `permissions` and `concurrency` on the checks that lack
them
- Renovate `helpers:pinGitHubActionDigests` for SHA pinning

Co-authored-by: Claude Opus 5 (1M context) <[email protected]>
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.

1 participant