github-pr-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub PR Review
GitHub PR 评审
Resolves Pull Request review comments with severity-based prioritization, fix application, and thread replies.
基于严重程度优先级处理PR评审评论,包含修复应用与评论线程回复。
Quick Start
快速开始
bash
undefinedbash
undefined1. 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. 所有修复验证通过后推送
undefinedundefinedPre-Review Checklist
评审前检查清单
Before processing comments, verify:
- Project conventions: Read ,
.claude/CLAUDE.md, or similar.kiro/steering/ - Commit format: Check for project style
git log --oneline -5 - Test command: Identify test runner (,
make test,pytest)npm test - Branch status: to ensure clean working tree
git status
处理评论前,请确认:
- 项目约定:阅读、
.claude/CLAUDE.md或类似文件.kiro/steering/ - 提交格式:通过查看项目提交风格
git log --oneline -5 - 测试命令:确认测试运行器(、
make test、pytest等)npm test - 分支状态:执行确保工作区干净
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.jsonbash
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.json2. Classify by Severity
2. 按严重程度分类
Process in order: CRITICAL > HIGH > MEDIUM > LOW
| Severity | Indicators | Action |
|---|---|---|
| CRITICAL | | Must fix |
| HIGH | | Should fix |
| MEDIUM | | Recommended |
| LOW | | Optional |
按以下顺序处理:CRITICAL > HIGH > MEDIUM > LOW
| 严重程度 | 识别标识 | 操作 |
|---|---|---|
| CRITICAL | | 必须修复 |
| HIGH | | 应该修复 |
| MEDIUM | | 建议修复 |
| LOW | | 可选修复 |
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: (max 50 chars)
type(scope): subject - Types: ,
fix,refactor,security,test,styleperf - 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技能):
- 第一行:(最多50字符)
type(scope): subject - 类型:、
fix、refactor、security、test、styleperf - 正文中引用评论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:
| Situation | Template |
|---|---|
| Fixed | |
| Won't fix | |
| By design | |
| Deferred | |
| Acknowledged | |
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}'标准回复模板:
| 场景 | 模板 |
|---|---|
| 已修复 | |
| 不修复 | |
| 设计如此 | |
| 延后处理 | |
| 已确认 | |
请勿使用表情符号。保持简洁专业。
6. Run Tests
6. 运行测试
bash
make test # or project-specific commandAll tests must pass before pushing.
bash
make test # 或项目特定命令推送前必须确保所有测试通过。
7. Push
7. 推送代码
bash
git pushbash
git push8. Submit Review (Optional)
8. 提交评审(可选)
After addressing all comments, formally submit a review:
bash
undefined处理完所有评论后,可正式提交评审:
bash
undefinedApprove 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 yetgh 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 Type | Strategy |
|---|---|
| Functional (CRITICAL/HIGH) | Separate commit per fix |
| Cosmetic (MEDIUM/LOW) | Single batch commit |
Workflow:
- Fix CRITICAL/HIGH → separate commits each
- Collect all cosmetic fixes
- Apply cosmetics → single commit
style: - Run tests once
- Push all together
处理多条评论时,按影响类型组织提交:
| 变更类型 | 策略 |
|---|---|
| 功能性变更(CRITICAL/HIGH) | 每个修复单独提交 |
| cosmetic变更(MEDIUM/LOW) | 单个批量提交 |
工作流程:
- 修复CRITICAL/HIGH问题 → 每个修复单独提交
- 收集所有 cosmetic 修复
- 应用cosmetic修复 → 单个提交
style: - 运行一次测试
- 批量推送所有提交
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 (or equivalent)
make test - Linting passing (or equivalent)
make lint - CI checks green ()
gh pr checks - No unresolved conversations
TIP: After resolving all comments, use the skill to execute the merge with full pre-merge validation.
github-pr-merge关闭/合并PR前,请验证(或使用github-pr-merge技能进行自动化验证):
- 所有CRITICAL和HIGH级评论已处理
- 所有MEDIUM级评论已处理或已说明跳过理由
- 所有已解决的线程均已回复
- 测试通过(或等效命令)
make test - 代码检查通过(或等效命令)
make lint - CI检查通过()
gh pr checks - 无未解决的对话
提示:解决所有评论后,可使用技能执行合并前完整验证并完成合并。
github-pr-mergeReply to Threads API
评论线程回复API
Important: Use with JSON for :
--input -in_reply_tobash
undefined重要提示:使用配合JSON格式指定:
--input -in_reply_tobash
undefinedCorrect syntax
正确语法
gh api repos/$REPO/pulls/$PR/comments
--input - <<< '{"body": "Fixed in abc123. Brief explanation.", "in_reply_to": 123456789}'
--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}'
--input - <<< '{"body": "已在abc123中修复。简要说明。", "in_reply_to": 123456789}'
**请勿使用**:`-f in_reply_to=...`(该方式无效)Avoiding Review Loops
避免评审循环
When bots review every push:
- Batch fixes: Accumulate all fixes, push once
- Draft PR: Convert to draft during fixes
- Commit keywords: Some bots respect or
[skip ci][skip review]
当机器人会对每次推送进行评审时:
- 批量修复:累积所有修复后一次性推送
- 草稿PR:修复期间将PR转为草稿状态
- 提交关键字:部分机器人支持或
[skip ci]关键字[skip review]
Severity Detection
严重程度检测
Gemini badges:
- -> CRITICAL
critical.svg - -> HIGH
high-priority.svg - -> MEDIUM
medium-priority.svg - -> LOW
low-priority.svg
Cursor comments:
- -> HIGH
<!-- **High Severity** --> - -> MEDIUM
<!-- **Medium Severity** -->
Fallback keywords: "security", "vulnerability", "injection" -> CRITICAL
Gemini徽章:
- → CRITICAL
critical.svg - → HIGH
high-priority.svg - → MEDIUM
medium-priority.svg - → LOW
low-priority.svg
Cursor评论:
- → HIGH
<!-- **High Severity** --> - → MEDIUM
<!-- **Medium Severity** -->
备选关键字:"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 () after addressing all comments
gh pr review - 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 commit
style:
- 务必在开始前阅读项目约定(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 - 评审完成后执行合并(所有评论修复完成后使用)