Fix PR Comments
Fetch unresolved review comments from the current PR and fix them interactively.
Instructions
Step 1: Get PR Information
Run the following to get the current PR's owner, repo, and number:
bash
gh pr view --json number,headRepositoryOwner,headRepository -q '{owner: .headRepositoryOwner.login, repo: .headRepository.name, number: .number}'
If this fails, the current branch likely doesn't have an open PR. Inform the user and stop.
Step 2: Fetch Unresolved Review Threads
Use the GitHub GraphQL API to get all unresolved review threads:
bash
gh api graphql -f query='
query($owner: String!, $repo: String!, $pr: Int!) {
repository(owner: $owner, name: $repo) {
pullRequest(number: $pr) {
reviewThreads(first: 100) {
nodes {
isResolved
comments(first: 10) {
nodes {
body
path
line
author { login }
}
}
}
}
}
}
}
' -f owner=OWNER -f repo=REPO -F pr=NUMBER
Replace OWNER, REPO, and NUMBER with values from Step 1.
Step 3: Filter and Process Comments
From the response:
- •Filter to threads where
isResolved: false - •For each thread, get the first comment (the original feedback)
- •Skip comments that are just questions or discussions (no actionable code change requested)
Step 4: Interactive Fixing
For each actionable unresolved comment:
- •
Present the comment to the user:
- •File path and line number
- •Author
- •Comment body
- •
Ask the user using AskUserQuestion with options:
- •"Fix" - Apply the requested change
- •"Skip" - Move to next comment
- •"Stop" - End processing
- •
If "Fix":
- •Read the relevant file
- •Understand the context around the line
- •Apply the fix using the Edit tool
- •Confirm the fix was applied
Step 5: Output Summary
After processing all comments, output:
code
## PR Comments Fixed **Fixed:** [count] comments **Skipped:** [count] comments ### Changes Made: - [file:line] - [brief description of fix] - ...
If no unresolved comments were found, output:
code
No unresolved PR comments found.