pr-review-fixer
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChinesePR Review Fixer
PR评审修复工具
Fetch unresolved PR comments, validate each issue, create a fix plan, implement fixes, and verify CI checks pass (tests, lint, build).
获取未解决的PR评论,验证每个问题,制定修复计划,实施修复并验证CI检查通过(测试、Lint、构建)。
Workflow
工作流
1. Fetch PR Comments
1. 获取PR评论
bash
undefinedbash
undefinedGet PR info
Get PR info
PR_NUM=$(gh pr view --json number --jq '.number')
PR_NUM=$(gh pr view --json number --jq '.number')
Get all PR comments via GraphQL (code-level AND PR-level)
Get all PR comments via GraphQL (code-level AND PR-level)
gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
# Code-level review comments (file/line specific)
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 50) {
nodes { id body author { login } path line }
}
}
}
# PR-level review comments (top-level review body)
reviews(first: 50) {
nodes {
id
body
state
author { login }
}
}
# PR-level issue comments (general discussion)
comments(first: 100) {
nodes {
id
body
author { login }
}
}
}
}
}
' -f owner=OWNER -f repo=REPO -F pr=$PR_NUM
undefinedgh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
# Code-level review comments (file/line specific)
reviewThreads(first: 100) {
nodes {
id
isResolved
comments(first: 50) {
nodes { id body author { login } path line }
}
}
}
# PR-level review comments (top-level review body)
reviews(first: 50) {
nodes {
id
body
state
author { login }
}
}
# PR-level issue comments (general discussion)
comments(first: 100) {
nodes {
id
body
author { login }
}
}
}
}
}
' -f owner=OWNER -f repo=REPO -F pr=$PR_NUM
undefined2. Filter Comments
2. 过滤评论
Code-level comments (reviewThreads):
- Exclude resolved threads: Filter out threads where
isResolved: true - claude[bot] handling: For comments, keep only the last comment per thread
claude[bot] - Group by file/location: Organize by path and line number
PR-level review comments (reviews):
- Exclude empty bodies: Skip reviews with empty or whitespace-only body
- Exclude approval-only: Skip reviews with state and no actionable feedback
APPROVED - claude[bot] handling: For reviews, keep only the most recent one
claude[bot]
PR-level issue comments (comments):
- Exclude bot noise: Skip automated comments (CI bots, etc.) unless actionable
- claude[bot] handling: Keep only the last comment
claude[bot] - Identify actionable items: Look for requested changes, questions, or suggestions
代码级评论(reviewThreads):
- 排除已解决的线程:过滤掉的线程
isResolved: true - claude[bot]评论处理:对于的评论,每个线程仅保留最后一条评论
claude[bot] - 按文件/位置分组:按路径和行号整理评论
PR级评审评论(reviews):
- 排除空内容:跳过内容为空或仅含空白字符的评审
- 排除仅批准的评审:跳过状态为且无可执行反馈的评审
APPROVED - claude[bot]评论处理:对于的评审,仅保留最新的一条
claude[bot]
PR级问题评论(comments):
- 排除机器人噪声评论:跳过自动化评论(如CI机器人评论),除非包含可执行内容
- claude[bot]评论处理:仅保留最后一条评论
claude[bot] - 识别可执行项:查找要求修改、问题或建议内容
3. Determine Working Location
3. 确定工作位置
Review reports are posted as PR comments (not committed). Task files are local working files only.
Working directory: Use a temp directory or for local task files during the session. These files are not committed.
.claude/reviews/PR-[number]/Iteration tracking: Check existing PR comments by with "PR Review Overview" in the body. Count those to determine the current iteration number N.
claude[bot]评审报告将作为PR评论发布(不提交到代码库)。任务文件仅保存在本地工作目录中。
工作目录:使用临时目录或作为会话期间的本地任务文件存储目录。这些文件不会被提交。
.claude/reviews/PR-[number]/迭代跟踪:检查PR中由发布的、正文包含"PR Review Overview"的评论,统计这些评论的数量以确定当前迭代次数N。
claude[bot]4. Validate Issues
4. 验证问题
Code-level comments:
- Read the referenced code at path:line
- Evaluate: Is issue still present? Is suggestion correct? Does it align with project conventions?
- Mark as valid or invalid with brief rationale
PR-level comments:
- Parse the comment for actionable items (suggestions, questions, requested changes)
- Check if the feedback applies to current PR state (changes may have been made since)
- Evaluate: Is the request reasonable? Does it align with project goals?
- Mark as valid or invalid with brief rationale
- Skip pure acknowledgments, thanks, or informational comments without action items
代码级评论:
- 读取路径:行号对应的代码
- 评估:问题是否仍然存在?建议是否正确?是否符合项目规范?
- 标记为有效或无效,并附上简短理由
PR级评论:
- 解析评论中的可执行项(建议、问题、修改要求)
- 检查反馈是否适用于当前PR状态(自评论发布以来可能已进行过修改)
- 评估:请求是否合理?是否符合项目目标?
- 标记为有效或无效,并附上简短理由
- 跳过纯确认、感谢或无执行项的信息性评论
5. Create Review Overview
5. 创建评审概述
Prepare the review overview content (this will be posted as a PR comment, not committed):
markdown
undefined准备评审概述内容(将作为PR评论发布,不提交到代码库):
markdown
undefinedPR Review Overview - Iteration [N]
PR Review Overview - Iteration [N]
PR: #[number] | Branch: [name] | Date: [YYYY-MM-DD]
PR: #[number] | Branch: [name] | Date: [YYYY-MM-DD]
Valid Issues
Valid Issues
Code-Level Issues
Code-Level Issues
Issue 1: [title]
Issue 1: [title]
- File:
path:line - Reviewer: @user
- Comment: [quoted]
- Validation: [rationale]
- File:
path:line - Reviewer: @user
- Comment: [quoted]
- Validation: [rationale]
PR-Level Issues
PR-Level Issues
Issue 2: [title]
Issue 2: [title]
- Type: review comment | discussion comment
- Reviewer: @user
- Comment: [quoted]
- Validation: [rationale]
- Type: review comment | discussion comment
- Reviewer: @user
- Comment: [quoted]
- Validation: [rationale]
Invalid/Skipped Issues
Invalid/Skipped Issues
Issue A: [title]
Issue A: [title]
- Location: or PR-level
path:line - Reviewer: @user
- Comment: [quoted]
- Reason: [why invalid]
undefined- Location: or PR-level
path:line - Reviewer: @user
- Comment: [quoted]
- Reason: [why invalid]
undefined6. Create Task List
6. 创建任务列表
Use rune to create :
review-fixes-[N].mdbash
rune create ${OUTPUT_DIR}/review-fixes-${N}.md \
--title "PR Review Fixes - Iteration ${N}" \
--reference ${OUTPUT_DIR}/review-overview-${N}.md使用rune创建:
review-fixes-[N].mdbash
rune create ${OUTPUT_DIR}/review-fixes-${N}.md \
--title "PR Review Fixes - Iteration ${N}" \
--reference ${OUTPUT_DIR}/review-overview-${N}.mdAdd tasks via batch for efficiency
Add tasks via batch for efficiency
rune batch ${OUTPUT_DIR}/review-fixes-${N}.md --input '{
"file": "review-fixes-'${N}'.md",
"operations": [
{"type": "add", "title": "Fix: [issue 1]"},
{"type": "add", "title": "Fix: [issue 2]"}
]
}'
undefinedrune batch ${OUTPUT_DIR}/review-fixes-${N}.md --input '{
"file": "review-fixes-'${N}'.md",
"operations": [
{"type": "add", "title": "Fix: [issue 1]"},
{"type": "add", "title": "Fix: [issue 2]"}
]
}'
undefined7. Fix Issues
7. 修复问题
Loop through tasks:
- - get next task
rune next [file] - - mark in-progress
rune progress [file] [id] - Implement the fix
- - mark complete
rune complete [file] [id] - Repeat until done
循环处理任务:
- - 获取下一个任务
rune next [file] - - 标记为进行中
rune progress [file] [id] - 实施修复
- - 标记为完成
rune complete [file] [id] - 重复直到所有任务完成
8. Check CI Status
8. 检查CI状态
After fixing review comments, verify CI checks:
bash
undefined修复评审评论后,验证CI检查状态:
bash
undefinedGet check status for the PR
Get check status for the PR
gh pr checks --json name,state,conclusion
gh pr checks --json name,state,conclusion
For failed checks, get details
For failed checks, get details
gh run view [RUN_ID] --log-failed
**Check types to handle:**
1. **Test failures**: Parse test output, identify failing tests, fix code or tests
2. **Lint errors**: Run linter locally, fix reported issues
3. **Type errors**: Run type checker, fix type mismatches
4. **Build failures**: Check build logs, fix compilation issuesgh run view [RUN_ID] --log-failed
**需要处理的检查类型:**
1. **测试失败**:解析测试输出,识别失败的测试,修复代码或测试用例
2. **Lint错误**:在本地运行Lint工具,修复报告的问题
3. **类型错误**:运行类型检查工具,修复类型不匹配问题
4. **构建失败**:检查构建日志,修复编译问题9. Fix CI Issues
9. 修复CI问题
For each failed check:
- Identify the failure type from check name and logs
- Run locally to reproduce:
- Tests: or project's test command
make test - Lint: or project's lint command
make lint - Types: or equivalent
make typecheck
- Tests:
- Parse error output to identify specific failures
- Fix the issues:
- For test failures: Check if test expectations need updating or if code has a bug
- For lint errors: Apply automatic fixes where possible, manual fixes otherwise
- For type errors: Add/fix type annotations or fix type mismatches
- Re-run locally to verify fix
- Add to task list if not already tracked
Test failure handling:
bash
undefined针对每个失败的检查:
- 从检查名称和日志中识别失败类型
- 在本地复现问题:
- 测试:或项目的测试命令
make test - Lint:或项目的Lint命令
make lint - 类型检查:或等效命令
make typecheck
- 测试:
- 解析错误输出以识别具体失败点
- 修复问题:
- 测试失败:检查是否需要更新测试预期或修复代码bug
- Lint错误:尽可能应用自动修复,否则手动修复
- 类型错误:添加/修复类型注解或修复类型不匹配问题
- 在本地重新运行以验证修复
- 如果未跟踪则添加到任务列表
测试失败处理:
bash
undefinedRun tests and capture output
Run tests and capture output
make test 2>&1 | tee test-output.txt
make test 2>&1 | tee test-output.txt
If using pytest
If using pytest
pytest --tb=short 2>&1 | tee test-output.txt
pytest --tb=short 2>&1 | tee test-output.txt
If using go test
If using go test
go test ./... 2>&1 | tee test-output.txt
Parse output for:
- Failed test names and locations
- Assertion errors with expected vs actual values
- Stack traces pointing to failure sourcego test ./... 2>&1 | tee test-output.txt
解析输出内容以获取:
- 失败的测试名称和位置
- 断言错误的预期值与实际值
- 指向失败源的堆栈跟踪10. Resolve Fixed Threads
10. 标记已修复的线程为已解决
After fixing code-level issues, resolve the corresponding review threads on GitHub:
bash
undefined修复代码级问题后,在GitHub上标记对应的评审线程为已解决:
bash
undefinedFor each fixed code-level thread, resolve it using its thread ID
For each fixed code-level thread, resolve it using its thread ID
gh api graphql -f query='
mutation($threadId: ID!) {
resolveReviewThread(input: {threadId: $threadId}) {
thread { isResolved }
}
}
' -f threadId=THREAD_NODE_ID
Only resolve threads whose issues were validated and fixed. Do not resolve threads that were skipped or marked invalid — those need human attention.gh api graphql -f query='
mutation($threadId: ID!) {
resolveReviewThread(input: {threadId: $threadId}) {
thread { isResolved }
}
}
' -f threadId=THREAD_NODE_ID
仅标记已验证并修复的问题对应的线程为已解决。不要标记被跳过或标记为无效的线程——这些需要人工处理。11. Post Review Report as PR Comment
11. 将评审报告作为PR评论发布
Post the review overview as a comment on the PR. This replaces committing report files.
bash
undefined将评审概述作为评论发布到PR上。这替代了提交报告文件的方式。
bash
undefinedPost the review overview content as a PR comment
Post the review overview content as a PR comment
gh pr comment $PR_NUM --body "$(cat <<'EOF'
gh pr comment $PR_NUM --body "$(cat <<'EOF'
PR Review Overview - Iteration [N]
PR Review Overview - Iteration [N]
PR: #[number] | Branch: [name] | Date: [YYYY-MM-DD]
PR: #[number] | Branch: [name] | Date: [YYYY-MM-DD]
Valid Issues (fixed)
Valid Issues (fixed)
[List of validated and fixed issues with file:line, reviewer, and brief description]
[List of validated and fixed issues with file:line, reviewer, and brief description]
Invalid/Skipped Issues
Invalid/Skipped Issues
[List of skipped issues with rationale]
[List of skipped issues with rationale]
CI Status
CI Status
[Summary of CI check results and any fixes applied]
EOF
)"
**Do not commit** `review-overview-*.md` or `review-fixes-*.md` files. They are working files only.[Summary of CI check results and any fixes applied]
EOF
)"
**请勿提交** `review-overview-*.md` 或 `review-fixes-*.md` 文件。这些仅为工作文件。12. Commit, Push, and Verify
12. 提交、推送并验证
After all fixes:
- Run full test suite locally
- Run linter
- Commit only code changes (exclude any local review/task files)
- Push to remote
- Monitor CI status to confirm checks pass
完成所有修复后:
- 在本地运行完整测试套件
- 运行Lint工具
- 仅提交代码变更(排除任何本地评审/任务文件)
- 推送到远程仓库
- 监控CI状态以确认检查通过
Key Behaviors
核心行为
- Auto-fix: Fix all validated issues without pausing for approval
- Context preservation: Keep diff_hunk context when analyzing
- Convention adherence: Follow project's existing patterns
- Deduplication: Consolidate multiple comments on same issue into one task
- CI verification: Always check CI status after fixing review comments
- Local reproduction: Run tests/linters locally before pushing fixes
- Reports as comments: Post review reports as PR comments, never commit them
- Clean commits: Only commit actual code changes, not working/report files
- 自动修复:自动修复所有已验证的问题,无需等待批准
- 上下文保留:分析时保留diff_hunk上下文
- 遵循规范:遵循项目现有的模式
- 去重:将同一问题的多条评论合并为一个任务
- CI验证:修复评审评论后始终检查CI状态
- 本地复现:推送修复前先在本地运行测试/Lint工具
- 报告作为评论发布:将评审报告作为PR评论发布,绝不提交到代码库
- 干净提交:仅提交实际代码变更,不提交工作文件/报告文件