fetching-pr-comments
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseFetching PR Comments
获取PR评论
Overview
概述
Retrieve and parse GitHub PR review comments for the current branch using CLI.
gh使用 CLI检索并解析当前分支的GitHub PR评审评论。
ghQuick Reference
快速参考
| Task | Command |
|---|---|
| Check if PR exists | |
| View PR with issue comments | |
| Fetch review comments (code-level) | |
| Extract key fields | |
| 任务 | 命令 |
|---|---|
| 检查PR是否存在 | |
| 查看包含议题评论的PR | |
| 获取评审评论(代码级) | |
| 提取关键字段 | |
Workflow
工作流程
-
Get PR number for current branch:bash
gh pr view --json number --jq '.number' -
Fetch review comments:bash
gh api repos/{owner}/{repo}/pulls/{n}/comments \ --jq '.[] | {path: .path, line: .line, body: .body}' -
Full command (single step):bash
gh api repos/OWNER/REPO/pulls/$(gh pr view --json number -q .number)/comments \ --jq '.[] | {path: .path, line: .line, body: .body}'
-
获取当前分支的PR编号:bash
gh pr view --json number --jq '.number' -
获取评审评论:bash
gh api repos/{owner}/{repo}/pulls/{n}/comments \ --jq '.[] | {path: .path, line: .line, body: .body}' -
完整命令(一步到位):bash
gh api repos/OWNER/REPO/pulls/$(gh pr view --json number -q .number)/comments \ --jq '.[] | {path: .path, line: .line, body: .body}'
Important Distinctions
重要区别
| Type | What it shows | How to get |
|---|---|---|
| Issue comments | PR-level discussion | |
| Review comments | Code-level feedback | |
| 类型 | 展示内容 | 获取方式 |
|---|---|---|
| 议题评论 | PR层面的讨论 | |
| 评审评论 | 代码级反馈 | |
Common Patterns
常见模式
Check if current branch has a PR:
bash
gh pr view 2>/dev/null && echo "PR exists" || echo "No PR"Get PR details + comments in one view:
bash
gh pr view --commentsFetch specific PR by number:
bash
gh pr view 429 --repo owner/repo --comments检查当前分支是否有PR:
bash
gh pr view 2>/dev/null && echo "PR exists" || echo "No PR"在一个视图中获取PR详情+评论:
bash
gh pr view --comments按编号获取特定PR:
bash
gh pr view 429 --repo owner/repo --comments不适用场景
- 创建新PR(使用)
gh pr create - 查看差异(使用)
gh pr diff - 合并PR(使用)
gh pr merge
When NOT to Use
—
- Creating new PRs (use )
gh pr create - Reviewing diffs (use )
gh pr diff - Merging (use )
gh pr merge
—