fetching-pr-comments

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Fetching PR Comments

获取PR评论

Overview

概述

Retrieve and parse GitHub PR review comments for the current branch using
gh
CLI.
使用
gh
CLI检索并解析当前分支的GitHub PR评审评论。

Quick Reference

快速参考

TaskCommand
Check if PR exists
gh pr view
View PR with issue comments
gh pr view --comments
Fetch review comments (code-level)
gh api repos/{owner}/{repo}/pulls/{n}/comments
Extract key fields
--jq '.[] | {path, line, body}'
任务命令
检查PR是否存在
gh pr view
查看包含议题评论的PR
gh pr view --comments
获取评审评论(代码级)
gh api repos/{owner}/{repo}/pulls/{n}/comments
提取关键字段
--jq '.[] | {path, line, body}'

Workflow

工作流程

  1. Get PR number for current branch:
    bash
    gh pr view --json number --jq '.number'
  2. Fetch review comments:
    bash
    gh api repos/{owner}/{repo}/pulls/{n}/comments \
      --jq '.[] | {path: .path, line: .line, body: .body}'
  3. 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}'
  1. 获取当前分支的PR编号:
    bash
    gh pr view --json number --jq '.number'
  2. 获取评审评论:
    bash
    gh api repos/{owner}/{repo}/pulls/{n}/comments \
      --jq '.[] | {path: .path, line: .line, body: .body}'
  3. 完整命令(一步到位):
    bash
    gh api repos/OWNER/REPO/pulls/$(gh pr view --json number -q .number)/comments \
      --jq '.[] | {path: .path, line: .line, body: .body}'

Important Distinctions

重要区别

TypeWhat it showsHow to get
Issue commentsPR-level discussion
gh pr view --comments
Review commentsCode-level feedback
gh api .../pulls/{n}/comments
类型展示内容获取方式
议题评论PR层面的讨论
gh pr view --comments
评审评论代码级反馈
gh api .../pulls/{n}/comments

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 --comments
Fetch 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
    )