forge-address-pr-feedback

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Address PR Feedback

处理PR反馈

Analyze and address unresolved feedback on a GitHub pull request.
分析并处理GitHub拉取请求中未解决的反馈。

Input

输入

The PR number or URL will be provided as: $ARGUMENTS
If no argument is provided, detect the PR from the current branch using
gh pr view --json number
.
PR编号或URL将以以下形式提供:$ARGUMENTS
如果未提供参数,将使用
gh pr view --json number
从当前分支检测对应的PR。

Process

流程

Step 1: Fetch PR Information and Unresolved Threads

步骤1:获取PR信息与未解决的讨论线程

IMPORTANT: Use the GraphQL API to get review threads with resolution status. The REST API does NOT provide
isResolved
status.
bash
undefined
重要提示:使用GraphQL API获取带有解决状态的评审线程。REST API不提供
isResolved
状态。
bash
undefined

Get PR number and repo info

Get PR number and repo info

gh pr view <PR_NUMBER> --json number,title,headRefName,url
gh pr view <PR_NUMBER> --json number,title,headRefName,url

CRITICAL: Use GraphQL to get ALL review threads with resolution status

CRITICAL: Use GraphQL to get ALL review threads with resolution status

gh api graphql -f query=' query { repository(owner: "<OWNER>", name: "<REPO>") { pullRequest(number: <PR_NUMBER>) { reviewThreads(first: 100) { nodes { isResolved isOutdated path line id comments(first: 10) { nodes { id body author { login } url } } } } } } }'

Filter the results to get only unresolved threads:
```bash
gh api graphql -f query=' query { repository(owner: "<OWNER>", name: "<REPO>") { pullRequest(number: <PR_NUMBER>) { reviewThreads(first: 100) { nodes { isResolved isOutdated path line id comments(first: 10) { nodes { id body author { login } url } } } } } } }'

过滤结果以仅获取未解决的线程:
```bash

Get unresolved threads with full context

Get unresolved threads with full context

gh api graphql -f query='...' --jq '.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved == false)'
undefined
gh api graphql -f query='...' --jq '.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved == false)'
undefined

Step 2: Process Each Unresolved Thread

步骤2:处理每条未解决的线程

For EACH unresolved thread:
  1. Read the thread ID, file path, line number, and all comments
  2. Read the relevant file and surrounding context
  3. Understand what change is being requested
  4. Categorize the feedback:
    • Actionable: Code change, fix, or improvement needed
    • Question: Clarification needed - respond with explanation
    • Discussion: Opinion/preference - assess if change improves code
    • Already addressed: Change was made but thread not resolved
    • Won't fix: Explain why the current approach is preferred
    • Follow-up issue: Valid improvement but out of scope - create linked issue
对于每一条未解决的线程:
  1. 读取线程ID、文件路径、行号以及所有评论
  2. 读取相关文件及上下文内容
  3. 理解评审者要求的修改内容
  4. 对反馈进行分类:
    • 可执行:需要修改代码、修复问题或进行优化
    • 疑问:需要澄清问题 - 回复相关解释
    • 讨论:意见/偏好类反馈 - 评估修改是否能提升代码质量
    • 已处理:已完成修改但线程未标记为解决
    • 不修复:解释为何当前方案更优
    • 后续议题:有效的改进建议但超出当前PR范围 - 创建关联议题

Step 3: Address and Reply to Each Thread INDIVIDUALLY

步骤3:单独处理并回复每条线程

CRITICAL: Reply to each thread IMMEDIATELY after addressing it. Do NOT batch responses into a single collective comment.
For each unresolved thread, in order:
  1. Make the change (if actionable):
    • Read the file(s) that need changes
    • Make the requested changes using Edit tool
    • Run the project's lint/format/check commands (see CLAUDE.md or package.json for scripts)
  2. Commit the change (if code was modified):
    bash
    git add <files>
    git commit -m "fix: Address PR feedback - <brief description>"
  3. Reply DIRECTLY to that specific thread using GraphQL:
    bash
    # Reply to a review thread (NOT a PR comment!)
    gh api graphql -f query='
    mutation {
      addPullRequestReviewThreadReply(input: {
        pullRequestReviewThreadId: "<THREAD_ID>"
        body: "<response>"
      }) {
        comment {
          id
        }
      }
    }'
    Alternative using REST API (reply to the first comment in the thread):
    bash
    gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments/<COMMENT_ID>/replies \
      -X POST \
      -f body="<response>"
  4. Move to the next thread and repeat
重要提示:处理完每条线程后立即回复。不要将所有回复批量整合为一条评论。
按顺序处理每条未解决的线程:
  1. 执行修改(如果是可执行类反馈):
    • 读取需要修改的文件
    • 使用编辑工具完成要求的修改
    • 运行项目的lint/格式化/检查命令(参考CLAUDE.md或package.json中的脚本)
  2. 提交修改(如果修改了代码):
    bash
    git add <files>
    git commit -m "fix: Address PR feedback - <brief description>"
  3. 使用GraphQL直接回复该线程
    bash
    # Reply to a review thread (NOT a PR comment!)
    gh api graphql -f query='
    mutation {
      addPullRequestReviewThreadReply(input: {
        pullRequestReviewThreadId: "<THREAD_ID>"
        body: "<response>"
      }) {
        comment {
          id
        }
      }
    }'
    使用REST API的替代方案(回复线程中的第一条评论):
    bash
    gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments/<COMMENT_ID>/replies \
      -X POST \
      -f body="<response>"
  4. 处理下一条线程并重复上述步骤

Step 4: Response Format for Thread Replies

步骤4:线程回复的格式

Reply format based on category:
  • Actionable: "Fixed in commit
    <sha>
    . <brief explanation of the change>"
  • Question: "<answer to the question with code references if helpful>"
  • Discussion: "Good point. <explanation of decision - either made the change or explained why not>"
  • Already addressed: "This was addressed in commit
    <sha>
    . <brief explanation>"
  • Won't fix: "Keeping the current approach because <reason>. Happy to discuss further."
  • Follow-up issue: "Created #<issue_number> to track this. <brief explanation of why it's out of scope>"
根据反馈分类使用对应的回复格式:
  • 可执行:“已在提交
    <sha>
    中修复。<修改内容的简要说明>”
  • 疑问:“<问题的解答,如有需要可引用代码>”
  • 讨论:“观点很好。<决策解释 - 说明已进行修改或为何不修改>”
  • 已处理:“该问题已在提交
    <sha>
    中处理。<简要说明>”
  • 不修复:“将保留当前方案,原因是<具体理由>。欢迎进一步讨论。”
  • 后续议题:“已创建#<议题编号>跟踪该问题。<说明为何超出当前PR范围>”

Step 5: Create Follow-up Issues (When Needed)

步骤5:创建后续议题(如有需要)

If feedback identifies valid improvements that are out of scope for this PR:
bash
gh issue create \
  --title "<concise description of the follow-up work>" \
  --body "## Context

This issue was identified during PR review of #<PR_NUMBER>.
如果反馈提出了有效的改进建议但超出当前PR范围:
bash
gh issue create \
  --title "<后续工作的简洁描述>" \
  --body "## 背景

该议题源于对PR #<PR_NUMBER>的评审。

Original Feedback

原始反馈

<quote the reviewer's comment>
<引用评审者的评论>

Proposed Solution

建议方案

<brief description of what should be done>
<简要说明需要完成的工作>

Related

关联内容

  • PR: #<PR_NUMBER>
  • Review comment: <link to the comment>"
undefined
  • PR: #<PR_NUMBER>
  • 评审评论: <评论链接>"
undefined

Step 6: Push All Changes

步骤6:推送所有修改

After all threads are addressed:
bash
git push
处理完所有线程后:
bash
git push

Step 7: Summary

步骤7:总结

Provide a summary of actions taken:
  • Number of feedback items addressed
  • Commits created (list each)
  • Follow-up issues created (with links)
  • Any items that need human review or decision
提供已执行操作的总结:
  • 已处理的反馈数量
  • 创建的提交(列出每一条)
  • 创建的后续议题(附带链接)
  • 任何需要人工评审或决策的事项

Important Guidelines

重要准则

  1. Use GraphQL for thread discovery: The REST API (
    /pulls/{}/comments
    ) does NOT show resolution status. Always use the GraphQL query to find unresolved threads.
  2. Reply to threads individually:
    • DO NOT post one collective comment addressing all feedback
    • DO reply directly to each thread as you address it
    • This keeps discussions organized and allows threads to be resolved
  3. Reply immediately after addressing: Don't wait until the end to reply. Address thread → reply → move to next thread.
  4. Be thorough: Address ALL unresolved feedback, don't skip items
  5. Be specific: Reference exact commits, line numbers, and code in responses
  6. Test changes: Run checks and tests before committing
  7. Granular commits: One commit per logical change for easy review
  8. Create follow-up issues: When valid feedback is out of scope, create a linked issue rather than ignoring or scope-creeping the PR
  1. 使用GraphQL发现线程:REST API(
    /pulls/{}/comments
    )不显示解决状态。请始终使用GraphQL查询来查找未解决的线程。
  2. 单独回复线程
    • 不要发布一条整合所有反馈的评论
    • 请直接回复每条已处理的线程
    • 这能让讨论更有条理,并允许线程被标记为解决
  3. 处理后立即回复:不要等到所有处理完成后再回复。处理线程→回复→处理下一条线程。
  4. 全面处理:处理所有未解决的反馈,不要跳过任何项
  5. 具体明确:在回复中引用确切的提交、行号和代码
  6. 测试修改:提交前运行检查和测试
  7. 细粒度提交:每个逻辑修改对应一个提交,便于评审
  8. 创建后续议题:当有效的反馈超出当前范围时,创建关联议题而非忽略或扩大PR范围

Example Workflow

示例工作流

1. Fetch unresolved threads via GraphQL
2. For thread about "missing null check" in file.ts:149:
   a. Read file.ts
   b. Add null check
   c. Run format/check
   d. Commit: "fix: Add null check for edge case"
   e. Reply to thread: "Fixed in commit `abc123`. Added null check."
3. For thread asking "why use X instead of Y?":
   a. Reply to thread: "Using X because <reason>. Y would require <tradeoff>."
4. For thread about "add tests":
   a. Create issue #123 for test coverage
   b. Reply to thread: "Created #123 to track this - out of scope for this PR."
5. Push all commits
6. Summarize actions taken
1. 通过GraphQL获取未解决的线程
2. 针对file.ts:149中“缺失空值检查”的线程:
   a. 读取file.ts
   b. 添加空值检查
   c. 运行格式化/检查命令
   d. 提交:"fix: Add null check for edge case"
   e. 回复线程:"Fixed in commit `abc123`. Added null check."
3. 针对询问“为何使用X而非Y?”的线程:
   a. 回复线程:"Using X because <reason>. Y would require <tradeoff>."
4. 针对“添加测试”的线程:
   a. 创建议题#123跟踪测试覆盖情况
   b. 回复线程:"Created #123 to track this - out of scope for this PR."
5. 推送所有提交
6. 总结已执行的操作

Related Skills

关联技能

Before: Use
forge-reflect-pr
to self-review before requesting review. After merging: Use
forge-update-changelog
to document user-facing changes. Full workflow:
forge-setup-project
forge-create-issue
forge-implement-issue
forge-reflect-pr
forge-address-pr-feedback
forge-update-changelog
之前:在请求评审前,使用
forge-reflect-pr
进行自我评审。 合并后:使用
forge-update-changelog
记录面向用户的修改。 完整工作流
forge-setup-project
forge-create-issue
forge-implement-issue
forge-reflect-pr
forge-address-pr-feedback
forge-update-changelog

Example Usage

示例用法

/forge-address-pr-feedback 123
/forge-address-pr-feedback https://github.com/owner/repo/pull/123
/forge-address-pr-feedback  # Uses current branch's PR
/forge-address-pr-feedback 123
/forge-address-pr-feedback https://github.com/owner/repo/pull/123
/forge-address-pr-feedback  # 使用当前分支对应的PR