respond-pr-feedback

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Respond to PR Feedback

回复PR反馈

Post replies to review comments after you've evaluated the feedback and made fixes. Resolves conversation threads by default.
在评估反馈并完成修复后,发布对评审意见的回复。默认会关闭对话线程。

Usage

使用方法

bash
/beagle-core:respond-pr-feedback [--pr <number>] [--no-resolve]
Flags:
  • --pr <number>
    - PR number to target (default: current branch's PR)
  • --no-resolve
    - Skip thread resolution after posting replies (default: resolve all)
bash
/beagle-core:respond-pr-feedback [--pr <number>] [--no-resolve]
参数说明:
  • --pr <number>
    - 目标PR编号(默认:当前分支对应的PR)
  • --no-resolve
    - 发布回复后不关闭线程(默认:关闭所有线程)

Prerequisites

前置条件

Run
/beagle-core:fetch-pr-feedback
first to evaluate the feedback and make any necessary fixes.
请先运行
/beagle-core:fetch-pr-feedback
来评估反馈并进行必要的修复。

Instructions

操作步骤

1. Parse Arguments

1. 解析参数

Extract flags from
$ARGUMENTS
:
  • --pr <number>
    or detect from current branch
  • --no-resolve
    flag (boolean, default false)
$ARGUMENTS
中提取参数:
  • --pr <number>
    或从当前分支自动识别
  • --no-resolve
    标记(布尔值,默认false)

2. Get PR Context

2. 获取PR上下文

bash
undefined
bash
undefined

Get PR info (if --pr not specified, uses current branch)

获取PR信息(如果未指定--pr,则使用当前分支)

gh pr view --json number,author --jq '{number, author: .author.login}'
gh pr view --json number,author --jq '{number, author: .author.login}'

Get repo owner/name

获取仓库所有者/名称

gh repo view --json owner,name --jq '{owner: .owner.login, name: .name}'
gh repo view --json owner,name --jq '{owner: .owner.login, name: .name}'

Get current authenticated user

获取当前已认证用户

gh api user --jq '.login'

Store as `$PR_NUMBER`, `$PR_AUTHOR`, `$OWNER`, `$REPO`, `$CURRENT_USER`.

**Note:** `$OWNER`, `$REPO`, etc. are placeholders. Substitute actual values from previous steps.
gh api user --jq '.login'

将结果存储为`$PR_NUMBER`、`$PR_AUTHOR`、`$OWNER`、`$REPO`、`$CURRENT_USER`。

**注意:** `$OWNER`、`$REPO`等为占位符,请替换为上一步获取的实际值。

3. Fetch Unreplied Comments and Thread Data

3. 获取未回复的评审意见和线程数据

3a. Unreplied Review Comments

3a. 未回复的评审意见

Fetch review comments, excluding PR author and current user, filtering to root comments that haven't been replied to.
Write the jq filter to a temp file using a heredoc with single-quoted delimiter (prevents shell escaping issues with
!=
, regex patterns, and angle brackets):
bash
cat > /tmp/unreplied_comments.jq << 'JQEOF'
add // [] |
获取评审意见,排除PR作者和当前用户,筛选出未被回复的根评论。
使用单引号分隔的here-doc将jq过滤器写入临时文件(避免shell对
!=
、正则表达式和尖括号的转义问题):
bash
cat > /tmp/unreplied_comments.jq << 'JQEOF'
add // [] |

Root comments from reviewers (not replies, not PR author, not current user)

来自评审者的根评论(不是回复,不是PR作者,不是当前用户)

[.[] | select( .in_reply_to_id == null and .user.login != $pr_author and .user.login != $current_user )] as $roots |
[.[] | select( .in_reply_to_id == null and .user.login != $pr_author and .user.login != $current_user )] as $roots |

IDs that current user has already replied to

当前用户已回复过的评论ID

[.[] | select(.user.login == $current_user) | .in_reply_to_id] as $replied |
[.[] | select(.user.login == $current_user) | .in_reply_to_id] as $replied |

Filter to unreplied only

筛选出未回复的评论

$roots | map(select(. as $c | $replied | index($c.id) == null)) |
$roots | map(select(. as $c | $replied | index($c.id) == null)) |

Dedup: group by path + line + reviewer, pick newest per group

去重:按路径+行号+评审者分组,选取每组最新的评论

group_by({ p: .path, l: (.line // .original_line), u: .user.login }) | map(sort_by(.created_at) | last) |
group_by({ p: .path, l: (.line // .original_line), u: .user.login }) | map(sort_by(.created_at) | last) |

Output needed fields

输出所需字段

map({ id, user: .user.login, path, line_display: ( .line as $end | .start_line as $start | if $start and $start != $end then "($start)-($end)" else "($end // .original_line)" end ), body }) JQEOF

```bash
gh api --paginate "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments" | \
  jq -s --arg pr_author "$PR_AUTHOR" --arg current_user "$CURRENT_USER" \
  -f /tmp/unreplied_comments.jq
If no unreplied comments found, output: "All review comments have been addressed." and stop.
map({ id, user: .user.login, path, line_display: ( .line as $end | .start_line as $start | if $start and $start != $end then "($start)-($end)" else "($end // .original_line)" end ), body }) JQEOF

```bash
gh api --paginate "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments" | \
  jq -s --arg pr_author "$PR_AUTHOR" --arg current_user "$CURRENT_USER" \
  -f /tmp/unreplied_comments.jq
如果未找到未回复的评论,输出:"所有评审意见均已处理完毕。"并终止流程。

3b. Pre-fetch Thread Data

3b. 预获取线程数据

Fetch review thread IDs to enable resolution after posting replies:
bash
gh api graphql -f query="
  query {
    repository(owner: \"$OWNER\", name: \"$REPO\") {
      pullRequest(number: $PR_NUMBER) {
        reviewThreads(first: 100) {
          nodes {
            id
            isResolved
            comments(first: 1) {
              nodes { databaseId }
            }
          }
        }
      }
    }
  }
"
Build a lookup map: comment
databaseId
→ thread
id
(unresolved threads only). This enables immediate resolution after posting each reply.
获取评审线程ID,以便在发布回复后关闭线程:
bash
gh api graphql -f query="
  query {
    repository(owner: \"$OWNER\", name: \"$REPO\") {
      pullRequest(number: $PR_NUMBER) {
        reviewThreads(first: 100) {
          nodes {
            id
            isResolved
            comments(first: 1) {
              nodes { databaseId }
            }
          }
        }
      }
    }
  }
"
构建查找映射表:评论
databaseId
→ 线程
id
(仅未关闭的线程)。这能在发布每条回复后立即关闭对应的线程。

4. Generate and Post Replies

4. 生成并发布回复

For each unreplied comment, determine the appropriate response based on your evaluation:
Evaluation OutcomeResponse
Feedback was incorrect/unfoundedExplain why the current code is correct
Feedback lacked contextExplain the design decision
Feedback was valid and fixed"Fixed in
$COMMIT_SHA
" or brief description of change
Feedback was valid but won't fixExplain the tradeoff/decision
Tagging guideline:
@
-tag bot reviewers (e.g.,
@coderabbitai
) to trigger their processing. Do not
@
-tag human reviewers.
Post reply to each comment:
bash
gh api "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments/$COMMENT_ID/replies" \
  -X POST --raw-field body="$RESPONSE"
针对每条未回复的评论,根据评估结果选择合适的回复:
评估结果回复内容
反馈不正确/无依据解释当前代码为何正确
反馈缺乏上下文解释设计决策
反馈有效且已修复"已在
$COMMIT_SHA
中修复" 或简要描述修改内容
反馈有效但暂不修复解释权衡/决策理由
标记准则: 使用
@
标记机器人评审者(如
@coderabbitai
)以触发其重新处理。不要
@
标记人类评审者。
发布对每条评论的回复:
bash
gh api "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments/$COMMENT_ID/replies" \
  -X POST --raw-field body="$RESPONSE"

5. Resolve Threads

5. 关闭线程

This step runs by default. Skip only if
--no-resolve
was passed.
After posting each reply, look up the
$THREAD_ID
from the step 3b mapping using the comment's
$COMMENT_ID
:
bash
gh api graphql -f query="
  mutation {
    resolveReviewThread(input: {threadId: \"$THREAD_ID\"}) {
      thread { isResolved }
    }
  }
"
  • If a comment's
    $COMMENT_ID
    has a matching thread ID in the lookup, resolve it
  • If no thread ID found (e.g., issue comment rather than review thread), skip resolution for that comment
此步骤默认执行。 仅当传入
--no-resolve
参数时跳过。
在发布每条回复后,使用步骤3b中构建的映射表,通过评论的
$COMMENT_ID
查找对应的
$THREAD_ID
bash
gh api graphql -f query="
  mutation {
    resolveReviewThread(input: {threadId: \"$THREAD_ID\"}) {
      thread { isResolved }
    }
  }
"
  • 如果评论的
    $COMMENT_ID
    在查找表中有对应的线程ID,则关闭该线程
  • 如果未找到线程ID(例如该评论是issue评论而非评审线程),则跳过该评论的线程关闭操作

6. Output Summary

6. 输出总结

Group by reviewer:
markdown
undefined
按评审者分组:
markdown
undefined

Reviewer: coderabbitai[bot]

评审者: coderabbitai[bot]

File:LineResponse TypeThread
src/foo.ts:42
Fixed in
abc1234
Resolved
src/bar.ts:15
Explained designResolved
文件:行号回复类型线程状态
src/foo.ts:42
已在
abc1234
中修复
已关闭
src/bar.ts:15
解释设计思路已关闭

Reviewer: octocat

评审者: octocat

File:LineResponse TypeThread
src/baz.ts:7
Won't fixResolved

Footer:

```markdown
**Threads resolved: 3/3**
文件:行号回复类型线程状态
src/baz.ts:7
暂不修复已关闭

页脚:

```markdown
**已关闭线程数: 3/3**

Response Guidelines

回复准则

  • @
    -tag bot reviewers to trigger re-processing; do not tag human reviewers
  • Keep responses concise and technical
  • No performative agreement ("Great point!", "You're right!")
  • Reference specific code/design when explaining decisions
  • If fixed: state what changed, no gratitude
  • 使用
    @
    标记机器人评审者以触发重新处理;不要标记人类评审者
  • 回复应简洁且专业
  • 无需客套话(如"好主意!"、"你说得对!")
  • 解释决策时引用具体代码/设计
  • 若已修复:说明修改内容,无需表达感谢

Example

示例

bash
undefined
bash
undefined

Respond to all reviewers on current PR (resolves threads)

回复当前PR上所有评审者的意见(默认关闭线程)

/beagle-core:respond-pr-feedback
/beagle-core:respond-pr-feedback

Respond on a specific PR

回复指定PR的评审意见

/beagle-core:respond-pr-feedback --pr 123
/beagle-core:respond-pr-feedback --pr 123

Respond without resolving threads

回复评审意见但不关闭线程

/beagle-core:respond-pr-feedback --no-resolve
undefined
/beagle-core:respond-pr-feedback --no-resolve
undefined