gh-pr-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Review Comment Workflow (gh-pr-review CLI)
PR评审意见处理工作流(gh-pr-review CLI)
GitHub repo: https://github.com/scottatron/gh-pr-review
A systematic approach to addressing PR review comments efficiently: fetch all threads, present options for each issue, collect all decisions upfront, implement fixes in a single commit, and document resolutions.
这是一种高效处理PR评审意见的系统化方法:获取所有评论线程、为每个问题提供处理选项、提前收集所有决策、在单次提交中实现修复,并记录解决方案。
Requirements
前置要求
- GitHub CLI () installed and authenticated
gh - CLI on
gh-pr-reviewPATH - Repository write permissions (for resolving threads)
- 已安装并完成身份验证的GitHub CLI ()
gh - CLI已添加至
gh-pr-review环境变量PATH - 具备仓库写入权限(用于标记线程为已解决)
Helper Commands (gh-pr-review CLI)
辅助命令(gh-pr-review CLI)
Fetch review threads
获取评审线程
Fetch review threads for a PR with resolution status.
bash
undefined获取指定PR的评审线程及其解决状态。
bash
undefinedUnresolved threads only
仅获取未解决线程
gh-pr-review list --pr [PR_NUMBER] --status unresolved
gh-pr-review list --pr [PR_NUMBER] --status unresolved
All threads
获取所有线程
gh-pr-review list --pr [PR_NUMBER] --status all
gh-pr-review list --pr [PR_NUMBER] --status all
Resolved threads without replies
获取已解决但未回复的线程
gh-pr-review list --pr [PR_NUMBER] --status resolved-no-reply
Use `--repo owner/name` if not running within the repo. Use `--json` for structured output.gh-pr-review list --pr [PR_NUMBER] --status resolved-no-reply
若未在仓库目录下运行,可使用`--repo owner/name`指定仓库。使用`--json`参数可获取结构化输出。Reply to a thread
回复评论线程
bash
gh-pr-review reply --thread-id "THREAD_ID" --body "Reply message"bash
gh-pr-review reply --thread-id "THREAD_ID" --body "回复内容"Resolve or unresolve a thread
标记线程为已解决或未解决
bash
gh-pr-review resolve --thread-id "THREAD_ID"
gh-pr-review unresolve --thread-id "THREAD_ID"bash
gh-pr-review resolve --thread-id "THREAD_ID"
gh-pr-review unresolve --thread-id "THREAD_ID"Core Workflow
核心工作流
1. Discovery
1. 发现环节
Fetch all unresolved review threads:
bash
gh-pr-review list --pr [PR_NUMBER] --status unresolved --jsonIf you need all threads, use .
--status allKey data points:
- - GraphQL thread ID (needed for replies/resolve/unresolve)
thread.id - - Resolution status
thread.isResolved - - File path
thread.path - - Line number
thread.line - /
comments[].body- comment contextcomments[].author.login
Organize threads by file path, severity (Critical/Medium/Low), and theme (security, bugs, quality, docs).
获取所有未解决的评审线程:
bash
gh-pr-review list --pr [PR_NUMBER] --status unresolved --json若需要获取所有线程,使用参数。
--status all关键数据点:
- - GraphQL线程ID(回复/标记解决/未解决时需要)
thread.id - - 解决状态
thread.isResolved - - 文件路径
thread.path - - 行号
thread.line - /
comments[].body- 评论上下文comments[].author.login
可按文件路径、严重程度(高/中/低)和主题(安全、Bug、代码质量、文档)对线程进行分类整理。
2. Analysis
2. 分析环节
For each comment group:
- Understand the issue and its impact
- Identify 2-4 resolution approaches with trade-offs
- Recommend best approach based on codebase patterns
- Read relevant code context (affected files, related patterns, docs)
针对每组评论:
- 理解问题及其影响
- 确定2-4种解决方案并分析利弊
- 根据代码库现有模式推荐最优方案
- 查阅相关代码上下文(受影响文件、相关模式、文档)
3. Decision Collection
3. 决策收集
Present ALL issues before implementing ANY fixes.
Format:
Issue #N: [Brief description]
File: path/to/file.ts:42
Severity: Critical/Medium/Low
Options:
1. [Quick fix] - [Trade-offs]
2. [Thorough fix] - [Trade-offs]
3. [Alternative] - [Trade-offs]
Recommendation: Option X because [reasoning]Use AskUserQuestion to collect decisions:
- Present 1-4 issues per question
- Batch by theme or priority for large sets
- Include skip/defer options when appropriate
Key Principle: Never start implementing until user has decided on ALL comments.
在开始任何修复之前,先呈现所有问题。
格式:
问题 #N: [简要描述]
文件: path/to/file.ts:42
严重程度: 高/中/低
可选方案:
1. [快速修复] - [利弊分析]
2. [彻底修复] - [利弊分析]
3. [替代方案] - [利弊分析]
推荐方案:选项X,原因是[理由说明]使用AskUserQuestion收集决策:
- 每次提问呈现1-4个问题
- 针对大量问题,按主题或优先级分批处理
- 适当情况下提供跳过/延后处理选项
核心原则: 在用户对所有评论做出决策之前,绝不要开始实施修复。
4. Implementation
4. 实施环节
After collecting all decisions:
- Plan file edit order (dependencies first)
- Make all changes based on user's choices
- Check for related code needing similar fixes
- Update affected documentation
- Reply to and resolve each thread as it's addressed:
bash
gh-pr-review reply --thread-id "THREAD_ID" --body "Fixed in collaboration with Claude Code - [brief description]"
gh-pr-review resolve --thread-id "THREAD_ID"- Run tests
Keep changes focused - only what was discussed, maintain existing style, preserve backward compatibility.
收集所有决策后:
- 规划文件编辑顺序(优先处理依赖项)
- 根据用户的选择进行所有修改
- 检查是否有相关代码需要类似修复
- 更新受影响的文档
- 在处理每个线程后进行回复并标记为已解决:
bash
gh-pr-review reply --thread-id "THREAD_ID" --body "已与Claude Code协作完成修复 - [简要描述]"
gh-pr-review resolve --thread-id "THREAD_ID"- 运行测试
保持修改聚焦:仅处理讨论过的内容,遵循现有代码风格,确保向后兼容性。
5. Commit
5. 提交
Create comprehensive commit message:
fix: address [source] PR review comments
[One-sentence summary of scope]
**Critical Fixes:**
- [Security/bug fixes]
**Code Quality:**
- [Refactoring, best practices]
**Documentation:**
- [Examples, guides, comments]
**Changes:**
- path/to/file: [what changed and why]
All [N] review threads addressed.
Relates to #[PR_NUMBER]Commit and push:
bash
git add [files]
git commit -m "[message above]"
git push编写全面的提交信息:
fix: 处理[来源]的PR评审意见
[范围简要概述]
**高优先级修复:**
- [安全/Bug修复内容]
**代码质量优化:**
- [重构、最佳实践改进]
**文档更新:**
- [示例、指南更新]
**具体变更:**
- path/to/file: [变更内容及原因]
已处理全部[N]条评审线程。
关联PR: #[PR_NUMBER]提交并推送:
bash
git add [files]
git commit -m "[上述提交信息]"
git push6. Verification
6. 验证环节
Verify all review threads are resolved:
bash
gh-pr-review list --pr [PR_NUMBER] --status unresolved --jsonIf any threads remain unresolved, investigate and address them before considering the work complete.
验证所有评审线程均已解决:
bash
gh-pr-review list --pr [PR_NUMBER] --status unresolved --json若仍有未解决的线程,需调查并处理后再确认工作完成。
Multi-Round Strategy
多轮处理策略
For PRs with many comments (>10), split into rounds:
- Round 1: Critical (security, bugs, breaking changes)
- Round 2: Code quality (refactoring, performance, best practices)
- Round 3: Polish (docs, examples, style)
Each round follows full workflow: Fetch → Analyze → Decide → Implement → Commit
针对评论较多的PR(>10条),可分轮次处理:
- 第一轮: 高优先级(安全、Bug、破坏性变更)
- 第二轮: 代码质量(重构、性能、最佳实践)
- 第三轮: 细节完善(文档、示例、代码风格)
每一轮均遵循完整工作流:获取→分析→决策→实施→提交
Quality Checkpoints
质量检查点
Before committing:
- All user decisions implemented correctly
- No unintended side effects
- Related code updated for consistency
- Documentation reflects changes
- Tests pass
- Commit message is comprehensive
提交前需检查:
- 所有用户决策均已正确实施
- 无意外副作用
- 相关代码已更新以保持一致性
- 文档已反映变更内容
- 测试通过
- 提交信息全面准确
Common Patterns
常见场景处理模式
Security: Always prioritize (Round 1), create issue if complex, document considerations
Naming/Style: Check existing patterns, apply consistently, update style guide if new pattern
Dependencies: Consider version compatibility, check breaking changes, update lock files
Documentation: Fix incorrect examples, update guides/READMEs, add comments for complex changes
安全问题: 始终优先处理(第一轮),若问题复杂需创建单独Issue,记录相关考虑因素
命名/风格: 参考现有模式,保持一致性,若引入新模式需更新风格指南
依赖项: 考虑版本兼容性,检查破坏性变更,更新锁文件
文档: 修复错误示例,更新指南/README,为复杂变更添加注释