# Accessing GitHub PR Review Comments with gh CLI

**Category**: GitHub CLI, Pull Requests, Automation
**Use Case**: Retrieving PR feedback for automated iteration workflows

## The Problem

GitHub has **two types** of comments on pull requests:
1. **Conversation comments** - Comments on the PR itself (visible in the main conversation thread)
2. **Inline review comments** - Comments attached to specific lines of code in the diff

The `gh pr view` command only shows conversation comments, not inline review comments. This is a critical limitation when building automated PR review workflows.

## Solution

### Get Conversation Comments (PR-Level)

```bash
# Shows only conversation comments, not inline review comments
gh pr view <PR_NUMBER> --comments
gh pr view 2 --comments
```

**Use case**: Quick overview of PR discussion

### Get Inline Review Comments (Line-Specific)

```bash
# Get all inline review comments attached to code
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments

# Pretty format showing file, line, and comment
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments \
  --jq '.[] | "📁 \(.path):\(.line)\n\(.body)\n---"'

# Filter by specific reviewer
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/comments \
  --jq '.[] | select(.user.login == "copilot-pull-request-reviewer") | {path: .path, line: .line, body: .body}'
```

**Use case**: Automated PR iteration, addressing specific code feedback

### Get Review Summaries

```bash
# Get all review objects (includes overall review state)
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/reviews

# Get comments from a specific review
gh api repos/<OWNER>/<REPO>/pulls/<PR_NUMBER>/reviews/<REVIEW_ID>/comments
```

**Use case**: Understanding review approval state, filtering by review session

## Real-World Example

```bash
# Automated workflow to get all Copilot feedback
OWNER="myorg"
REPO="myproject"
PR_NUMBER="42"

# Get inline comments from Copilot
gh api "repos/$OWNER/$REPO/pulls/$PR_NUMBER/comments" \
  --jq '.[] | select(.user.login == "copilot-pull-request-reviewer") | {
    file: .path,
    line: .line,
    comment: .body,
    created: .created_at
  }'
```

## Why This Matters for AI-Assisted Development

When building automated PR review iteration systems (like our `/iterate-pr` command), you **must** use the GitHub API to access inline review comments. Using only `gh pr view --comments` will miss the majority of actionable feedback from reviewers like @copilot, @claude, or human reviewers.

### Automation Checklist

✅ Use `gh api repos/.../pulls/.../comments` for inline review comments
✅ Use `gh pr view --comments` for conversation-level discussion
✅ Use `gh api repos/.../pulls/.../reviews` for review state (APPROVED, CHANGES_REQUESTED)
❌ Don't rely on `gh pr view` alone - you'll miss inline comments

## Common Gotcha

```bash
# ❌ This won't show inline review comments
gh pr view 2 --comments

# ✅ This will show inline review comments
gh api repos/owner/repo/pulls/2/comments
```

## Integration with .claude/scripts

Our automation scripts use this pattern:

```bash
# .claude/scripts/check-pr-reviews.sh
REVIEW_COMMENTS=$(gh api "repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/comments" \
  --jq "[.[] | select(.created_at > \"$LAST_CHECK\")] | length")
```

This ensures Claude Code can detect and respond to all types of review feedback automatically.

## References

- [GitHub API: Pull Request Review Comments](https://docs.github.com/en/rest/pulls/comments)
- [GitHub CLI Manual](https://cli.github.com/manual/)
- Related: `.claude/scripts/check-pr-reviews.sh` in this repository

## Key Takeaway

**For AI-powered PR automation**: Always use the GitHub API (`gh api`) to retrieve inline review comments. The `gh pr view` command is insufficient for automated workflows that need to address line-specific feedback.
