Fetch PR Feedback
Fetch review comments from all reviewers on the current PR, format them, and evaluate using the receive-feedback skill. Excludes the PR author and current user by default.
Usage
CODEBLOCK0
Flags:
- -
--pr <number> - PR number to target (default: current branch's PR) - INLINECODE1 - Include PR author's own comments (default: excluded)
Instructions
1. Parse Arguments
Extract flags from $ARGUMENTS:
- -
--pr <number> or detect from current branch - INLINECODE4 flag (boolean, default false)
2. Get PR Context
CODEBLOCK1
Store as $PR_NUMBER, $PR_AUTHOR, $OWNER, $REPO, $CURRENT_USER.
Note: $OWNER, $REPO, etc. are placeholders. Substitute actual values from previous steps.
If no PR exists for current branch, fail with: "No PR found for current branch. Use --pr to specify a PR number."
3. Fetch Comments
Fetch both types of comments, excluding $PR_AUTHOR and $CURRENT_USER (unless --include-author is set). Use --paginate with jq -s to combine paginated JSON arrays into one.
Write jq filters to temp files using heredocs with single-quoted delimiters (prevents shell escaping issues with !=, regex patterns, and angle brackets):
Issue comments (summary/walkthrough posts):
CODEBLOCK2
Review comments (line-specific):
CODEBLOCK3
If --include-author is set, omit the --arg pr_author parameter and the .user.login != $pr_author condition from both jq filter files. Keep the $current_user exclusion either way.
4. Format Feedback Document
Noise stripping — handled by the clean_body jq function in Step 3. Order matters: <!-- suggestion_start -->...<!-- suggestion_end --> blocks are removed first, then remaining HTML comments, then known-noise <details> blocks (Analysis chain, Prompt for AI Agents, Committable suggestion, Past reviewee, Recent review details, Tips), and finally the --- footer boilerplate. The <details> blocks must be stripped before the --- footer pattern because bot analysis chains contain --- separators that would otherwise truncate the actual finding. Substantive <details> blocks (e.g. "Suggested fix", "Proposed fix") are preserved. Comments exceeding 4000 chars after stripping are truncated with a [comment truncated] marker.
Group by reviewer — organize the formatted output by reviewer username:
CODEBLOCK4
If no comments found from any reviewer, output: "No review comments found on this PR (excluding PR author and current user)."
5. Evaluate with receive-feedback
Use the Skill tool to load the receive-feedback skill: INLINECODE32
Then process the formatted feedback document:
- 1. Parse each actionable item from the formatted document
- Process each item through verify → evaluate → execute
- Produce structured response summary
Example
CODEBLOCK5
获取PR反馈
从当前PR的所有审查者处获取审查评论,进行格式化,并使用接收反馈技能进行评估。默认排除PR作者和当前用户。
使用方法
bash
/beagle-core:fetch-pr-feedback [--pr <编号>] [--include-author]
标志参数:
- - --pr <编号> - 目标PR编号(默认:当前分支的PR)
- --include-author - 包含PR作者自己的评论(默认:排除)
操作说明
1. 解析参数
从$ARGUMENTS中提取标志参数:
- - --pr <编号> 或从当前分支检测
- --include-author 标志(布尔值,默认为false)
2. 获取PR上下文
bash
如果指定了--pr,直接使用该编号
否则,获取当前分支的PR:
gh pr view --json number,headRefName,url,author --jq {number, headRefName, url, author: .author.login}
获取仓库所有者/名称
gh repo view --json owner,name --jq {owner: .owner.login, name: .name}
获取当前认证用户
gh api user --jq .login
存储为$PRNUMBER、$PRAUTHOR、$OWNER、$REPO、$CURRENT_USER。
注意: $OWNER、$REPO等为占位符。请用前面步骤的实际值替换。
如果当前分支没有对应的PR,则失败并提示:当前分支未找到PR。请使用--pr指定PR编号。
3. 获取评论
获取两种类型的评论,排除$PRAUTHOR和$CURRENTUSER(除非设置了--include-author)。使用--paginate配合jq -s将分页的JSON数组合并为一个。
使用单引号分隔符的heredoc将jq过滤器写入临时文件(防止!=、正则表达式模式和尖括号导致的shell转义问题):
问题评论(摘要/概述帖子):
bash
cat > /tmp/issue_comments.jq << JQEOF
def clean_body:
gsub(.*?; ; s)
| gsub(; ; s)
| gsub(\\s\\s
🧩 分析链[\\s\\S]*? ; ; s)
| gsub(\\s\\s
🤖 AI代理提示[\\s\\S]*? ; ; s)
| gsub(\\s\\s
📝 可提交建议[\\s\\S]*? ; ; s)
| gsub(\\s过往被审查者.
? ; ; s)
| gsub(\\s近期审查详情[\\s\\S]
? ; ; s)
| gsub(\\s\\s
提示\\b.*? ; ; s)
| gsub(\\n?---\\n[\\s\\S]*$; ; s)
| gsub(^\\s+|\\s+$; )
| if length > 4000 then .[:4000] + \n\n[评论已截断] else . end
;
[(add // []) | .[] | select(
.user.login != $pr_author and
.user.login != $current_user
)] |
map({id, user: .user.login, body: (.body | cleanbody), createdat})
JQEOF
gh api --paginate repos/$OWNER/$REPO/issues/$PR_NUMBER/comments | \
jq -s --arg prauthor $PRAUTHOR --arg currentuser $CURRENTUSER \
-f /tmp/issue_comments.jq
审查评论(行级评论):
bash
cat > /tmp/review_comments.jq << JQEOF
def clean_body:
gsub(.*?; ; s)
| gsub(; ; s)
| gsub(\\s\\s
🧩 分析链[\\s\\S]*? ; ; s)
| gsub(\\s\\s
🤖 AI代理提示[\\s\\S]*? ; ; s)
| gsub(\\s\\s
📝 可提交建议[\\s\\S]*? ; ; s)
| gsub(\\s过往被审查者.
? ; ; s)
| gsub(\\s近期审查详情[\\s\\S]
? ; ; s)
| gsub(\\s\\s
提示\\b.*? ; ; s)
| gsub(\\n?---\\n[\\s\\S]*$; ; s)
| gsub(^\\s+|\\s+$; )
| if length > 4000 then .[:4000] + \n\n[评论已截断] else . end
;
[(add // []) | .[] | select(
.user.login != $pr_author and
.user.login != $current_user
)] |
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: (.body | clean_body),
created_at
})
JQEOF
gh api --paginate repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments | \
jq -s --arg prauthor $PRAUTHOR --arg currentuser $CURRENTUSER \
-f /tmp/review_comments.jq
如果设置了--include-author,则省略两个jq过滤器文件中的--arg prauthor参数和.user.login != $prauthor条件。无论是否设置该标志,都保留$current_user排除条件。
4. 格式化反馈文档
噪声去除 — 由步骤3中的cleanbody jq函数处理。顺序很重要:首先移除...块,然后是剩余的HTML注释,接着是已知噪声的块(分析链、AI代理提示、可提交建议、过往被审查者、近期审查详情、提示),最后是---页脚模板。必须在---页脚模式之前去除块,因为机器人分析链中包含---分隔符,否则会截断实际发现。保留有实质内容的块(例如建议修复、提议修复)。去除噪声后超过4000字符的评论将被截断,并添加[评论已截断]标记。
按审查者分组 — 按审查者用户名组织格式化输出:
markdown
PR #$PR_NUMBER 审查反馈
审查者:coderabbitai[bot]
摘要评论
[该审查者的问题评论,每条用---分隔]
行级评论
[该审查者的审查评论,每条格式为:]
文件:path/to/file.ts:42
[清理后的评论内容]
审查者:another-reviewer
摘要评论
...
行级评论
...
如果未找到任何审查者的评论,则输出:此PR上未找到审查评论(已排除PR作者和当前用户)。
5. 使用接收反馈技能进行评估
使用Skill工具加载接收反馈技能:Skill(skill: beagle-core:receive-feedback)
然后处理格式化的反馈文档:
- 1. 从格式化文档中解析每个可操作项
- 对每个项目执行验证→评估→执行流程
- 生成结构化响应摘要
示例
bash
获取当前分支PR的所有审查者评论(默认)
/beagle-core:fetch-pr-feedback
从指定PR获取
/beagle-core:fetch-pr-feedback --pr 123
包含PR作者自己的评论
/beagle-core:fetch-pr-feedback --include-author
组合使用
/beagle-core:fetch-pr-feedback --pr 456 --include-author