gh-pr-review
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesegh-pr-review
gh-pr-review
A GitHub CLI extension that provides complete inline PR review comment access from the terminal with LLM-friendly JSON output.
一款GitHub CLI扩展,可从终端提供完整的PR内联评审评论访问权限,并支持对LLM友好的JSON输出。
When to Use
适用场景
Use this skill when you need to:
- View inline review comments and threads on a pull request
- Reply to review comments programmatically
- Resolve or unresolve review threads
- Create and submit PR reviews with inline comments
- Access PR review context for automated workflows
- Filter reviews by state, reviewer, or resolution status
This tool is particularly useful for:
- Automated PR review workflows
- LLM-based code review agents
- Terminal-based PR review processes
- Getting structured review data without multiple API calls
在以下场景中使用该工具:
- 查看拉取请求(PR)上的内联评审评论和对话线程
- 以编程方式回复评审评论
- 标记评审线程为已解决或未解决
- 创建并提交带有内联评论的PR评审
- 为自动化工作流获取PR评审上下文
- 按状态、评审人或解决状态筛选评审内容
该工具尤其适用于:
- 自动化PR评审工作流
- 基于LLM的代码评审Agent
- 基于终端的PR评审流程
- 无需多次调用API即可获取结构化评审数据
Installation
安装步骤
First, ensure the extension is installed:
sh
gh extension install agynio/gh-pr-review首先,确保已安装该扩展:
sh
gh extension install agynio/gh-pr-reviewCore Commands
核心命令
1. View All Reviews and Threads
1. 查看所有评审和对话线程
Get complete review context with inline comments and thread replies:
sh
gh pr-review review view -R owner/repo --pr <number>Useful filters:
- - Only show unresolved threads
--unresolved - - Filter by specific reviewer
--reviewer <login> - - Filter by review state
--states <APPROVED|CHANGES_REQUESTED|COMMENTED|DISMISSED> - - Keep only last n replies per thread
--tail <n> - - Exclude outdated threads
--not_outdated
Output: Structured JSON with reviews, comments, thread_ids, and resolution status.
获取包含内联评论和对话回复的完整评审上下文:
sh
gh pr-review review view -R owner/repo --pr <number>实用筛选器:
- - 仅显示未解决的对话线程
--unresolved - - 按特定评审人筛选
--reviewer <login> - - 按评审状态筛选
--states <APPROVED|CHANGES_REQUESTED|COMMENTED|DISMISSED> - - 仅保留每个对话线程的最后n条回复
--tail <n> - - 排除已过时的对话线程
--not_outdated
输出: 包含评审、评论、thread_ids和解决状态的结构化JSON。
2. Reply to Review Threads
2. 回复评审对话线程
Reply to an existing inline comment thread:
sh
gh pr-review comments reply <pr-number> -R owner/repo \
--thread-id <PRRT_...> \
--body "Your reply message"回复现有的内联评论对话线程:
sh
gh pr-review comments reply <pr-number> -R owner/repo \
--thread-id <PRRT_...> \
--body "Your reply message"3. List Review Threads
3. 列出评审对话线程
Get a filtered list of review threads:
sh
gh pr-review threads list -R owner/repo <pr-number> --unresolved --mine获取经过筛选的评审对话线程列表:
sh
gh pr-review threads list -R owner/repo <pr-number> --unresolved --mine4. Resolve/Unresolve Threads
4. 标记对话线程为已解决/未解决
Mark threads as resolved:
sh
gh pr-review threads resolve -R owner/repo <pr-number> --thread-id <PRRT_...>将对话线程标记为已解决:
sh
gh pr-review threads resolve -R owner/repo <pr-number> --thread-id <PRRT_...>5. Create and Submit Reviews
5. 创建并提交评审
Start a pending review:
sh
gh pr-review review --start -R owner/repo <pr-number>Add inline comments to pending review:
sh
gh pr-review review --add-comment \
--review-id <PRR_...> \
--path <file-path> \
--line <line-number> \
--body "Your comment" \
-R owner/repo <pr-number>Submit the review:
sh
gh pr-review review --submit \
--review-id <PRR_...> \
--event <APPROVE|REQUEST_CHANGES|COMMENT> \
--body "Overall review summary" \
-R owner/repo <pr-number>启动一个待处理的评审:
sh
gh pr-review review --start -R owner/repo <pr-number>向内联待处理评审添加评论:
sh
gh pr-review review --add-comment \
--review-id <PRR_...> \
--path <file-path> \
--line <line-number> \
--body "Your comment" \
-R owner/repo <pr-number>提交评审:
sh
gh pr-review review --submit \
--review-id <PRR_...> \
--event <APPROVE|REQUEST_CHANGES|COMMENT> \
--body "Overall review summary" \
-R owner/repo <pr-number>Output Format
输出格式
All commands return structured JSON optimized for programmatic use:
- Consistent field names
- Stable ordering
- Omitted fields instead of null values
- Essential data only (no URLs or metadata noise)
- Pre-joined thread replies
Example output structure:
json
{
"reviews": [
{
"id": "PRR_...",
"state": "CHANGES_REQUESTED",
"author_login": "reviewer",
"comments": [
{
"thread_id": "PRRT_...",
"path": "src/file.go",
"author_login": "reviewer",
"body": "Consider refactoring this",
"created_at": "2024-01-15T10:30:00Z",
"is_resolved": false,
"is_outdated": false,
"thread_comments": [
{
"author_login": "author",
"body": "Good point, will fix",
"created_at": "2024-01-15T11:00:00Z"
}
]
}
]
}
]
}所有命令均返回适用于编程使用的结构化JSON:
- 统一的字段名称
- 稳定的排序顺序
- 省略字段而非返回null值
- 仅包含必要数据(无URL或元数据冗余)
- 预合并的对话线程回复
示例输出结构:
json
{
"reviews": [
{
"id": "PRR_...",
"state": "CHANGES_REQUESTED",
"author_login": "reviewer",
"comments": [
{
"thread_id": "PRRT_...",
"path": "src/file.go",
"author_login": "reviewer",
"body": "Consider refactoring this",
"created_at": "2024-01-15T10:30:00Z",
"is_resolved": false,
"is_outdated": false,
"thread_comments": [
{
"author_login": "author",
"body": "Good point, will fix",
"created_at": "2024-01-15T11:00:00Z"
}
]
}
]
}
]
}Best Practices
最佳实践
- Always use to specify the repository explicitly
-R owner/repo - Use and
--unresolvedto focus on actionable comments--not_outdated - Save thread_id values from output for replying
review view - Filter by reviewer when dealing with specific review feedback
- Use to reduce output size by keeping only latest replies
--tail 1 - Parse JSON output instead of trying to scrape text
- ALWAYS get user approval before posting replies - Never automatically reply to PR comments without explicit user confirmation
- 始终使用明确指定仓库
-R owner/repo - 使用和
--unresolved聚焦于可处理的评论--not_outdated - 保存thread_id值 从的输出中获取,用于回复操作
review view - 按评审人筛选 处理特定评审人的反馈时使用
- 使用通过仅保留最新回复来减少输出大小
--tail 1 - 解析JSON输出 而非尝试抓取文本内容
- 发布回复前务必获得用户批准 - 绝不要在未获得用户明确确认的情况下自动回复PR评论
Common Workflows
常见工作流
Get Unresolved Comments for Current PR
获取当前PR的未解决评论
sh
gh pr-review review view --unresolved --not_outdated -R owner/repo --pr $(gh pr view --json number -q .number)sh
gh pr-review review view --unresolved --not_outdated -R owner/repo --pr $(gh pr view --json number -q .number)Reply to All Unresolved Comments
回复所有未解决评论
IMPORTANT: Always follow this workflow when addressing PR comments:
- Fetch comments: Get unresolved threads with
gh pr-review review view --unresolved --not_outdated -R owner/repo --pr <number> - Make code changes: Address the review feedback by modifying files
- Show proposed replies: Present the changes made and draft reply messages to the user
- Wait for approval: Get explicit user confirmation before posting any replies
- Post replies: Only after approval, use
gh pr-review comments reply <pr> -R owner/repo --thread-id <id> --body "..." - Optionally resolve: If appropriate, resolve threads with
gh pr-review threads resolve <pr> -R owner/repo --thread-id <id>
Never skip step 4 - automated replies without user review can be inappropriate or premature.
重要提示: 处理PR评论时请务必遵循以下工作流:
- 获取评论: 使用获取未解决的对话线程
gh pr-review review view --unresolved --not_outdated -R owner/repo --pr <number> - 修改代码: 通过修改文件来处理评审反馈
- 展示拟回复内容: 向用户展示已做的修改并草拟回复消息
- 等待批准: 在发布任何回复前获得用户的明确确认
- 发布回复: 仅在获得批准后,使用发布回复
gh pr-review comments reply <pr> -R owner/repo --thread-id <id> --body "..." - 可选:标记为已解决: 如果合适,使用标记线程为已解决
gh pr-review threads resolve <pr> -R owner/repo --thread-id <id>
绝不要跳过步骤4 - 未经用户审核的自动回复可能不合时宜或过于仓促。
Create Review with Inline Comments
创建带有内联评论的评审
- Start:
gh pr-review review --start -R owner/repo <pr> - Add comments:
gh pr-review review --add-comment -R owner/repo <pr> --review-id <PRR_...> --path <file> --line <num> --body "..." - Submit:
gh pr-review review --submit -R owner/repo <pr> --review-id <PRR_...> --event REQUEST_CHANGES --body "Summary"
- 启动评审:
gh pr-review review --start -R owner/repo <pr> - 添加评论:
gh pr-review review --add-comment -R owner/repo <pr> --review-id <PRR_...> --path <file> --line <num> --body "..." - 提交评审:
gh pr-review review --submit -R owner/repo <pr> --review-id <PRR_...> --event REQUEST_CHANGES --body "Summary"
Important Notes
重要说明
- All IDs use GraphQL format (PRR_... for reviews, PRRT_... for threads)
- Commands use pure GraphQL (no REST API fallbacks)
- Empty arrays are returned when no data matches filters
[] - The flag adds PRRC_... IDs when needed
--include-comment-node-id - Thread replies are sorted by created_at ascending
- 所有ID均使用GraphQL格式(PRR_...代表评审,PRRT_...代表对话线程)
- 命令使用纯GraphQL(无REST API降级方案)
- 无匹配数据时返回空数组
[] - 标志会在需要时添加PRRC_...格式的ID
--include-comment-node-id - 对话线程回复按created_at升序排序