by @openhands
Post PR review comments using the GitHub API with inline comments, suggestions, and priority labels.
Post structured code review feedback using the GitHub API with inline comments on specific lines.
Bundle ALL comments into a single review API call. Do not post comments individually.
Use the GitHub CLI (gh). The GITHUB_TOKEN is automatically available.
gh api \
-X POST \
repos/{owner}/{repo}/pulls/{pr_number}/reviews \
-F commit_id='{commit_sha}' \
-F event='COMMENT' \
-F body='Brief 1-3 sentence summary.' \
-F comments[][path]='path/to/file.py' \
-F comments[][line]=42 \
-F comments[][side]='RIGHT' \
-F comments[][body]='š Important: Your comment here.' \
-F comments[][path]='another/file.js' \
-F comments[][line]=15 \
-F comments[][side]='RIGHT' \
-F comments[][body]='š” Suggestion: Another comment.'
| Parameter | Description |
|---|---|
commit_id | Commit SHA to comment on (use git rev-parse HEAD) |
event | COMMENT, APPROVE, or REQUEST_CHANGES |
path | File path as shown in the diff |
line | Line number in the NEW version (right side of diff) |
side | RIGHT for new/added lines, LEFT for deleted lines |
body | Comment text with priority label |
For comments spanning multiple lines, add start_line to specify the range:
-F comments[][path]='path/to/file.py' \
-F comments[][start_line]=10 \
-F comments[][line]=12 \
-F comments[][side]='RIGHT' \
-F comments[][body]='š” Suggestion: Refactor this block:
```suggestion
line_one = "new"
line_two = "code"
line_three = "here"
```'
Important: The suggestion must have the same number of lines as the range (e.g., lines 10-12 = 3 lines).
Start each comment with a priority label. Minimize nits - leave minor style issues to linters.
| Label | When to Use |
|---|---|
| š“ Critical | Must fix: security vulnerabilities, bugs, data loss risks |
| š ... |