github-pr-review

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

GitHub PR Review

GitHub PR 评审

Resolves Pull Request review comments with severity-based prioritization, fix application, and thread replies.
基于严重程度优先级处理PR评审评论,包含修复应用与评论线程回复。

Quick Start

快速开始

bash
undefined
bash
undefined

1. Check project-specific instructions

1. 查看项目特定说明

cat .claude/CLAUDE.md 2>/dev/null | head -50 # Review project conventions
cat .claude/CLAUDE.md 2>/dev/null | head -50 # 查阅项目约定

2. Get PR and repo info

2. 获取PR与仓库信息

PR=$(gh pr view --json number -q '.number') REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
PR=$(gh pr view --json number -q '.number') REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')

3. Fetch and list comments by severity

3. 按严重程度获取并列出评论

gh api repos/$REPO/pulls/$PR/comments | python3 -c " import json, sys comments = [c for c in json.load(sys.stdin) if not c.get('in_reply_to_id')] def sev(b): return 'CRITICAL' if 'critical' in b.lower() else 'HIGH' if 'high' in b.lower() else 'MEDIUM' if 'medium' in b.lower() else 'LOW' for s in ['CRITICAL','HIGH','MEDIUM','LOW']: cs = [c for c in comments if sev(c['body'])==s] if cs: print(f'{s} ({len(cs)}): ' + ', '.join(f"#{c['id]}" for c in cs)) "
gh api repos/$REPO/pulls/$PR/comments | python3 -c " import json, sys comments = [c for c in json.load(sys.stdin) if not c.get('in_reply_to_id')] def sev(b): return 'CRITICAL' if 'critical' in b.lower() else 'HIGH' if 'high' in b.lower() else 'MEDIUM' if 'medium' in b.lower() else 'LOW' for s in ['CRITICAL','HIGH','MEDIUM','LOW']: cs = [c for c in comments if sev(c['body'])==s] if cs: print(f'{s} ({len(cs)}): ' + ', '.join(f"#{c['id]}" for c in cs)) "

4. For each comment: read -> analyze -> fix -> verify -> commit -> reply

4. 针对每条评论:读取 → 分析 → 修复 → 验证 → 提交 → 回复

5. Run tests: make test (or project-specific command)

5. 运行测试:make test(或项目特定命令)

6. Push when all fixes verified

6. 所有修复验证通过后推送

undefined
undefined

Pre-Review Checklist

评审前检查清单

Before processing comments, verify:
  1. Project conventions: Read
    .claude/CLAUDE.md
    ,
    .kiro/steering/
    , or similar
  2. Commit format: Check
    git log --oneline -5
    for project style
  3. Test command: Identify test runner (
    make test
    ,
    pytest
    ,
    npm test
    )
  4. Branch status:
    git status
    to ensure clean working tree
处理评论前,请确认:
  1. 项目约定:阅读
    .claude/CLAUDE.md
    .kiro/steering/
    或类似文件
  2. 提交格式:通过
    git log --oneline -5
    查看项目提交风格
  3. 测试命令:确认测试运行器(
    make test
    pytest
    npm test
    等)
  4. 分支状态:执行
    git status
    确保工作区干净

Core Workflow

核心工作流程

1. Fetch PR Comments

1. 获取PR评论

bash
PR=$(gh pr view --json number -q '.number')
REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
gh api repos/$REPO/pulls/$PR/comments > /tmp/pr_comments.json
bash
PR=$(gh pr view --json number -q '.number')
REPO=$(gh repo view --json nameWithOwner -q '.nameWithOwner')
gh api repos/$REPO/pulls/$PR/comments > /tmp/pr_comments.json

2. Classify by Severity

2. 按严重程度分类

Process in order: CRITICAL > HIGH > MEDIUM > LOW
SeverityIndicatorsAction
CRITICAL
critical.svg
, "security", "vulnerability"
Must fix
HIGH
high-priority.svg
, "High Severity"
Should fix
MEDIUM
medium-priority.svg
, "Medium Severity"
Recommended
LOW
low-priority.svg
, "style", "nit"
Optional
按以下顺序处理:CRITICAL > HIGH > MEDIUM > LOW
严重程度识别标识操作
CRITICAL
critical.svg
、"security"、"vulnerability"
必须修复
HIGH
high-priority.svg
、"High Severity"
应该修复
MEDIUM
medium-priority.svg
、"Medium Severity"
建议修复
LOW
low-priority.svg
、"style"、"nit"
可选修复

3. Process Each Comment

3. 处理每条评论

For each comment:
a. Show context
Comment #123456789 (HIGH) - app/auth.py:45
"The validation logic should use constant-time comparison..."
b. Read affected code and propose fix
c. Confirm with user before applying
d. Apply fix if approved
e. Verify fix addresses ALL issues in the comment
针对每条评论:
a. 展示上下文
评论 #123456789(HIGH)- app/auth.py:45
"验证逻辑应使用恒定时间比较..."
b. 阅读受影响代码并提出修复方案
c. 应用修复前需获得用户确认
d. 若获批准则应用修复
e. 验证修复是否解决了评论中的所有问题

4. Commit Changes

4. 提交变更

Use git-commit skill format for review fixes:
bash
git add <files>
git commit -m "fix(scope): address review comment #ID

Brief explanation of what was wrong and how it's fixed.
Addresses review comment #123456789."
Review fix commit rules (see git-commit skill for full details):
  • First line:
    type(scope): subject
    (max 50 chars)
  • Types:
    fix
    ,
    refactor
    ,
    security
    ,
    test
    ,
    style
    ,
    perf
  • Reference the comment ID in body
  • Explain what was wrong and how it's fixed
使用git-commit技能格式处理评审修复提交:
bash
git add <files>
git commit -m "fix(scope): address review comment #ID

简要说明问题所在及修复方式。
对应评审评论 #123456789。"
评审修复提交规则(详见git-commit技能):
  • 第一行:
    type(scope): subject
    (最多50字符)
  • 类型:
    fix
    refactor
    security
    test
    style
    perf
  • 正文中引用评论ID
  • 说明问题所在及修复方式

5. Reply to Thread

5. 回复评论线程

bash
COMMIT=$(git rev-parse --short HEAD)
gh api repos/$REPO/pulls/$PR/comments \
  --input - <<< '{"body": "Fixed in '"$COMMIT"'. Replaced set lookup with hmac.compare_digest.", "in_reply_to": 123456789}'
Standard Reply Templates:
SituationTemplate
Fixed
Fixed in [hash]. [brief description of fix]
Won't fix
Won't fix: [reason - e.g., out of scope, acceptable risk]
By design
By design: [explanation of why current behavior is intentional]
Deferred
Deferred to [issue/task number]. Will address in future iteration.
Acknowledged
Acknowledged. [brief note, e.g., "acceptable for MVP"]
No emojis. Keep it minimal and professional.
bash
COMMIT=$(git rev-parse --short HEAD)
gh api repos/$REPO/pulls/$PR/comments \
  --input - <<< '{"body": "已在'"$COMMIT"'中修复。将集合查找替换为hmac.compare_digest。", "in_reply_to": 123456789}'
标准回复模板
场景模板
已修复
已在[哈希值]中修复。[修复简要说明]
不修复
不修复:[原因 - 如超出范围、风险可接受]
设计如此
设计如此:[解释当前行为为何是有意为之]
延后处理
延后至[问题/任务编号]处理。将在后续迭代中解决。
已确认
已确认。[简要说明,如“对MVP而言可接受”]
请勿使用表情符号。保持简洁专业。

6. Run Tests

6. 运行测试

bash
make test  # or project-specific command
All tests must pass before pushing.
bash
make test  # 或项目特定命令
推送前必须确保所有测试通过。

7. Push

7. 推送代码

bash
git push
bash
git push

8. Submit Review (Optional)

8. 提交评审(可选)

After addressing all comments, formally submit a review:
bash
undefined
处理完所有评论后,可正式提交评审:
bash
undefined

Approve the PR (use after all comments resolved)

批准PR(所有评论解决后使用)

gh pr review $PR --approve --body "All review comments addressed. Ready to merge."
gh pr review $PR --approve --body "所有评审评论已处理完毕。可合并。"

Or request changes if issues remain

若仍有问题,可请求修改

gh pr review $PR --request-changes --body "Addressed X comments, Y issues remain."
gh pr review $PR --request-changes --body "已处理X条评论,仍有Y个问题待解决。"

Or just comment without approval decision

或仅提交评论不做批准决定

gh pr review $PR --comment --body "Partial progress: fixed A and B, working on C."

**When to use each**:
- `--approve`: All comments addressed, PR is ready
- `--request-changes`: Critical issues remain unresolved
- `--comment`: Progress update, no approval decision yet
gh pr review $PR --comment --body "进展更新:已修复A和B,正在处理C。"

**各场景使用时机**:
- `--approve`:所有评论已处理,PR就绪
- `--request-changes`:仍有严重问题未解决
- `--comment`:进度更新,暂不做批准决定

Batch Commit Strategy

批量提交策略

Organize commits by impact when addressing multiple comments:
Change TypeStrategy
Functional (CRITICAL/HIGH)Separate commit per fix
Cosmetic (MEDIUM/LOW)Single batch commit
Workflow:
  1. Fix CRITICAL/HIGH → separate commits each
  2. Collect all cosmetic fixes
  3. Apply cosmetics → single
    style:
    commit
  4. Run tests once
  5. Push all together
处理多条评论时,按影响类型组织提交:
变更类型策略
功能性变更(CRITICAL/HIGH)每个修复单独提交
cosmetic变更(MEDIUM/LOW)单个批量提交
工作流程
  1. 修复CRITICAL/HIGH问题 → 每个修复单独提交
  2. 收集所有 cosmetic 修复
  3. 应用cosmetic修复 → 单个
    style:
    提交
  4. 运行一次测试
  5. 批量推送所有提交

Pre-Merge Checklist

合并前检查清单

Before closing/merging PR, verify (or use github-pr-merge skill for automated validation):
  • All CRITICAL and HIGH comments addressed
  • All MEDIUM comments addressed or justified skip
  • Replies posted to all resolved threads
  • Tests passing (
    make test
    or equivalent)
  • Linting passing (
    make lint
    or equivalent)
  • CI checks green (
    gh pr checks
    )
  • No unresolved conversations
TIP: After resolving all comments, use the
github-pr-merge
skill to execute the merge with full pre-merge validation.
关闭/合并PR前,请验证(或使用github-pr-merge技能进行自动化验证):
  • 所有CRITICAL和HIGH级评论已处理
  • 所有MEDIUM级评论已处理或已说明跳过理由
  • 所有已解决的线程均已回复
  • 测试通过(
    make test
    或等效命令)
  • 代码检查通过(
    make lint
    或等效命令)
  • CI检查通过(
    gh pr checks
  • 无未解决的对话
提示:解决所有评论后,可使用
github-pr-merge
技能执行合并前完整验证并完成合并。

Reply to Threads API

评论线程回复API

Important: Use
--input -
with JSON for
in_reply_to
:
bash
undefined
重要提示:使用
--input -
配合JSON格式指定
in_reply_to
bash
undefined

Correct syntax

正确语法

gh api repos/$REPO/pulls/$PR/comments
--input - <<< '{"body": "Fixed in abc123. Brief explanation.", "in_reply_to": 123456789}'

**Do NOT use**: `-f in_reply_to=...` (doesn't work)
gh api repos/$REPO/pulls/$PR/comments
--input - <<< '{"body": "已在abc123中修复。简要说明。", "in_reply_to": 123456789}'

**请勿使用**:`-f in_reply_to=...`(该方式无效)

Avoiding Review Loops

避免评审循环

When bots review every push:
  1. Batch fixes: Accumulate all fixes, push once
  2. Draft PR: Convert to draft during fixes
  3. Commit keywords: Some bots respect
    [skip ci]
    or
    [skip review]
当机器人会对每次推送进行评审时:
  1. 批量修复:累积所有修复后一次性推送
  2. 草稿PR:修复期间将PR转为草稿状态
  3. 提交关键字:部分机器人支持
    [skip ci]
    [skip review]
    关键字

Severity Detection

严重程度检测

Gemini badges:
  • critical.svg
    -> CRITICAL
  • high-priority.svg
    -> HIGH
  • medium-priority.svg
    -> MEDIUM
  • low-priority.svg
    -> LOW
Cursor comments:
  • <!-- **High Severity** -->
    -> HIGH
  • <!-- **Medium Severity** -->
    -> MEDIUM
Fallback keywords: "security", "vulnerability", "injection" -> CRITICAL
Gemini徽章
  • critical.svg
    → CRITICAL
  • high-priority.svg
    → HIGH
  • medium-priority.svg
    → MEDIUM
  • low-priority.svg
    → LOW
Cursor评论
  • <!-- **High Severity** -->
    → HIGH
  • <!-- **Medium Severity** -->
    → MEDIUM
备选关键字:"security"、"vulnerability"、"injection" → CRITICAL

Important Rules

重要规则

  • ALWAYS read project conventions (CLAUDE.md, etc.) before starting
  • ALWAYS confirm before modifying files
  • ALWAYS verify ALL issues in multi-issue comments are fixed
  • ALWAYS run tests before pushing
  • ALWAYS reply to resolved threads using standard templates
  • ALWAYS submit formal review (
    gh pr review
    ) after addressing all comments
  • NEVER use emojis in commit messages or thread replies
  • NEVER skip HIGH/CRITICAL comments without explicit user approval
  • Functional fixes -> separate commits (one per fix)
  • Cosmetic fixes -> batch into single
    style:
    commit
  • 务必在开始前阅读项目约定(CLAUDE.md等)
  • 务必在修改文件前获得确认
  • 务必验证多问题评论中的所有问题均已修复
  • 务必在推送前运行测试
  • 务必使用标准模板回复已解决的线程
  • 务必处理完所有评论后提交正式评审(
    gh pr review
  • 切勿在提交信息或线程回复中使用表情符号
  • 切勿在未获得用户明确批准的情况下跳过HIGH/CRITICAL级评论
  • 功能性修复 → 单独提交(每个修复一个提交)
  • ** cosmetic修复** → 批量合并为单个
    style:
    提交

Related Skills

相关技能

  • git-commit - Commit message format and conventions (use for review fix commits)
  • github-pr-merge - Execute merge after review is complete (use after fixing all comments)
  • git-commit - 提交信息格式与约定(用于评审修复提交)
  • github-pr-merge - 评审完成后执行合并(所有评论修复完成后使用)