---
name: review-pr
description: Review a GitHub PR with inline comments for logic, style, performance, and documentation issues.
disable-model-invocation: true
argument-hint: "<pr_number_or_url>"
---

Review the GitHub PR provided as argument: $ARGUMENTS

## Steps

1. Fetch the PR metadata and diff using `gh pr view` and `gh pr diff`.
2. Fetch the actual file content from the PR's head branch for every changed file, so that line numbers are accurate. Use:
   ```
   gh api repos/{owner}/{repo}/contents/{path}?ref={head_branch} --jq '.content' | base64 -d
   ```
   This is critical — the `line` parameter in the GitHub API refers to the real line number in the new version of the file, NOT a position in the diff hunk. Always verify line numbers against the fetched file content before posting comments.
3. Analyze the changes for:
   - **Logic issues**: correctness bugs, performance problems, data quality risks, edge cases
   - **Style issues**: violations of the Gemma Analytics SQL style guide (CLAUDE.md has the summary)
   - **Documentation**: missing or incomplete PR description, missing tests/docs for new models
4. Present a structured review summary to the user with all findings.
5. Ask the user if they want the comments posted to the PR.
6. If confirmed, post each finding as an **individual inline comment** on the relevant diff line using `gh api repos/{owner}/{repo}/pulls/{number}/comments`.

## Comment format

Every inline comment MUST follow this format:

```
[Blocking] Category: description
[Non-Blocking] Category: description
```

- **[Blocking]** — must be fixed before merge (logic bugs, performance issues, data correctness)
- **[Non-Blocking]** — suggestions, style nits, questions (won't block merge)

Common categories: `Logic`, `Style`, `Performance`, `Documentation`, `Question`, `Security`

## Posting comments

- Use the GitHub API to post individual inline review comments (not a batched review):
  ```
  gh api repos/{owner}/{repo}/pulls/{number}/comments \
    --method POST \
    -f commit_id="<head_commit_sha>" \
    -f path="<file_path>" \
    -F line=<line_number> \
    -f body="<comment>"
  ```
- Get the head commit SHA via: `gh pr view {number} --json commits --jq '.commits[-1].oid'`
- Post all comments in parallel for efficiency.

## Important

- Always read the full file before commenting — don't review only the diff in isolation.
- For dbt/SQL projects, check against the Gemma Analytics SQL style guide rules in CLAUDE.md.
- Do NOT post comments without user confirmation.
