better-github-skill
Raw gh first when you know the command; the scripts replace only the flows
agents repeatedly get wrong. Scripts run TS directly (node ≥ 23.6), no deps.
Scripts
| script | use for |
|---|---|
scripts/pr-snapshot.ts [pr] [-R o/r] | full PR state in one call: meta, mergeability, checks, files, reviews, comments, thread counts. Use instead of hand-assembling pr view --json field sets or chaining view/checks/comments calls. |
scripts/pr-threads.ts [pr] [-R o/r] [--all] [--author X] [--since ISO] | the full review conversation: review bodies, issue comments, and unresolved inline threads (resolution state porcelain gh cannot get). Resolved/outdated threads are hidden by default, counted in the header; --all includes them. Read-only: never reply to or resolve threads unless explicitly told to. |
scripts/pr-watch.ts [pr] [-R o/r] [--timeout 9m] | wait on a PR: blocks until a check fails, the required or all checks pass, someone else comments or reviews, the branch conflicts, or the PR merges or closes; prints what happened. Rerun after acting; it never repeats news. Quiet PRs cost nothing (conditional requests). Run it in the background, or give the tool a timeout above --timeout. |
scripts/ci-failures.ts [run-id] [--pr N] [--list] [-R o/r] | failing checks → failing jobs/steps → log snippet each; full logs saved to files (paths printed); rg those instead of re-fetching. --list [--workflow W] [-L n] shows recent runs with conclusions; use it to find the failing run id instead of gh run list --json field sets. |
Rule of thumb: pr-snapshot answers "what's the state of this PR", pr-threads answers "what did reviewers write". Neither replaces the other.
All scripts: --json for structured output, --help for usage (includes the
--json shape). Omit the PR number to use the current branch's PR. Default
output is sized for context; pass --full only when a truncation marker
([…+N chars]) hides something you need. They exit 0 when the report
succeeds even if CI is red or threads are unresolved.
Gotchas (each one burned real sessions repeatedly)
- Never pipe gh into
head: SIGPIPE can kill gh mid-write (spurious nonzero exit, shell-dependent) or silently truncate large output. Redirect to a file and read that, or trim with--jq '.[0:20]'. gh pr diffhas no--statand no positive pathspec (--name-onlyand-e/--excludeglobs exist in gh ≥ 2.95). Per-file stats:gh api 'repos/{owner}/{repo}/pulls/N/files' --jq '.[]|[.filename,.additions,.deletions]|@tsv'Full diff:gh pr diff N > "$TMPDIR/pr.diff"once, then rg/sed the file.gh pr checksexits 1 = failing, 8 = pending by design; append|| true, read the table.- File at any ref, no base64 dance:
gh api 'repos/{owner}/{repo}/contents/PATH?ref=SHA' -H 'Accept: application/vnd.github.raw' gh apifills{owner}/{repo}from the cwd repo (GH_REPO=o/roverrides). Quote any api path containing?(zsh globs it), or use-X GET -F per_page=100(any-f/-Fsilently flips the request to POST without-X GET).--paginateon any list endpoint (/comments,/files,/reviews);--jqalready runs per page; don't add--slurp.- PR/comment bodies:
--body-file file.mdor a quoted heredoc. Never inline--body "..."containing backticks. - Field cheat-sheet: CI status on a PR =
statusCheckRollup(pr view); steps live undergh run view N --json jobs;gh search prsfields ≠gh pr viewfields. - gh has no
-C; pass-R owner/repoto every command, or cd first. - Branch rules live at
gh api 'repos/{owner}/{repo}/rulesets'on modern repos;/branches/main/protection404s unless classic protection is on AND you have admin ("Branch not protected" or plain "Not Found" both mean check rulesets; neither is a path error). - Branch drift:
gh api 'repos/{owner}/{repo}/compare/BASE...HEAD' --jq '{ahead_by,behind_by}' - jq beyond one line: write the program to a file and
jq -f prog.jq; inline zsh quoting breaks.
Rate limits
Every agent on the account shares 5,000 REST requests and 5,000 GraphQL points an hour.
- Waiting on CI or reviewers is
pr-watch.ts, nevergh run watch(~60 REST calls a minute),gh pr checks --watch(a GraphQL query every 10s) or a sleep loop aroundgh pr view. A watched check failing?ci-failures.ts. - Checking the budget is free:
gh api rate_limit --jq '.resources|{core,graphql}'. - Repeat reads of slow-changing data:
gh api --cache 1h PATHanswers from disk without a request. - Writes have a second cap: about 80 content-creating requests a minute and 500 an hour per account (comments, reviews, issues, PRs; the web UI counts too). Post one at a time, never in parallel. Put findings in one review rather than a comment each, and keep its inline comments well under 80: a review with 119 was refused on every try.
- Rate limited (403/429)? Wait
retry-afterseconds, or untilx-ratelimit-resetwhenx-ratelimit-remainingis 0, else a minute, then double. Retrying sooner extends the block.


