GitHub PR Review
D5.0Comprehensive PR review workflow with automated code analysis, issue resolution, and merge execution.
Get This Skill on GitHubOverview
name: gh-pr-review description: PR 代码审查、问题修复、CI 验证与合并。
GitHub PR Review
Comprehensive PR review workflow with automated code analysis, issue resolution, and merge execution.
Purpose
Drive thorough PR review cycles: analyze code changes using codeagent, verify CI status, fix all identified issues, and merge when ready. Supports both single PR review and epic batch review modes.
When to Use
Trigger this skill when:
- User provides a PR number to review (e.g., "review PR #123")
- User requests "review issue:45" for epic batch review
- User asks to "merge PR" or "check PR status"
- User mentions "code review" with a PR reference
Workflow Modes
Mode 1: Single PR Review
For reviewing individual pull requests.
Input: PR number (e.g., "123")
Mode 2: Epic Batch Review
For reviewing all PRs linked to an epic issue.
Input: "issue:N" format (e.g., "issue:45")
Workflow
Phase 0: Input Detection
-
Parse Input:
- If
$ARGUMENTSstarts withissue:→ Epic mode (go to Phase 0.1) - If
$ARGUMENTSis a number → Single PR mode (go to Phase 1) - If no argument → List open PRs and ask user to select
- If
-
List Open PRs (if no argument):
gh pr list --json number,title,author,updatedAtDisplay formatted list and use
AskUserQuestionto select PR.
Phase 0.1: Epic Batch Review Mode
For epic issues with multiple sub-issues and linked PRs:
-
Extract Epic Issue Number:
EPIC_NUMBER=$(echo "$ARGUMENTS" | sed 's/issue://') -
Fetch Epic Details:
gh issue view $EPIC_NUMBER --json title,body,labels -
Parse Sub-Issues: Look for patterns in issue body:
- [ ] #123or- [x] #123Depends on #123Closes #123
-
Find Linked PRs: For each sub-issue:
gh pr list --search "linked:issue:$SUB_ISSUE_NUMBER" --json number,title,stateOr parse PR links from sub-issue body/comments.
-
Build PR Queue: Order PRs by sub-issue dependency (blocking issues first).
-
Display Summary:
Found N sub-issues with M linked PRs. Proceeding with batch review: - Sub-issue #X → PR #Y - Sub-issue #A → PR #B -
Process Each PR: Execute Phase 1-6 for each PR in the queue.
-
Post Epic Summary: After all PRs reviewed:
gh issue comment $EPIC_NUMBER --body "## Epic Review Complete | Sub-Issue | PR | Status | |-----------|-----|--------| | #sub1 | #pr1 | ✅ Merged | | #sub2 | #pr2 | ✅ Merged | All PRs reviewed and merged successfully. Reviewed by Claude Code"
Phase 1: PR Discovery & Context
-
Fetch PR Details:
gh pr view $PR_NUMBER --json title,body,author,baseRefName,headRefName,url -
Get PR Diff:
gh pr diff $PR_NUMBER -
Check CI Status:
gh pr checks $PR_NUMBER --json name,status,conclusion -
Check for Linked Issues: Parse PR body for "Closes #N" or "Fixes #N" patterns. If found, fetch issue details for context.
Phase 2: Deep Code Review via Codeagent
Delegate comprehensive code review to codeagent:
# Use codeagent skill for review
# Pass the PR diff and context
Review focus areas:
- Correctness: Logic errors, edge cases, null handling
- Conventions: Project patterns, naming, structure
- Performance: Inefficient algorithms, unnecessary operations
- Tests: Coverage gaps, missing test cases
- Security: Input validation, auth checks, data exposure
Categorize findings:
- [Critical]: Must fix before merge (bugs, security issues)
- [Suggestions]: Nice-to-have improvements
- [Approved]: No issues found
Phase 3: CI Analysis
If any checks failed:
-
Get Failed Run Details:
gh run view $RUN_ID --log-failed -
Diagnose Root Cause: Categorize failure type:
- Test failure (which tests, why)
- Lint error (which rules, where)
- Build error (compilation, dependencies)
- Other (deployment, integration)
-
Document Findings: Add to issues list with specific error messages.
Phase 4: Issue Resolution Loop
If [Critical] issues or failed checks exist:
-
Fix Each Issue: Use codeagent skill to fix:
# Invoke codeagent with specific fix instructions -
Commit and Push:
git add -A git commit -m "fix: [specific issue description]" git push -
Wait for CI: Monitor CI re-run:
gh pr checks $PR_NUMBER --watch -
Iterate: Repeat until all checks pass. Maximum 3 fix iterations before escalating to user.
-
Track Progress: Use
TodoWriteto track fix progress.
Phase 5: Review Summary & Approval
Once all issues resolved and CI green:
-
Post Review Comment:
gh pr review $PR_NUMBER --approve --body "$(cat <<'EOF' ## Code Review Summary ### Changes Reviewed - [List key changes from diff] ### Review Findings - [Findings or "No issues found"] ### CI Status - ✅ All checks passing ### Verdict Approved for merge. Reviewed by Claude Code EOF )" -
If Fixes Were Made: Add additional comment detailing fixes:
gh pr comment $PR_NUMBER --body "## Fixes Applied - Fixed [issue 1] - Fixed [issue 2] All issues resolved. Ready for merge."
Phase 6: Merge Execution
-
Verify Merge Readiness:
gh pr view $PR_NUMBER --json mergeable,mergeStateStatus -
Check for Conflicts: If conflicts exist:
- Notify user
- Provide rebase instructions
- Stop (do not merge)
-
Select Merge Strategy: Default to squash merge (clean history). Only ask user if they want different strategy.
-
Execute Merge:
gh pr merge $PR_NUMBER --squash --delete-branch -
Return Result: Display merged PR URL and summary.
Phase 7: Error Handling
If CI Keeps Failing (after 3 iterations):
- Summarize blockers clearly
- Post comment on PR with findings
- Ask user for guidance
- Do not merge
If PR Has Conflicts:
- Notify user immediately
- Provide rebase command:
git fetch origin git rebase origin/main git push --force-with-lease - Stop workflow
If PR Already Merged/Closed:
- Report current status
- Exit gracefully
If gh Command Fails:
- Surface stderr message
- Check permissions and repository access
- Stop workflow
Integration with Codeagent
This skill uses the codeagent skill for:
- Comprehensive code review analysis
- Automated issue fixing
- Test coverage verification
- Code quality validation
The codeagent skill provides deep code understanding and can execute fixes autonomously while this skill manages the GitHub workflow.
Best Practices
Review Comments:
- Be specific about issues found
- Provide context and reasoning
- Suggest concrete improvements
- Acknowledge good practices
Merge Strategy:
- Squash merge for feature branches (clean history)
- Merge commit for release branches (preserve history)
- Rebase for linear history (when appropriate)
CI Verification:
- Always wait for CI to complete
- Never merge with failing checks
- Investigate flaky tests before merging
Example Usage
Single PR Review:
User: "Review PR #42"
Skill Actions:
1. Fetch PR #42 details and diff
2. Run codeagent code review
3. Check CI status (2 tests failing)
4. Fix failing tests with codeagent
5. Wait for CI to pass
6. Post approval comment
7. Squash merge and delete branch
Epic Batch Review:
User: "Review issue:10"
Skill Actions:
1. Fetch epic issue #10
2. Find 3 sub-issues with linked PRs
3. Review PR #15 (sub-issue #11) → Merge
4. Review PR #16 (sub-issue #12) → Merge
5. Review PR #17 (sub-issue #13) → Merge
6. Post summary on epic issue #10
What This Skill Can Do
AI-generated examples showing real capabilities
Ready to use this skill?
Visit the original repository to get the full skill configuration and installation instructions.
View on GitHub