implement-feedback-from-pr

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Implement feedback from a PR review

落实PR评审反馈

Fetch reviewer comments from a GitHub pull request, classify them, apply the requested changes, and respond to each comment in-thread.
从GitHub拉取请求中获取评审员的评论,对其进行分类,应用要求的修改,并在对应线程中回复每条评论。

Before You Start

开始之前

  • gh
    CLI authenticated —
    gh auth status
    confirms.
  • CLAUDE.md
    — the project's conventions are the reference point when a reviewer asks for a "standard pattern."
  • skills/workflow/review-diff/SKILL.md
    — after applying feedback, run
    review-diff
    locally to check for regressions.
  • 已完成gh CLI认证——
    gh auth status
    可确认认证状态。
  • CLAUDE.md
    ——当评审员要求采用「标准模式」时,以项目的约定文档为参考依据。
  • skills/workflow/review-diff/SKILL.md
    ——应用反馈后,本地运行
    review-diff
    检查是否存在回归问题。

Step 1: identify the PR

步骤1:确定目标PR

bash
undefined
bash
undefined

Current branch's PR (if one exists)

当前分支对应的PR(如果存在)

gh pr view --json number,title,url
gh pr view --json number,title,url

Or by number if the user gave one

或者如果用户指定了PR编号

PR=<number> gh pr view "$PR" --json number,title,url

Confirm with the user which PR this is.
PR=<number> gh pr view "$PR" --json number,title,url

与用户确认目标PR。

Step 2: fetch all review comments

步骤2:获取所有评审评论

GitHub has three comment types; fetch all:
bash
PR=<number>
GitHub有三种评论类型,需全部获取:
bash
PR=<number>

PR-level "conversation" comments (top-level on the PR)

PR级别的「会话」评论(PR顶部的评论)

gh api "repos/{owner}/{repo}/issues/$PR/comments" > /tmp/pr-conversation.json
gh api "repos/{owner}/{repo}/issues/$PR/comments" > /tmp/pr-conversation.json

Review comments (inline on specific lines)

评审评论(针对特定代码行的内联评论)

gh api "repos/{owner}/{repo}/pulls/$PR/comments" > /tmp/pr-inline.json
gh api "repos/{owner}/{repo}/pulls/$PR/comments" > /tmp/pr-inline.json

Review summaries with verdicts (approved / changes requested)

带有结论的评审总结(批准/要求修改)

gh api "repos/{owner}/{repo}/pulls/$PR/reviews" > /tmp/pr-reviews.json

Extract the substance:

```bash
jq -r '.[] | "[\(.user.login)] \(.body)"' /tmp/pr-conversation.json
jq -r '.[] | "[\(.user.login)] \(.path):\(.line // .original_line) — \(.body)"' /tmp/pr-inline.json
jq -r '.[] | select(.body != null and .body != "") | "[\(.user.login)] \(.state) — \(.body)"' /tmp/pr-reviews.json
gh api "repos/{owner}/{repo}/pulls/$PR/reviews" > /tmp/pr-reviews.json

提取核心内容:

```bash
jq -r '.[] | "[\(.user.login)] \(.body)"' /tmp/pr-conversation.json
jq -r '.[] | "[\(.user.login)] \(.path):\(.line // .original_line) — \(.body)"' /tmp/pr-inline.json
jq -r '.[] | select(.body != null and .body != "") | "[\(.user.login)] \(.state) — \(.body)"' /tmp/pr-reviews.json

Step 3: classify each comment

步骤3:对每条评论进行分类

Put every comment into one of five buckets:
BucketWhat to do
Must change — reviewer is correct, apply the changeImplement, commit separately, reply to the thread linking the commit
Question — reviewer asked somethingAnswer in-thread; no code change needed
Discuss — reviewer suggested an alternative worth consideringReply with your reasoning; if you agree, move to "must change"; if not, explain why
Out of scope — valid point but outside this PR's goalReply acknowledging, link to a follow-up issue you create
Nit / optional — formatting, personal preferenceApply if easy, otherwise acknowledge
Show the classified list to the user before acting. Let them adjust the buckets.
将每条评论归入以下五个类别之一:
类别处理方式
必须修改——评审员的意见正确,需应用修改落实修改,单独提交代码,并在对应线程中回复,关联提交记录
疑问——评审员提出了问题在对应线程中回复;无需修改代码
讨论——评审员提出了值得考虑的替代方案回复你的理由;若同意,则归入「必须修改」;若不同意,解释原因
超出范围——意见合理但超出当前PR的目标回复表示认可,并关联你创建的后续跟进Issue
细微建议/可选——格式问题、个人偏好若容易实现则应用,否则表示认可
在执行操作前,将分类后的列表展示给用户,让他们可以调整分类。

Step 4: apply "must change" edits

步骤4:应用「必须修改」的编辑

For each comment in Must change:
  1. Open the file and make the change exactly as the reviewer requested (or the closest correct interpretation).
  2. Commit as a separate commit with a message referencing the feedback:
    bash
    git add <file>
    git commit -m "fix: address review feedback on <file> — <one-line summary>"
  3. Push the commit:
    bash
    git push
Do NOT squash review-fix commits into feature commits — the reviewer wants to see the diff from their comment.
对于每条「必须修改」的评论:
  1. 打开文件,严格按照评审员的要求进行修改(或最接近的正确解读)。
  2. 单独提交代码,提交信息需关联该反馈:
    bash
    git add <file>
    git commit -m "fix: address review feedback on <file> — <one-line summary>"
  3. 推送提交:
    bash
    git push
请勿将评审修复的提交合并到功能提交中——评审员需要查看自他们评论以来的差异。

Step 5: create follow-up issues for out-of-scope items

步骤5:为超出范围的内容创建后续Issue

For each Out of scope comment, create a GitHub issue:
bash
gh issue create --title "Follow-up: <one-line>" --body "$(cat <<EOF
Raised in #<PR-number>:

> <quote from the comment>

<your proposed scope>
EOF
)"
Capture the issue URL for the reply.
对于每条「超出范围」的评论,创建GitHub Issue:
bash
gh issue create --title "Follow-up: <one-line>" --body "$(cat <<EOF
Raised in #<PR-number>:

> <quote from the comment>

<your proposed scope>
EOF
)"
记录Issue的URL用于回复。

Step 6: reply to every comment

步骤6:回复每条评论

For each review comment, post a reply. Use the comment's
id
from
/tmp/pr-inline.json
:
bash
gh api -X POST "repos/{owner}/{repo}/pulls/$PR/comments/<comment-id>/replies" \
  -f body="Addressed in <commit-sha>. <optional note>."
For conversation-level comments:
bash
gh api -X POST "repos/{owner}/{repo}/issues/$PR/comments" \
  -f body="Addressed in <commit-sha>. <optional note>."
Reply to every comment, even "Nit" ones — a silent response leaves the reviewer wondering.
针对每条评审评论,发布回复。使用
/tmp/pr-inline.json
中的评论
id
bash
gh api -X POST "repos/{owner}/{repo}/pulls/$PR/comments/<comment-id>/replies" \
  -f body="Addressed in <commit-sha>. <optional note>."
针对会话级别的评论:
bash
gh api -X POST "repos/{owner}/{repo}/issues/$PR/comments" \
  -f body="Addressed in <commit-sha>. <optional note>."
回复每条评论,包括「细微建议」类的——沉默会让评审员疑惑。

Step 7: re-request review

步骤7:重新请求评审

bash
gh pr comment "$PR" --body "All feedback addressed in <range-of-commits>. Re-requesting review."
gh pr review-request "$PR" --reviewer <reviewer-login>    # if the project uses review-request
bash
gh pr comment "$PR" --body "All feedback addressed in <range-of-commits>. Re-requesting review."
gh pr review-request "$PR" --reviewer <reviewer-login>    # 若项目使用评审请求机制

Verify

验证

bash
undefined
bash
undefined

Every must-change comment has a commit that references it

每条「必须修改」的评论都有对应的提交记录关联

git log --oneline origin/main..HEAD | grep -i "review|feedback"
git log --oneline origin/main..HEAD | grep -i "review|feedback"

Lint/tests still pass after the changes (pull from CLAUDE.md Quick Reference)

修改后代码检查/测试仍能通过(参考CLAUDE.md快速参考)

CI has re-run on the latest commit

CI已在最新提交上重新运行

gh pr checks "$PR"
undefined
gh pr checks "$PR"
undefined

Common Mistakes

常见错误

MistakeCorrection
Squashing review fixes into the original commitsKeep them separate. The PR reviewer needs to see what changed since they last looked.
Silently ignoring a commentReply to every comment. "Deferred to follow-up #123" is a valid reply; silence is not.
Applying changes you disagree with without pushbackIf the reviewer is wrong, reply explaining why. Healthy reviews are dialogues, not dictations.
Missing reviews posted as top-level PR commentsFetch all three comment APIs (
/issues/$PR/comments
,
/pulls/$PR/comments
,
/pulls/$PR/reviews
). They're separate endpoints.
错误修正方式
将评审修复的提交合并到原始提交中保留单独提交。PR评审员需要查看自他们上次查看以来的变更内容。
默默忽略评论回复每条评论。「已推迟到后续Issue #123处理」是合理回复;沉默则不是。
应用你不同意的修改而不提出异议如果评审员的意见有误,回复解释原因。良好的评审是对话,而非指令。
遗漏作为PR顶部评论发布的评审意见获取全部三个评论API(
/issues/$PR/comments
/pulls/$PR/comments
/pulls/$PR/reviews
)。它们是独立的接口。