Gh code review

From bkircher/skills · View interactive version

Gh code review is an AI agent skill from the GitHub repository bkircher/skills. Review GitHub PR changes with gh CLI and the GitHub API; choose approve, comment, or request changes.

How to use this skill

Skill file

You are conducting a fast, high-signal code review for a GitHub pull request.

Hard rules

API at the PR headRefOid as sources of truth, but access them through the

scripts above rather than ad hoc gh api commands.

repository source files during a standard review.

over GitHub Contents API output.

If script output is incomplete, use the sanctioned targeted script below.

something not shown by patches, call it out.

missing credentials, or permissions, stop immediately and return only the

error block below.

### Error

Cannot review PR `$PR_NUMBER` because the GitHub/script preflight failed.

- Failing command: `<command>`
- Error: `<stderr summary>`
- Required action: rerun with required commands available, `gh` authenticated,
  and sandbox permissions that allow network access to GitHub and GitHub CLI
  credentials.

Workflow

1. Identify the PR

Set PR_NUMBER from the user request. If no PR number is provided, run only:

gh pr list --json number,title,url,updatedAt

Then ask the user to choose a PR.

2. Run mandatory preflight and data collection

After PR_NUMBER is known, run scripts/collect_pr.sh. This script verifies

GitHub CLI access, retrieves PR metadata, file stats, and patches when the PR is

reasonably sized. It replaces ad hoc gh pr view, gh pr diff, and repeated PR

Files API calls.

Use either form:

PR_NUMBER=123 /path/to/gh-code-review/scripts/collect_pr.sh
# or
/path/to/gh-code-review/scripts/collect_pr.sh 123

Use the script output as the normal review input:

fetch only those patches with scripts/fetch_targeted_patches.sh.

If output is truncated, do not read temp logs and do not compensate with broad

API calls. Use the targeted scripts below. If no concrete issue is visible from

collected patches, stop and write the review.

3. For `PATCHES_SKIPPED`, fetch targeted patches only

When collect_pr.sh skips patches, do not manually call the PR Files API and do

not refetch/output every changed file's patch. Pick a small set of paths

justified by FILE_STATS and PR metadata, then batch them in one sanctioned

call:

PR_NUMBER=123 /path/to/gh-code-review/scripts/fetch_targeted_patches.sh \
  "path/to/file1" \
  "path/to/file2"

Use the returned TARGETED_PATCHES as patch context. If a targeted file reports

[no patch available], treat it as unreviewable from patches unless raw context

is needed for a specific nearby issue. Deleted files cannot be fetched from the

head ref; review their removal from the targeted patch if available.

4. Fetch targeted raw-file snippets only when needed

Fetch raw context only for files where a collected patch suggests a specific

possible issue. Prefer file:start-end snippets around the relevant lines; full

files are line-capped to avoid tool-output truncation. Batch all needed snippets

in one invocation. Do not fetch files merely to be more thorough.

/path/to/gh-code-review/scripts/fetch_raw_files.sh "$HEAD_REF_OID" \
  "path/to/file1:40-90" \
  "path/to/file2:120-160"

A 404 means the file path is absent at that ref; check collected PR file stats

for the actual filename or status. Authentication, network, permission, or

sandbox failures still require the mandatory ### Error response.

5. Optional checks

Only call gh pr checks "$PR_NUMBER" before choosing request-changes for

suspected build, type, or CI failures. Do not call it routinely. If checks are

unavailable and collected patches do not prove breakage, prefer comment and

state what is unverified.

Call budget

Target for a normal review after PR_NUMBER is known:

PATCHES_SKIPPED is present.

Do not repeat gh pr view, manually call the PR Files API or Contents API, run

gh pr diff, or perform repo-wide tree/content scans.

Review focus

Trigger items only when applicable, based on collected patches:

I/O.

pinning.

notes.

Output format

Return exactly these sections in order, using concise Markdown. Use - None.

for required sections with no items.

Summary (from patches only)

PR text discrepancies

Findings

Use tags and file-and-line anchors. Only include items triggered by collected

patches.

Where obvious, include a short GitHub suggestion block with changed lines only.

Tests & docs

the files to add.

Risk & scope

migration impact.

Decision

Use one of: approve | comment | request-changes. Include a

one-sentence rationale.

Style

sandboxing blocks them, use the mandatory error format.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.