respond-pr-feedback
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseRespond 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 to target (default: current branch's PR)
--pr <number> - - Skip thread resolution after posting replies (default: resolve all)
--no-resolve
bash
/beagle-core:respond-pr-feedback [--pr <number>] [--no-resolve]参数说明:
- - 目标PR编号(默认:当前分支对应的PR)
--pr <number> - - 发布回复后不关闭线程(默认:关闭所有线程)
--no-resolve
Prerequisites
前置条件
Run first to evaluate the feedback and make any necessary fixes.
/beagle-core:fetch-pr-feedback请先运行来评估反馈并进行必要的修复。
/beagle-core:fetch-pr-feedbackInstructions
操作步骤
1. Parse Arguments
1. 解析参数
Extract flags from :
$ARGUMENTS- or detect from current branch
--pr <number> - flag (boolean, default false)
--no-resolve
从中提取参数:
$ARGUMENTS- 或从当前分支自动识别
--pr <number> - 标记(布尔值,默认false)
--no-resolve
2. Get PR Context
2. 获取PR上下文
bash
undefinedbash
undefinedGet 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.jqIf 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 → thread (unresolved threads only). This enables immediate resolution after posting each reply.
databaseIdid获取评审线程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 }
}
}
}
}
}
}
"构建查找映射表:评论 → 线程(仅未关闭的线程)。这能在发布每条回复后立即关闭对应的线程。
databaseIdid4. Generate and Post Replies
4. 生成并发布回复
For each unreplied comment, determine the appropriate response based on your evaluation:
| Evaluation Outcome | Response |
|---|---|
| Feedback was incorrect/unfounded | Explain why the current code is correct |
| Feedback lacked context | Explain the design decision |
| Feedback was valid and fixed | "Fixed in |
| Feedback was valid but won't fix | Explain the tradeoff/decision |
Tagging guideline: -tag bot reviewers (e.g., ) to trigger their processing. Do not -tag human reviewers.
@@coderabbitai@Post reply to each comment:
bash
gh api "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments/$COMMENT_ID/replies" \
-X POST --raw-field body="$RESPONSE"针对每条未回复的评论,根据评估结果选择合适的回复:
| 评估结果 | 回复内容 |
|---|---|
| 反馈不正确/无依据 | 解释当前代码为何正确 |
| 反馈缺乏上下文 | 解释设计决策 |
| 反馈有效且已修复 | "已在 |
| 反馈有效但暂不修复 | 解释权衡/决策理由 |
标记准则: 使用标记机器人评审者(如)以触发其重新处理。不要标记人类评审者。
@@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 was passed.
--no-resolveAfter posting each reply, look up the from the step 3b mapping using the comment's :
$THREAD_ID$COMMENT_IDbash
gh api graphql -f query="
mutation {
resolveReviewThread(input: {threadId: \"$THREAD_ID\"}) {
thread { isResolved }
}
}
"- If a comment's has a matching thread ID in the lookup, resolve it
$COMMENT_ID - If no thread ID found (e.g., issue comment rather than review thread), skip resolution for that comment
此步骤默认执行。 仅当传入参数时跳过。
--no-resolve在发布每条回复后,使用步骤3b中构建的映射表,通过评论的查找对应的:
$COMMENT_ID$THREAD_IDbash
gh api graphql -f query="
mutation {
resolveReviewThread(input: {threadId: \"$THREAD_ID\"}) {
thread { isResolved }
}
}
"- 如果评论的在查找表中有对应的线程ID,则关闭该线程
$COMMENT_ID - 如果未找到线程ID(例如该评论是issue评论而非评审线程),则跳过该评论的线程关闭操作
6. Output Summary
6. 输出总结
Group by reviewer:
markdown
undefined按评审者分组:
markdown
undefinedReviewer: coderabbitai[bot]
评审者: coderabbitai[bot]
| File:Line | Response Type | Thread |
|---|---|---|
| Fixed in | Resolved |
| Explained design | Resolved |
| 文件:行号 | 回复类型 | 线程状态 |
|---|---|---|
| 已在 | 已关闭 |
| 解释设计思路 | 已关闭 |
Reviewer: octocat
评审者: octocat
| File:Line | Response Type | Thread |
|---|---|---|
| Won't fix | Resolved |
Footer:
```markdown
**Threads resolved: 3/3**| 文件:行号 | 回复类型 | 线程状态 |
|---|---|---|
| 暂不修复 | 已关闭 |
页脚:
```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
undefinedbash
undefinedRespond 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