github-pr-review-workflow
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseGitHub PR Review Workflow
GitHub PR评审工作流
Complete workflow for reviewing, addressing feedback, and resolving threads in GitHub pull requests using the extension from agynio/gh-pr-review.
gh-pr-reviewFor gh-pr-review documentation, see: https://github.com/agynio/gh-pr-review
本文介绍使用agynio/gh-pr-review提供的扩展,完成GitHub拉取请求(PR)的评审、反馈处理及线程解决的完整工作流。
gh-pr-reviewgh-pr-review文档地址: https://github.com/agynio/gh-pr-review
Installation
安装
Install gh-pr-review extension (if not already installed):
bash
gh extension install agynio/gh-pr-reviewVerify installation:
bash
gh pr-review --help安装gh-pr-review扩展(若未安装):
bash
gh extension install agynio/gh-pr-review验证安装:
bash
gh pr-review --helpWorkflow Overview
工作流概述
PR Review Request
├─ Get PR number/repo context
├─ List all review threads
├─ Analyze feedback and comments
├─ Validate whether each comment applies and explain decisions
├─ Implement fixes in code
├─ Run tests (unit + lint + typecheck)
├─ Reply to all open review threads with explanations
├─ Wait up to 5 minutes for follow-up
├─ Resolve review threads (or address follow-ups)
└─ Commit and push changesPR评审请求
├─ 获取PR编号/仓库上下文
├─ 列出所有评审线程
├─ 分析反馈与评论
├─ 验证每条评论是否适用并说明决策
├─ 在代码中实现修复
├─ 运行测试(单元测试 + 代码检查 + 类型校验)
├─ 回复所有未关闭的评审线程并说明处理情况
├─ 等待最多5分钟以获取后续反馈
├─ 解决评审线程(或处理后续反馈)
└─ 提交并推送更改Step-by-Step Process
分步流程
1. Get PR Context
1. 获取PR上下文
Get current PR details:
bash
undefined获取当前PR详情:
bash
undefinedGet PR number
获取PR编号
gh pr view --json number
gh pr view --json number
Get PR title and status
获取PR标题与状态
gh pr view --json title,author,state,reviews
gh pr view --json title,author,state,reviews
Get repository info (for gh pr-review)
获取仓库信息(供gh pr-review使用)
git remote get-url origin
**Output:** PR number (e.g., `<PR_NUMBER>`) and repo (e.g., `<OWNER/REPO>`)
---git remote get-url origin
**输出:** PR编号(例如:`<PR_NUMBER>`)和仓库信息(例如:`<OWNER/REPO>`)
---2. List Review Threads
2. 列出评审线程
List all review threads (active and outdated):
bash
undefined列出所有评审线程(活跃与已过时):
bash
undefinedFrom PR root directory
在PR根目录执行
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
Example:
示例:
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
**Response format:**
```json
[
{
"threadId": "<THREAD_ID>",
"isResolved": false,
"updatedAt": "2026-01-17T22:48:36Z",
"path": "path/to/file.ts",
"line": 42,
"isOutdated": false
}
]Key fields:
- : GraphQL node ID for resolving/replying
threadId - : Current status
isResolved - : Whether code has changed since comment
isOutdated - +
path: File locationline
If all review threads are resolved or none are present, search for normal comments and analyse them:
bash
gh pr view <PR_NUMBER> --comments --json author,comments,reviewsgh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
**响应格式:**
```json
[
{
"threadId": "<THREAD_ID>",
"isResolved": false,
"updatedAt": "2026-01-17T22:48:36Z",
"path": "path/to/file.ts",
"line": 42,
"isOutdated": false
}
]关键字段:
- : 用于回复/解决线程的GraphQL节点ID
threadId - : 当前状态
isResolved - : 评论后代码是否已更改
isOutdated - +
path: 文件位置line
若所有评审线程已解决或无评审线程,则搜索普通评论并分析:
bash
gh pr view <PR_NUMBER> --comments --json author,comments,reviews3. Read and Analyze Feedback
3. 阅读并分析反馈
Get review comments via GitHub API:
bash
undefined通过GitHub API获取评审评论:
bash
undefinedGet all review comments for PR
获取PR的所有评审评论
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments
With jq for cleaner output
使用jq优化输出格式
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments
--jq '.[] | {id,body,author,created_at,line,path}'
--jq '.[] | {id,body,author,created_at,line,path}'
**Read the specific files mentioned:**
```bashgh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments
--jq '.[] | {id,body,author,created_at,line,path}'
--jq '.[] | {id,body,author,created_at,line,path}'
**查看评论提及的具体文件:**
```bashRead the file context to understand feedback
查看文件上下文以理解反馈
cat <path>
cat <path>
or use Read tool
或使用编辑工具
**Categorize feedback:**
- **High priority**: Security issues, bugs, breaking changes
- **Medium priority**: Code quality, maintainability, test coverage
- **Low priority**: Style, documentation, nice-to-haves
**Validate applicability before changing code (required):**
- Confirm each comment is accurate and relevant to the current code.
- If a suggestion is incorrect, outdated, or doesn’t make sense in this codebase, **reply with a detailed explanation** of why it was not implemented.
- Do not skip a change simply because it is time-consuming—either implement it or explain clearly why it should not be done.
---
**对反馈进行分类:**
- **高优先级**:安全问题、Bug、破坏性变更
- **中优先级**:代码质量、可维护性、测试覆盖率
- **低优先级**:代码风格、文档、优化建议
**修改代码前需验证反馈适用性:**
- 确认每条评论对当前代码准确且相关。
- 若建议不正确、已过时或不符合代码库逻辑,**需回复详细说明未采纳的原因**。
- 不可仅因耗时跳过修改——要么实现修改,要么清晰说明不修改的理由。
---4. Implement Fixes
4. 实现修复
Edit the files mentioned in review:
bash
undefined编辑评审中提及的文件:
bash
undefinedUse Edit tool or bash
使用编辑工具或bash命令
edit <file_path> <oldString> <newString>
**Follow repository conventions:**
- Check existing patterns in similar files
- Follow AGENTS.md guidelines
- Maintain code style consistency
- Add/update tests for new logic
---edit <file_path> <oldString> <newString>
**遵循仓库约定:**
- 参考相似文件的现有模式
- 遵循AGENTS.md指南
- 保持代码风格一致性
- 为新逻辑添加/更新测试
---5. Verify Changes (CRITICAL)
5. 验证变更(至关重要)
Always run tests before replying:
bash
undefined回复前务必运行测试:
bash
undefinedRun project tests
运行项目测试
bun run test
bun run test
Or specific test suites
或运行特定测试套件
bun run test:unit
bun run test:unit:watch
bun run test:e2e
**Run type checking:**
```bash
bun run typecheckbun run test:unit
bun run test:unit:watch
bun run test:e2e
**运行类型校验:**
```bash
bun run typecheckor
或
tsc --noEmit
**Run linting:**
```bash
bun run linttsc --noEmit
**运行代码检查:**
```bash
bun run lintor
或
eslint
**Verify all pass:**
- ✓ No TypeScript errors
- ✓ No ESLint warnings/errors
- ✓ All unit tests pass
- ✓ E2E tests pass (if relevant)
---eslint
**验证所有检查通过:**
- ✓ 无TypeScript错误
- ✓ 无ESLint警告/错误
- ✓ 所有单元测试通过
- ✓ 端到端(E2E)测试通过(若相关)
---6. Commit and Push Changes
6. 提交并推送更改
Stage and commit changes:
bash
undefined暂存并提交更改:
bash
undefinedCheck status
查看状态
git status
git status
Stage modified files
暂存修改的文件
git add <files>
git add <files>
Commit with clear message
提交并添加清晰的信息
git commit -m "<type>(<scope>): <description>
git commit -m "<type>(<scope>): <description>
Example:
示例:
git commit -m "refactor(emails): centralize from name logic and improve sanitization
- Extract RESEND_FROM_NAME constant to lib/emails/from-address.ts
- Replace duplicated logic in lib/auth.ts and app/actions/contact.ts
- Improve formatFromAddress sanitization (RFC 5322 chars)
- Add test cases for additional sanitization patterns"
**Push to remote:**
```bash
git pushVerify working tree:
bash
git statusgit commit -m "refactor(emails): 集中发件人名称逻辑并改进清理机制
- 将RESEND_FROM_NAME常量提取至lib/emails/from-address.ts
- 替换lib/auth.ts和app/actions/contact.ts中的重复逻辑
- 优化formatFromAddress的清理机制(符合RFC 5322字符规范)
- 为新增清理模式添加测试用例"
**推送到远程仓库:**
```bash
git push验证工作树:
bash
git statusShould show: "nothing to commit, working tree clean"
应显示:"nothing to commit, working tree clean"
---
---7. Reply to Review Threads
7. 回复评审线程
Reply with explanation of fixes:
bash
gh pr-review comments reply \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID> \
--body "<your explanation>"Best practices for replies:
- Acknowledge the feedback
- Explain what was changed
- Reference specific commit(s) if relevant
- Be concise but clear
- Use code fences for code snippets
Example reply:
bash
gh pr-review comments reply \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID> \
--body "$(cat <<'EOF'
@reviewer Thanks for the feedback! I've addressed your suggestions:
1. Applied the requested refactor in the relevant module
2. Removed duplicated logic in the affected call sites
3. Improved sanitization to match the project’s expectations
4. Added/updated tests for the new behavior
Changes committed in abc1234, all tests pass.
EOF
)"Note: Use heredoc for multi-line bodies to avoid shell escaping issues.
Note: Always start replies with (e.g., or ) after you push changes. There can be multiple reviewers, so always look for the exact comment from which reviewer the comment is.
@reviewer@gemini-code-assist ...@greptile …If this was a normal comment and not a review (see step 2), you can use this to answer:
bash
gh pr comment <PR_NUMBER> --body "$(cat <<'EOF'
@reviewer … <same as above>
EOF
)"You can also just react to the comment if appropriate.
Reply to all open threads first:
- Respond to every open comment with what you did or why it was not done.
- Only after all replies are posted, proceed to the wait/resolve phase.
回复并说明修复内容:
bash
gh pr-review comments reply \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID> \
--body "<你的说明内容>"回复最佳实践:
- 感谢反馈
- 说明修改内容
- 若相关,引用特定提交
- 简洁明了
- 代码片段使用代码块包裹
回复示例:
bash
gh pr-review comments reply \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID> \
--body "$(cat <<'EOF'
@reviewer 感谢你的反馈!我已处理所有建议:
1. 在相关模块中应用了要求的重构
2. 移除了受影响调用位置的重复逻辑
3. 优化了清理机制以符合项目要求
4. 为新行为添加/更新了测试
变更已提交至abc1234,所有测试均通过。
EOF
)"注意: 多行内容使用heredoc以避免Shell转义问题。
注意: 推送更改后,回复务必以开头(例如或)。若有多位评审者,需明确对应评论的评审者。
@reviewer@gemini-code-assist ...@greptile …若为普通评论而非评审线程(见步骤2),可使用以下命令回复:
bash
gh pr comment <PR_NUMBER> --body "$(cat <<'EOF'
@reviewer … <与上述内容一致>
EOF
)"合适的情况下也可仅对评论添加表情回应。
先回复所有未关闭的线程:
- 对每条未关闭的评论回复已执行的操作或未修改的原因。
- 所有回复完成后,再进入等待/解决阶段。
8. Wait for Follow-ups and Resolve Threads
8. 等待后续反馈并解决线程
After implementing fixes, pushing the commit, and replying to all open comments, wait up to 5 minutes for follow-ups:
bash
undefined完成修复、推送提交并回复所有未关闭评论后,等待最多5分钟以获取后续反馈:
bash
undefinedWait for a minute for reviewer response
等待1分钟以获取评审者响应
sleep 60
sleep 60
Re-check for new replies or new threads
重新检查新回复或新线程
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
Do this step up to 5 times to wait for up to 5 minutes.
**If there is a follow-up hint, address it (steps 3-7) and then resolve.**
**If there is a confirmation, resolve the thread:**
```bash
gh pr-review threads resolve \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID>Response:
json
{
"thread_node_id": "PRRT_kwDOQkQlKs5p24lu",
"is_resolved": true
}Batch resolve multiple threads:
bash
undefinedgh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
此步骤最多重复5次,累计等待5分钟。
**若有后续反馈,处理后(步骤3-7)再解决线程。**
**若收到确认,解决线程:**
```bash
gh pr-review threads resolve \
--pr <PR_NUMBER> \
--repo <OWNER/REPO> \
--thread-id <THREAD_ID>响应:
json
{
"thread_node_id": "PRRT_kwDOQkQlKs5p24lu",
"is_resolved": true
}批量解决多个线程:
bash
undefinedResolve outdated threads first
先解决已过时的线程
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_OUTDATED_1>
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_OUTDATED_2>
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_OUTDATED_1>
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_OUTDATED_2>
Then resolve active threads after replying
回复后解决活跃线程
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_ACTIVE>
**Strategy:**
1. Resolve outdated threads (isOutdated: true) - no reply needed
2. Reply to active threads explaining fixes (or non-changes)
3. Wait up to 5 minutes for a response
4. Resolve active threads after confirmation or no response
---gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO> --thread-id <THREAD_ID_ACTIVE>
**策略:**
1. 解决已过时的线程(isOutdated: true)——无需回复
2. 回复活跃线程说明修复内容(或未修改原因)
3. 等待最多5分钟以获取响应
4. 收到确认或无响应后解决活跃线程
---9. Verify All Threads Resolved
9. 验证所有线程已解决
Final check:
bash
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>Expected output: All threads show
isResolved: true最终检查:
bash
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>预期输出: 所有线程均显示
isResolved: trueComplete Example Workflow
完整工作流示例
bash
undefinedbash
undefined1. Get PR context
1. 获取PR上下文
gh pr view --json number
git remote get-url origin
gh pr view --json number
git remote get-url origin
2. List review threads
2. 列出评审线程
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
3. Read comments and files
3. 查看评论与文件
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments --jq '.[] | {id,body,path,line}'
cat path/to/file.ts
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments --jq '.[] | {id,body,path,line}'
cat path/to/file.ts
4. Implement fixes
4. 实现修复
edit path/to/file.ts <oldString> <newString>
edit path/to/file.ts <oldString> <newString>
5. Run tests
5. 运行测试
bun run test:unit -- tests/path/to/file.test.ts
bun run typecheck
bun run lint
bun run test:unit -- tests/path/to/file.test.ts
bun run typecheck
bun run lint
6. Commit and push
6. 提交并推送
git add lib/emails/from-address.ts
git commit -m "fix: address PR review feedback"
git push
git add lib/emails/from-address.ts
git commit -m "fix: 处理PR评审反馈"
git push
7. Reply to threads
7. 回复线程
gh pr-review comments reply --pr <PR_NUMBER> --repo <OWNER/REPO>
--thread-id <THREAD_ID> --body "$(cat <<'EOF' @reviewer Thanks for review! I've addressed all feedback:
--thread-id <THREAD_ID> --body "$(cat <<'EOF' @reviewer Thanks for review! I've addressed all feedback:
- Centralized logic
- Improved sanitization
- Added tests
Changes in abc1234.
EOF
)"
gh pr-review comments reply --pr <PR_NUMBER> --repo <OWNER/REPO>
--thread-id <THREAD_ID> --body "$(cat <<'EOF' @reviewer 感谢评审!我已处理所有反馈:
--thread-id <THREAD_ID> --body "$(cat <<'EOF' @reviewer 感谢评审!我已处理所有反馈:
- 集中管理逻辑
- 优化清理机制
- 添加测试用例
变更提交至abc1234。
EOF
)"
8. Wait then resolve threads
8. 等待后解决线程
sleep 300
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO>
--thread-id <THREAD_ID>
--thread-id <THREAD_ID>
sleep 300
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
gh pr-review threads resolve --pr <PR_NUMBER> --repo <OWNER/REPO>
--thread-id <THREAD_ID>
--thread-id <THREAD_ID>
9. Verify
9. 验证
gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
git status
---gh pr-review threads list --pr <PR_NUMBER> --repo <OWNER/REPO>
git status
---gh-pr-review Commands Reference
gh-pr-review命令参考
| Command | Purpose |
|---|---|
| List all review threads |
| Resolve a specific thread |
| Reopen a resolved thread |
| Reply to a review thread |
| Manage pending reviews |
Common flags:
- : Pull request number
--pr <number> - : Repository identifier
-R, --repo <owner/repo> - : GraphQL thread node ID
--thread-id <id>
| 命令 | 用途 |
|---|---|
| 列出所有评审线程 |
| 解决指定线程 |
| 重新打开已解决的线程 |
| 回复评审线程 |
| 管理待处理的评审 |
常用参数:
- : 拉取请求编号
--pr <number> - : 仓库标识符
-R, --repo <owner/repo> - : GraphQL线程节点ID
--thread-id <id>
Troubleshooting
故障排除
| Issue | Solution |
|---|---|
| Install extension: |
| Run from PR directory or add |
| Add |
Shell escaping issues with | Use heredoc: |
| Thread not found | Check threadId is exact GraphQL ID, not PR number |
| 问题 | 解决方案 |
|---|---|
| 安装扩展: |
| 在PR目录执行或添加 |
| 添加 |
Shell转义 | 使用heredoc: |
| 线程未找到 | 确认threadId为准确的GraphQL ID,而非PR编号 |
Best Practices
最佳实践
Before replying:
- ✓ Read all review comments carefully
- ✓ Understand the intent (suggestion vs. blocker)
- ✓ Check if similar issues exist elsewhere
When implementing fixes:
- ✓ Follow existing code patterns
- ✓ Update/add tests for changes
- ✓ Run full test suite
- ✓ Check lint and type errors
When replying:
- ✓ Be polite and appreciative
- ✓ Explain what was changed
- ✓ Reference specific files/lines
- ✓ Keep it concise
Before resolving:
- ✓ Ensure all issues are addressed
- ✓ Verify tests pass
- ✓ Commit changes to branch
回复前:
- ✓ 仔细阅读所有评审评论
- ✓ 理解评论意图(建议 vs 阻塞问题)
- ✓ 检查是否存在类似问题
实现修复时:
- ✓ 遵循现有代码模式
- ✓ 为变更添加/更新测试
- ✓ 运行完整测试套件
- ✓ 检查代码检查与类型错误
回复时:
- ✓ 礼貌且表达感谢
- ✓ 说明修改内容
- ✓ 引用具体文件/行号
- ✓ 保持简洁
解决线程前:
- ✓ 确保所有问题已处理
- ✓ 验证测试通过
- ✓ 将变更提交至分支