PR Reviewer (Review Only)
Fetch all comments from a GitHub PR, summarize issues, and generate a detailed implementation prompt for a faster coding agent to resolve them.
Workflow
1. Get Repository Info
gh repo view --json owner,name
2. Fetch PR Comments
Ask for the PR number, then fetch all comments:
gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
title
body
author { login }
reviews(first: 100) {
nodes {
author { login }
body
state
comments(first: 100) {
nodes {
body
path
line
author { login }
}
}
}
}
comments(first: 100) {
nodes {
author { login }
body
}
}
reviewThreads(first: 100) {
nodes {
isResolved
path
line
comments(first: 50) {
nodes {
author { login }
body
}
}
}
}
}
}
}' -F owner='{owner}' -F repo='{repo}' -F pr={PR_NUMBER}
3. Identify Reviewer Types
Known bots:
- •
qodo-merge-pro[bot]- Structured suggestions - •
coderabbitai[bot]- Detailed analysis - •
gemini-code-assist[bot]- Suggestions - •
copilot[bot]- Code suggestions - •
sonarcloud[bot]- Security/bugs
Tag each comment as 🤖 Bot or 👤 Human.
4. Summarize Issues
Present a table: | # | File:Line | Reviewer | Type | Issue | Status |
Group by:
- •🔴 Blocking (changes requested, security)
- •🟠 Suggestions (improvements)
- •🟡 Nitpicks (style, minor)
- •💬 Questions/Discussion
5. Create Worktree to Read PR Code
Create a temporary worktree to access the PR's current code:
PR_BRANCH=$(gh pr view {PR_NUMBER} --json headRefName -q .headRefName)
git worktree add ../pr-{PR_NUMBER}-review "$PR_BRANCH"
cd ../pr-{PR_NUMBER}-review
6. Read Referenced Files
For each issue, read the referenced file from the worktree to understand the full context. Extract the relevant code snippets to include in the implementation prompt.
7. Cleanup Review Worktree
After reading all files, remove the temporary worktree:
cd -
git worktree remove ../pr-{PR_NUMBER}-review
8. Generate Implementation Prompt
Output a detailed, self-contained prompt that a less capable coding agent can follow to resolve all issues. The prompt must include:
# PR Review Implementation Task
## Context
- PR #{number}: {title}
- Branch: {branch_name}
## Setup
Create an isolated worktree for this PR (allows parallel work on multiple PRs):
```bash
# Get the PR branch name
PR_BRANCH=$(gh pr view {PR_NUMBER} --json headRefName -q .headRefName)
# Create worktree in sibling directory
git worktree add ../pr-{PR_NUMBER} "$PR_BRANCH"
# Change to the worktree directory
cd ../pr-{PR_NUMBER}
Working directory: ../pr-{PR_NUMBER}
Issues to Address
Issue 1: {short description}
File: {path} (line {line})
Priority: {🔴/🟠/🟡}
Requested by: {reviewer} ({human/bot})
Current code:
{relevant code snippet}
Problem: {clear explanation of what's wrong}
Required change: {explicit instructions on what to do}
Expected result:
{example of correct code if applicable}
Issue 2: ...
(repeat for each issue)
Verification
After making changes, run:
{type check / build / test commands}
Commit and Push
git add -A git commit -m "Address PR review feedback" git push
Cleanup
After pushing, remove the worktree:
cd ..
git worktree remove pr-{PR_NUMBER}
### 9. Prompt Quality Guidelines The generated prompt must be: - **Self-contained**: Agent should not need to search for context - **Explicit**: No ambiguity about what changes to make - **Ordered**: Blocking issues first, then suggestions, then nitpicks - **Verified**: Include exact file paths and line numbers - **Actionable**: Each issue has clear before/after expectations **Bot handling in prompt:** - Include rationale for why bot suggestion should/shouldn't be applied - Flag security issues prominently - Note when human feedback contradicts bot suggestions ### 10. Output Format Present the final prompt in a fenced code block so it can be easily copied and passed to another agent. ## Notes - Always preserve the original PR author's intent - Skip resolved threads - Human feedback takes priority over bot suggestions when they conflict - Security issues from any source should always be included - If an issue is unclear, include it with a note asking the implementing agent to clarify