pr-review-fixer

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

PR 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
undefined
bash
undefined

Get 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
undefined
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
undefined

2. Filter Comments

2. 过滤评论

Code-level comments (reviewThreads):
  1. Exclude resolved threads: Filter out threads where
    isResolved: true
  2. claude[bot] handling: For
    claude[bot]
    comments, keep only the last comment per thread
  3. Group by file/location: Organize by path and line number
PR-level review comments (reviews):
  1. Exclude empty bodies: Skip reviews with empty or whitespace-only body
  2. Exclude approval-only: Skip reviews with state
    APPROVED
    and no actionable feedback
  3. claude[bot] handling: For
    claude[bot]
    reviews, keep only the most recent one
PR-level issue comments (comments):
  1. Exclude bot noise: Skip automated comments (CI bots, etc.) unless actionable
  2. claude[bot] handling: Keep only the last
    claude[bot]
    comment
  3. Identify actionable items: Look for requested changes, questions, or suggestions
代码级评论(reviewThreads):
  1. 排除已解决的线程:过滤掉
    isResolved: true
    的线程
  2. claude[bot]评论处理:对于
    claude[bot]
    的评论,每个线程仅保留最后一条评论
  3. 按文件/位置分组:按路径和行号整理评论
PR级评审评论(reviews):
  1. 排除空内容:跳过内容为空或仅含空白字符的评审
  2. 排除仅批准的评审:跳过状态为
    APPROVED
    且无可执行反馈的评审
  3. claude[bot]评论处理:对于
    claude[bot]
    的评审,仅保留最新的一条
PR级问题评论(comments):
  1. 排除机器人噪声评论:跳过自动化评论(如CI机器人评论),除非包含可执行内容
  2. claude[bot]评论处理:仅保留最后一条
    claude[bot]
    评论
  3. 识别可执行项:查找要求修改、问题或建议内容

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
.claude/reviews/PR-[number]/
for local task files during the session. These files are not committed.
Iteration tracking: Check existing PR comments by
claude[bot]
with "PR Review Overview" in the body. Count those to determine the current iteration number N.
评审报告将作为PR评论发布(不提交到代码库)。任务文件仅保存在本地工作目录中。
工作目录:使用临时目录或
.claude/reviews/PR-[number]/
作为会话期间的本地任务文件存储目录。这些文件不会被提交。
迭代跟踪:检查PR中由
claude[bot]
发布的、正文包含"PR Review Overview"的评论,统计这些评论的数量以确定当前迭代次数N。

4. Validate Issues

4. 验证问题

Code-level comments:
  1. Read the referenced code at path:line
  2. Evaluate: Is issue still present? Is suggestion correct? Does it align with project conventions?
  3. Mark as valid or invalid with brief rationale
PR-level comments:
  1. Parse the comment for actionable items (suggestions, questions, requested changes)
  2. Check if the feedback applies to current PR state (changes may have been made since)
  3. Evaluate: Is the request reasonable? Does it align with project goals?
  4. Mark as valid or invalid with brief rationale
  5. Skip pure acknowledgments, thanks, or informational comments without action items
代码级评论:
  1. 读取路径:行号对应的代码
  2. 评估:问题是否仍然存在?建议是否正确?是否符合项目规范?
  3. 标记为有效或无效,并附上简短理由
PR级评论:
  1. 解析评论中的可执行项(建议、问题、修改要求)
  2. 检查反馈是否适用于当前PR状态(自评论发布以来可能已进行过修改)
  3. 评估:请求是否合理?是否符合项目目标?
  4. 标记为有效或无效,并附上简短理由
  5. 跳过纯确认、感谢或无执行项的信息性评论

5. Create Review Overview

5. 创建评审概述

Prepare the review overview content (this will be posted as a PR comment, not committed):
markdown
undefined
准备评审概述内容(将作为PR评论发布,不提交到代码库):
markdown
undefined

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

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:
    path:line
    or PR-level
  • Reviewer: @user
  • Comment: [quoted]
  • Reason: [why invalid]
undefined
  • Location:
    path:line
    or PR-level
  • Reviewer: @user
  • Comment: [quoted]
  • Reason: [why invalid]
undefined

6. Create Task List

6. 创建任务列表

Use rune to create
review-fixes-[N].md
:
bash
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].md
bash
rune create ${OUTPUT_DIR}/review-fixes-${N}.md \
  --title "PR Review Fixes - Iteration ${N}" \
  --reference ${OUTPUT_DIR}/review-overview-${N}.md

Add 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]"} ] }'
undefined
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]"} ] }'
undefined

7. Fix Issues

7. 修复问题

Loop through tasks:
  1. rune next [file]
    - get next task
  2. rune progress [file] [id]
    - mark in-progress
  3. Implement the fix
  4. rune complete [file] [id]
    - mark complete
  5. Repeat until done
循环处理任务:
  1. rune next [file]
    - 获取下一个任务
  2. rune progress [file] [id]
    - 标记为进行中
  3. 实施修复
  4. rune complete [file] [id]
    - 标记为完成
  5. 重复直到所有任务完成

8. Check CI Status

8. 检查CI状态

After fixing review comments, verify CI checks:
bash
undefined
修复评审评论后,验证CI检查状态:
bash
undefined

Get 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 issues
gh run view [RUN_ID] --log-failed

**需要处理的检查类型:**

1. **测试失败**:解析测试输出,识别失败的测试,修复代码或测试用例
2. **Lint错误**:在本地运行Lint工具,修复报告的问题
3. **类型错误**:运行类型检查工具,修复类型不匹配问题
4. **构建失败**:检查构建日志,修复编译问题

9. Fix CI Issues

9. 修复CI问题

For each failed check:
  1. Identify the failure type from check name and logs
  2. Run locally to reproduce:
    • Tests:
      make test
      or project's test command
    • Lint:
      make lint
      or project's lint command
    • Types:
      make typecheck
      or equivalent
  3. Parse error output to identify specific failures
  4. 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
  5. Re-run locally to verify fix
  6. Add to task list if not already tracked
Test failure handling:
bash
undefined
针对每个失败的检查:
  1. 从检查名称和日志中识别失败类型
  2. 在本地复现问题
    • 测试:
      make test
      或项目的测试命令
    • Lint:
      make lint
      或项目的Lint命令
    • 类型检查:
      make typecheck
      或等效命令
  3. 解析错误输出以识别具体失败点
  4. 修复问题
    • 测试失败:检查是否需要更新测试预期或修复代码bug
    • Lint错误:尽可能应用自动修复,否则手动修复
    • 类型错误:添加/修复类型注解或修复类型不匹配问题
  5. 在本地重新运行以验证修复
  6. 如果未跟踪则添加到任务列表
测试失败处理:
bash
undefined

Run 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 source
go 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
undefined

For 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
undefined

Post 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:
  1. Run full test suite locally
  2. Run linter
  3. Commit only code changes (exclude any local review/task files)
  4. Push to remote
  5. Monitor CI status to confirm checks pass
完成所有修复后:
  1. 在本地运行完整测试套件
  2. 运行Lint工具
  3. 仅提交代码变更(排除任何本地评审/任务文件)
  4. 推送到远程仓库
  5. 监控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评论发布,绝不提交到代码库
  • 干净提交:仅提交实际代码变更,不提交工作文件/报告文件