SuperAPI AI 工具集

attach-review-to-pr

编程与开发

查看项目

更新于 10-16 01:35

技能介绍

用途:为 GitHub Pull Request 添加面向具体代码行的审查评论,效果类似 GitHub 界面中在代码行上留言。gh pr review 本身不支持行级评论,需改用底层 gh api 调用 REST 接口。

主要能力:优先使用 MCP 工具 mcp__github_inline_comment__create_inline_comment;不可用时用 gh api。单条评论走 /pulls/{pr}/comments 端点,多条评论合并为一次审查走 /pulls/{pr}/reviews 端点,后者为原子操作、通知更少。审查事件类型有 COMMENT、APPROVE、REQUEST_CHANGES。支持多行评论,用 start_line 与 start_side 指定范围。

必要用法:先运行 gh auth status 确认 GitHub CLI 已安装并认证。单条评论示例:gh api repos/{owner}/{repo}/pulls/{pr_number}/comments -f body='评论内容' -f commit_id='<sha>' -f path='path/to/file.js' -F line=42 -f side='RIGHT'。多条评论用 heredoc 管道传入 JSON:cat <<'EOF' | gh api repos/{owner}/{repo}/pulls/{pr_number}/reviews --input -,其中包含 event、body 与 comments 数组。参数注意:字符串用 -f,整数用 -F。line 指 diff 中的位置而非文件绝对行号,side 取 RIGHT(新增/修改行)或 LEFT(删除行)。可先用 gh api repos/{owner}/{repo}/pulls/{pr_number} --jq '.head.sha' 获取最新提交 SHA。

限制与常见问题:GitHub 每个用户对同一 PR 只允许一个未提交的 pending review,否则报 422 错误 user_id can only have one pending review per pull request;可改用单条评论端点或先提交待处理审查。数组不能通过 --raw-field 传入,需用 --input 的 JSON。行号必须属于该 diff,否则报 line must be part of the diff。commit_id 必须属于该 PR,否则报 commit_sha is not part of the pull request。具体费用、平台限制等资料暂未提供。