Fetch and address all PR review comments
Automates addressing PR review comments by fetching, categorizing, and systematically resolving feedback with code changes and replies.
/plugin marketplace add openshift-eng/ai-helpers/plugin install utils@ai-helpers[PR number (optional - uses current branch if omitted)]utils:address-reviews
/utils:address-reviews [PR number (optional - uses current branch if omitted)]
This command automates the process of addressing PR review comments by fetching all comments from a pull request, categorizing them by priority (blocking, change requests, questions, suggestions), and systematically addressing each one. It intelligently filters out outdated comments, bot-generated content, and oversized responses to optimize context usage. The command handles code changes, posts replies to reviewers, and maintains a clean git history by amending relevant commits rather than creating unnecessary new ones.
gh pr list --head <current-branch>gh pr checkout <PR_NUMBER> if not already on the branch, then git pullgit status. If uncommitted changes exist, ask user how to proceedFetch PR metadata with selective filtering:
a. First pass - Get metadata only (IDs, authors, lengths, URLs):
# Get issue comments (general PR comments - main conversation)
gh pr view <PR_NUMBER> --json comments --jq '.comments | map({
id,
author: .author.login,
length: (.body | length),
url,
createdAt,
type: "issue_comment"
})'
# Get reviews (need REST API for numeric IDs)
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/reviews --jq 'map({
id,
author: .user.login,
length: (.body | length),
state,
submitted_at,
type: "review"
})'
# Get review comments (inline code comments)
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments --jq 'map({
id,
author: .user.login,
length: (.body | length),
path,
line,
created_at,
type: "review_comment"
})'
b. Apply filtering logic (DO NOT fetch full body yet):
line == null (outdated review comments)length > 5000author in ["openshift-ci-robot", "openshift-ci"] (keep coderabbitai for code review insights)c. Second pass - Fetch ONLY essential fields for kept items:
# For issue comments - fetch only body and minimal metadata:
gh api repos/{owner}/{repo}/issues/comments/<comment_id> --jq '{id, body, user: .user.login, created_at, url}'
# For reviews - fetch only body and state:
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/reviews/<review_id> --jq '{id, body, user: .user.login, state, submitted_at}'
# For review comments - fetch only body and code context:
gh api repos/{owner}/{repo}/pulls/comments/<comment_id> --jq '{id, body, user: .user.login, path, position, diff_hunk, created_at}'
Note: Using --jq to select only needed fields minimizes context usage. Avoid fetching full API responses with all metadata.
d. Log filtering results:
ℹ️ Fetched N/M comments (filtered out K large/bot comments saving ~X chars)
Fetch commit messages: gh pr view <PR_NUMBER> --json commits -q '.commits[] | "\(.messageHeadline)\n\n\(.messageBody)"'
Store ONLY the kept (filtered) comments for analysis
Note: Most filtering already happened in Step 1 to save context window space.
Additional filtering (for remaining fetched comments):
Categorize:
Group by context: Group by file, then by proximity (within 10 lines)
Prioritize: BLOCKING → CHANGE_REQUEST → QUESTION → SUGGESTION
Present summary: Show counts by category and file groupings, ask user to confirm
When multiple comments relate to the same concern/fix:
Done. (Also addresses feedback from @user)a. Validate: Thoroughly analyze if the change is valid and fixes an issue or improves code. Don't be afraid to reject the change if it doesn't make sense.
b. If requested change is valid:
Plan and implement changes
Commit and Push
Review changes: git diff
Analyze commit structure: git log --oneline origin/main..HEAD
Commit strategy:
DEFAULT: Amend the relevant commit
git rebase -i origin/main to amend the specific relevant commitCreate and push commit:
git commit --amend --no-edit && git push --force-with-lease (or update message if scope changed)Concise Reply template: Done. [1-line what changed]. [Optional 1-line why]
Post reply:
gh api repos/{owner}/{repo}/pulls/<PR_NUMBER>/comments/<comment_id>/replies -f body="<reply>"
If fails: gh pr comment <PR_NUMBER> --body="@<author> <reply>"
c. If declining change:
d. If unsure: Ask user for clarification
All replies must include: ---\n*AI-assisted response via Claude Code*
Show user: