360 Secure SkillHub
360 安全技能中心

gh

通过 gh 与 gh api 读取 PR 状态、评审线程、评论、CI 检查和运行日志,支持筛选、分页与失败归因,并可向 PR 发布一条评论或线程回复;不修改代码、不创建或更新 PR,也不合并 PR 或解决线程。

分类:开发
prathamdby
热度 0.00
最近更新 2026-12-02 12:22:19

安装

发给 Agent
帮我安装这个技能:npx secure-skills-cli add prathamdby/skills/gh
兼容性
通用兼容
联网要求
需要联网
数据出网
必须出网
Metadata
name
gh
description
Inspect GitHub pull-request status, review threads, comments, CI check failures, workflow logs, or other GitHub records, and post a single PR comment or inline thread reply without changing code. Use whenever the user asks what failed in CI, why checks are red, what reviewers said, PR mergeability, or to reply on a PR without edits, instead of ad-hoc gh commands. Do not use to fix code for PR feedback or CI (use fix-pr) or to open or update a PR (use make-pr).

Use gh and gh api directly to inspect pull request state, read discussions, diagnose CI failures, read other GitHub records, or post one reply without changing code. Confirm gh is installed and authenticated (gh auth status) before doing anything, and stop on missing binary or auth errors.

Default to the current branch's pull request in the current repo, returning truncated text unless I ask for full bodies or structured JSON. If I give you a PR number or URL, target that one instead. If I name another repo, pass -R owner/repo on gh pr or gh run commands (and always include a PR number for PR-bound work). Stop on conflicting choices or missing values, and if there is no PR on the current branch for PR-bound work, say so and stop. Never resolve review threads, push commits, or merge pull requests from this skill.

Open references/commands.md whenever you run PR snapshots, thread collection, CI failure drilldowns, log downloads, or PR replies so every run uses the exact same deterministic commands, pagination loops, and fallback steps.

Keep PR state separate from PR discussions, because neither replaces the other. A snapshot covers title, state, draft flag, author, URL, base and head branches, head SHA, mergeability, merge state status, review decision, body, file stats, check buckets (pass, fail, pending, skipping, cancel), latest non-PENDING review per author, recent comments, and open versus total thread counts. If a combined GraphQL snapshot fails with complexity, timeout, or 5xx, fall back to the split commands in references/commands.md.

For discussions, collect nonempty non-PENDING review bodies, conversation comments, and inline review threads, keeping each thread's path, line, originalLine, isResolved, isOutdated, and first comment databaseId and url (REST replies target that root comment databaseId, not the GraphQL thread ID). Hide resolved and outdated threads by default. If I ask for open threads, keep unresolved threads including outdated ones. If I ask for all threads, include resolved too (stop if open and all are both requested).

Author filters keep conversation items by that author and threads where any comment is by that author. ISO 8601 since filters keep conversation items at or after that timestamp and threads where any comment is at or after that timestamp (stop on an invalid date). Tell me explicitly whenever any list is truncated or capped, because partial data never counts as exhaustive.

For CI inspection, pin checks to a known head SHA with filter=latest&per_page=100 (and commit statuses) when available, list recent runs with gh run list (default limit 10, optional workflow filter), or inspect a specific Actions run ID directly with gh run view. For CheckRun entries, statuses IN_PROGRESS, QUEUED, WAITING, PENDING, and REQUESTED are pending, SUCCESS is pass, SKIPPED and NEUTRAL are skipping, and conclusions FAILURE, TIMED_OUT, ACTION_REQUIRED, and STARTUP_FAILURE are fail (CANCELLED maps to cancel in snapshot rollups and also counts as a failing run in CI failure drilldowns). For StatusContext entries, SUCCESS is pass, FAILURE and ERROR are fail, and PENDING or EXPECTED are pending.

Actions job drilldown alone does not prove which checks are required versus optional, so query repos/<owner>/<repo>/rules/branches/<base> (or repos/<owner>/<repo>/rulesets/<id>) and cross-check gh pr checks --required when that matters. Remember that red CI or open threads is a successful inspection result, not a tool failure.

Download job logs only through gh api --allow-escape-sequences written directly to a private temporary file (umask 077, 0700 dir, 0600 files), and never forward a GitHub bearer token to a redirected blob URL. Unzip PK ZIP archives into .log files and delete the ZIP, treat a 404 as log not available yet (job still running), never print tokens, Authorization headers, or signed URLs, and cite the saved temp path with focused error snippets instead of pasting full logs.

When posting a reply, require exactly one target (an inline comment databaseId, discussion_rN, or comment URL, or the main PR conversation) and one non-empty body passed via -F body=@<file> or --input - on gh api (or --body-file on gh pr commands) so backticks and quotes stay literal. If I already supplied the reply text, post it verbatim. If you draft the reply yourself, follow the plain voice rules below. Always follow the root-resolution and duplicate-safe fallback procedure in references/commands.md, never silently post a main-conversation fallback unless the caller asks for it, and cite the returned html_url as proof of posting rather than the draft text.

Keep these gh CLI traps in mind on every raw command:

  • Never pipe large gh output into head (it breaks with SIGPIPE). Redirect to a file or slice with --jq.
  • gh api has no -R flag. Use literal repos/<owner>/<repo>/... paths or GH_REPO instead.
  • Passing -f or -F to gh api switches the request to POST unless you pass -X GET. Put GET query params inside the quoted URL, and keep owner and repo strings out of numeric coercion.
  • gh api --paginate emits one JSON document per page, which breaks JSON parsers on page 2+ unless you also pass --slurp to wrap all pages in one outer array (then flatten array pages or object fields locally or by piping to jq). Never use --paginate --jq expecting one merged array across pages, and put multiline jq programs in a temp file passed with jq -f (not gh api -f).
  • gh pr diff has no --stat or positive pathspec. Use repos/<owner>/<repo>/pulls/<N>/files for per-file stats, or save the full diff once and search locally.
  • gh pr checks exits 1 for failures and 8 for pending (both have valid stdout), and "no checks reported" is an empty list, not an error. Empty stdout paired with stderr is a real error.
  • Fetch raw file contents at a ref with -H "Accept: application/vnd.github.raw" and quote ?ref=SHA.
  • Pass bodies via -F body=@<file> or --input - on gh api (or --body-file on gh pr commands), never inline shell strings that can expand backticks or $.
  • PR checks rollup lives on statusCheckRollup, job steps live on gh run view --json jobs, and gh search fields differ from gh pr view fields.
  • gh has no -C flag, so pass -R owner/repo on gh pr or gh run or cd into the repo in the same command.
  • Modern effective branch rules live at repos/<owner>/<repo>/rules/branches/<base> (and individual ruleset definitions at repos/<owner>/<repo>/rulesets/<id>, while a 404 on classic protection does not mean no rules exist). Use repos/<owner>/<repo>/compare/BASE...HEAD for ahead_by and behind_by.
  • Never sleep-poll runs or checks. Use host watchers or background gh run watch or gh pr checks --watch.

Keep your summaries and any reply bodies you draft plain, impersonal, and result-focused: describe the result rather than the investigation, superseded decisions, or who was wrong (keeping required evidence lines), keep one kind of text per section (never mix facts, arguments, and instructions in one paragraph), and write active voice with a named actor, one word per action, and one name per thing. Keep sentences under 25 words (instructions under 20), place "only" and "not" next to what they change, break noun strings longer than three words, make every "it", "this", or "they" point to one clear noun, and use "you" only in an instruction to a person.

Avoid filler, review-session framing, we, let's, please, simply, easy, (s), Latin abbreviations, em dashes, semicolons, slash pairs like and/or, harness footers, and banned AI words (additionally, crucial, delve, enduring, enhance, fostering, garner, interplay, intricate, abstract landscape, pivotal, showcase, tapestry, testament, underscore, vibrant). Paths, SHAs, quoted errors, and code literals are exempt from both the word-length and punctuation limits.