implement-feedback-from-pr
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseImplement 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
开始之前
- CLI authenticated —
ghconfirms.gh auth status - — the project's conventions are the reference point when a reviewer asks for a "standard pattern."
CLAUDE.md - — after applying feedback, run
skills/workflow/review-diff/SKILL.mdlocally to check for regressions.review-diff
- 已完成gh CLI认证——可确认认证状态。
gh auth status - ——当评审员要求采用「标准模式」时,以项目的约定文档为参考依据。
CLAUDE.md - ——应用反馈后,本地运行
skills/workflow/review-diff/SKILL.md检查是否存在回归问题。review-diff
Step 1: identify the PR
步骤1:确定目标PR
bash
undefinedbash
undefinedCurrent 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.jsongh 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.jsonStep 3: classify each comment
步骤3:对每条评论进行分类
Put every comment into one of five buckets:
| Bucket | What to do |
|---|---|
| Must change — reviewer is correct, apply the change | Implement, commit separately, reply to the thread linking the commit |
| Question — reviewer asked something | Answer in-thread; no code change needed |
| Discuss — reviewer suggested an alternative worth considering | Reply with your reasoning; if you agree, move to "must change"; if not, explain why |
| Out of scope — valid point but outside this PR's goal | Reply acknowledging, link to a follow-up issue you create |
| Nit / optional — formatting, personal preference | Apply 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:
-
Open the file and make the change exactly as the reviewer requested (or the closest correct interpretation).
-
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>" -
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.
对于每条「必须修改」的评论:
-
打开文件,严格按照评审员的要求进行修改(或最接近的正确解读)。
-
单独提交代码,提交信息需关联该反馈:bash
git add <file> git commit -m "fix: address review feedback on <file> — <one-line summary>" -
推送提交: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 from :
id/tmp/pr-inline.jsonbash
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.jsonidbash
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-requestbash
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
undefinedbash
undefinedEvery 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"
undefinedgh pr checks "$PR"
undefinedCommon Mistakes
常见错误
| Mistake | Correction |
|---|---|
| Squashing review fixes into the original commits | Keep them separate. The PR reviewer needs to see what changed since they last looked. |
| Silently ignoring a comment | Reply to every comment. "Deferred to follow-up #123" is a valid reply; silence is not. |
| Applying changes you disagree with without pushback | If the reviewer is wrong, reply explaining why. Healthy reviews are dialogues, not dictations. |
| Missing reviews posted as top-level PR comments | Fetch all three comment APIs ( |
| 错误 | 修正方式 |
|---|---|
| 将评审修复的提交合并到原始提交中 | 保留单独提交。PR评审员需要查看自他们上次查看以来的变更内容。 |
| 默默忽略评论 | 回复每条评论。「已推迟到后续Issue #123处理」是合理回复;沉默则不是。 |
| 应用你不同意的修改而不提出异议 | 如果评审员的意见有误,回复解释原因。良好的评审是对话,而非指令。 |
| 遗漏作为PR顶部评论发布的评审意见 | 获取全部三个评论API( |