Fetch unresolved PR review threads and apply fixes with user confirmation
Automates resolving pull request review comments by applying AI-suggested fixes and running tests.
npx claudepluginhub synthesys-lab/agentizeAutomates resolving unresolved PR review comments by fetching threads via GitHub's GraphQL API, applying AI-driven code modifications with user confirmation, running tests with bounded retry, and pushing changes with proper [review] tag commit formatting. Validates branch context and fails fast on mismatch (automation-friendly).
Invocation: /resolve-review [pr-no]
NOTE: This command is designed to be hands-off! Just faithfully apply changes to resolve all the unresolved and non-outdated review threads in the specified PR. NO NEED to ask user for confirmations.
From arguments:
[pr-no] (optional): The pull request number to process. If not provided, auto-detects from current branch.From GitHub (via gh CLI):
scripts/gh-graphql.sh review-threadsFrom git:
Terminal output:
Git commits:
[review] tag first, following docs/git-msg-tags.md conventionsIf a PR number is provided as argument, validate it. Otherwise, auto-detect from current branch:
# If argument provided, validate it's numeric
if [ -n "$PR_NO" ]; then
if ! [[ "$PR_NO" =~ ^[0-9]+$ ]]; then
echo "Error: Invalid PR number '$PR_NO'"
echo "Usage: /resolve-review [pr-no]"
exit 1
fi
else
# Auto-detect PR from current branch
PR_NO=$(gh pr view --json number --jq '.number' 2>/dev/null)
if [ -z "$PR_NO" ]; then
echo "Error: No PR number provided and could not auto-detect PR for current branch"
echo "Usage: /resolve-review [pr-no]"
exit 1
fi
echo "Auto-detected PR #$PR_NO from current branch"
fi
# Get PR details
gh pr view "$PR_NO" --json state,headRefName,headRepository
# Get repo owner/name
gh repo view --json owner,name
Error handling:
Check that the current branch matches the PR head branch. On mismatch, abort immediately and leave a failure comment on the PR (fail-fast for automation compatibility):
CURRENT_BRANCH=$(git branch --show-current)
PR_HEAD=$(gh pr view "$PR_NO" --json headRefName --jq '.headRefName')
if [ "$CURRENT_BRANCH" != "$PR_HEAD" ]; then
# Leave failure comment on PR for visibility
gh pr comment "$PR_NO" --body "⚠️ /resolve-review aborted: Current branch ($CURRENT_BRANCH) does not match PR head ($PR_HEAD). Please ensure the correct worktree is active."
echo "Error: Branch mismatch - current ($CURRENT_BRANCH) != PR head ($PR_HEAD)"
echo "Failure comment left on PR #$PR_NO"
exit 1
fi
This fail-fast behavior ensures compatibility with server-managed worktree workflows that require non-interactive execution.
# Get repo info
OWNER=$(gh repo view --json owner --jq '.owner.login')
REPO=$(gh repo view --json name --jq '.name')
# Fetch review threads
THREADS=$(scripts/gh-graphql.sh review-threads "$OWNER" "$REPO" "$PR_NO")
# Filter to unresolved and non-outdated threads
UNRESOLVED=$(echo "$THREADS" | jq '[.data.repository.pullRequest.reviewThreads.nodes[] | select(.isResolved == false and .isOutdated == false)]')
Error handling:
pageInfo.hasNextPage is true → Warn about pagination limitationCOUNT=$(echo "$UNRESOLVED" | jq 'length')
if [ "$COUNT" -eq 0 ]; then
echo "No unresolved review threads found."
echo "All review comments have been addressed."
exit 0
fi
echo "Found $COUNT unresolved review thread(s)"
For each unresolved thread:
Display thread context:
─────────────────────────────────────────
Thread 1/3: src/utils/parser.py:42
─────────────────────────────────────────
@reviewer1 commented:
> Consider adding error handling for empty input
File context (lines 40-45):
Read file context: Use the Read tool to show surrounding code context at the specified path and line range.
Propose changes: Analyze the review comment and propose code modifications.
Request confirmation:
Apply these changes? [y/n/s(skip)]
Apply changes (if confirmed): Use Edit tool to apply the proposed modifications.
Resolve thread via GraphQL (best-effort): After successfully applying a fix, attempt to resolve the review thread:
THREAD_ID=$(echo "$THREAD" | jq -r '.id')
scripts/gh-graphql.sh resolve-thread "$THREAD_ID"
If the resolve call fails, log a warning and continue processing remaining threads.
After processing all threads:
git diff --stat
Display the summary and ask:
Run tests (make test)? [y/n]
MAX_ATTEMPTS=2
ATTEMPT=1
while [ $ATTEMPT -le $MAX_ATTEMPTS ]; do
echo "Running tests (attempt $ATTEMPT/$MAX_ATTEMPTS)..."
if make test; then
echo "All tests passed!"
break
else
if [ $ATTEMPT -lt $MAX_ATTEMPTS ]; then
echo "Tests failed. Attempting to fix..."
# Allow one fix attempt
ATTEMPT=$((ATTEMPT + 1))
else
echo "Tests still failing after $MAX_ATTEMPTS attempts."
echo "Please review the failures manually."
# Ask user whether to proceed anyway or abort
fi
fi
done
git add .
Invoke /git-commit command, ensuring the commit message:
[review] tag first per docs/git-msg-tags.md conventionsExample commit message format:
[review][bugfix] Address PR review feedback
- Add error handling for empty input in parser
- Add test case for special characters
git push
Display summary:
✓ Resolved 2 review threads
✓ Tests passing
✓ Changes pushed to origin/$BRANCH
Error: PR #123 not found in this repository.
Verify the PR number and try again.
No unresolved review threads found.
All review comments have been addressed.
When the current branch doesn't match the PR head, the command aborts immediately and leaves a failure comment on the PR:
Terminal output:
Error: Branch mismatch - current (main) != PR head (feature-branch)
Failure comment left on PR #123
PR comment:
⚠️ /resolve-review aborted: Current branch (main) does not match PR head (feature-branch). Please ensure the correct worktree is active.
This fail-fast behavior supports automation workflows where interactive prompts are not compatible.
If pageInfo.hasNextPage is true:
Warning: PR has more than 100 review threads.
Only the first 100 threads were fetched.
Consider running the command again after resolving these.
Tests still failing after 2 attempts.
Failing tests:
- tests/cli/test-parser.sh
Options:
1. Review and fix manually
2. Commit anyway (not recommended)
3. Abort changes