get-pr-comments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Get PR Comments

获取PR评论

Fetch, organize, and present all comments on a GitHub pull request — issue-level comments, review bodies, and inline review comments — grouped by human vs bot, with actionable items (must-fix, optional) extracted from structured reviews and inline comments.
获取、整理并展示GitHub pull request上的所有评论——包括议题级评论、评审正文和内联评审评论——按人工评论与机器人评论分组,并从结构化评审和内联评论中提取可操作项(必须修复、可选修复)。

Pre-Flight Context

预飞上下文

  • Current branch:
    !git rev-parse --abbrev-ref HEAD
  • Repo:
    !gh repo view --json nameWithOwner --jq .nameWithOwner 2>/dev/null || echo "unknown"
  • Current branch PR:
    !gh pr view --json number,title --jq '"\(.number) — \(.title)"' 2>/dev/null || echo "none"
  • 当前分支:
    !git rev-parse --abbrev-ref HEAD
  • 仓库:
    !gh repo view --json nameWithOwner --jq .nameWithOwner 2>/dev/null || echo "unknown"
  • 当前分支关联PR:
    !gh pr view --json number,title --jq '"\(.number) — \(.title)"' 2>/dev/null || echo "none"

Workflow

工作流程

1. Identify the PR

1. 识别PR

Parse
$ARGUMENTS
for a PR number or URL. If present, use it directly.
If no arguments provided, check the pre-flight "Current branch PR" value. If it contains a PR number (not "none"), use the detected PR.
If no PR detected, list open PRs:
bash
gh pr list --state open --limit 10 --json number,title,headRefName --jq '.[] | "\(.number)\t\(.title)\t(\(.headRefName))"'
If the list is empty, report "No open PRs found for this repository" and stop. If only one open PR exists, use it directly. Otherwise present options via AskUserQuestion.
解析
$ARGUMENTS
以获取PR编号或URL。如果存在,则直接使用。
如果未提供参数,检查预飞上下文的“当前分支关联PR”值。如果其中包含PR编号(不是“none”),则使用检测到的PR。
如果未检测到PR,则列出所有开放PR:
bash
gh pr list --state open --limit 10 --json number,title,headRefName --jq '.[] | "\(.number)\t\(.title)\t(\(.headRefName))"'
如果列表为空,报告“此仓库未找到开放PR”并停止操作。如果仅存在一个开放PR,则直接使用该PR。否则通过AskUserQuestion提供选项供用户选择。

2. Fetch comments

2. 获取评论

Run the fetch script with the resolved PR number (default text output is pre-formatted and token-efficient; use
--output json
only for programmatic consumers):
bash
python3 ${CLAUDE_PLUGIN_ROOT}/skills/get-pr-comments/scripts/fetch_pr_comments.py <PR_NUMBER>
Exit 0 = proceed. Exit 2 =
gh
auth or network error — report to user.
使用解析得到的PR编号运行获取脚本(默认文本输出已预格式化且令牌效率高;仅在供程序使用时才使用
--output json
参数):
bash
python3 ${CLAUDE_PLUGIN_ROOT}/skills/get-pr-comments/scripts/fetch_pr_comments.py <PR_NUMBER>
退出码0 = 继续执行。退出码2 =
gh
认证或网络错误——向用户报告该错误。

3. Present results

3. 展示结果

The script output is already formatted for presentation. If the output starts with "0 human, 0 bot", report "No comments on this PR yet" and skip to Step 4.
Otherwise, relay the script output directly. The output is structured as: actionable items (must-fix, optional) first, then human comments, then bot comments (truncated). Do not reformat or reparse — present as-is.
If must-fix items are listed, check whether a subsequent review already resolved them by querying both issue comments and formal PR reviews. Pipe to external
jq
gh api
rejects
--slurp
combined with
--jq
in current versions, and
--paginate --slurp
yields an array-of-pages that must be flattened with
[.[][]]
:
bash
undefined
脚本输出已为展示做好格式化处理。如果输出以“0 human, 0 bot”开头,报告“此PR暂无评论”并跳至步骤4。
否则,直接转发脚本输出。输出结构为:先展示可操作项(必须修复、可选修复),然后是人工评论,最后是机器人评论(已截断)。请勿重新格式化或重新解析——直接原样展示。
如果列出了必须修复项,通过查询议题评论和正式PR评审,检查后续评审是否已解决这些问题。通过外部
jq
处理——当前版本的
gh api
不支持
--slurp
--jq
结合使用,而
--paginate --slurp
会生成一个页面数组,必须用
[.[][]]
进行扁平化处理:
bash
undefined

Latest issue-level comment (paginated — PRs may exceed 30 comments):

最新议题级评论(分页处理——PR评论可能超过30条):

gh api repos/{owner}/{repo}/issues/<PR_NUMBER>/comments --paginate --slurp
| jq -r '[.[][]] | last | .body // ""'
gh api repos/{owner}/{repo}/issues/<PR_NUMBER>/comments --paginate --slurp
| jq -r '[.[][]] | last | .body // ""'

Latest formal PR review body (approvals and review-body sign-offs land here,

最新正式PR评审正文(批准和评审正文签字确认会在此处显示,而非议题评论中):

not in issue comments):

gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/reviews --paginate --slurp
| jq -r '[.[][] | select(.body != "")] | last | .body // ""'

If either output contains phrases like "ready to merge", "all issues fixed",
"lgtm", "approved", or similar resolution language, surface that summary first
with a note that the listed must-fix items may already be resolved. Then
present the full script output.
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/reviews --paginate --slurp
| jq -r '[.[][] | select(.body != "")] | last | .body // ""'

如果任一输出包含“ready to merge”“all issues fixed”“lgtm”“approved”或类似表示已解决的表述,先展示该摘要,并注明列出的必须修复项可能已解决。然后再展示完整的脚本输出。

4. Suggest next steps

4. 建议下一步操作

After presenting comments, offer context-appropriate actions:
  • If must-fix items exist: "Want me to address these must-fix items?"
  • If inline comments reference specific files: "Want me to read the referenced files and check if these issues are already resolved?"
  • If the PR is the user's: "Want me to respond to any of these comments?"
展示评论后,提供符合上下文的操作选项:
  • 如果存在必须修复项:“需要我处理这些必须修复项吗?”
  • 如果内联评论引用了特定文件:“需要我读取引用的文件并检查这些问题是否已解决吗?”
  • 如果该PR属于用户:“需要我回复这些评论中的任意一条吗?”