You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This document provides a comprehensive guide for conducting thorough PR reviews using Claude Code tools, following industry best practices for code review.
Overview
A good PR review should:
Identify critical issues that could cause bugs or security problems
Suggest improvements for code quality and maintainability
Recognize good practices and well-implemented features
Provide actionable feedback with specific suggestions
Follow a consistent priority system
Step-by-Step PR Review Process
1. Initial PR Analysis
Start by gathering basic PR information:
# Get PR overview, files changed, and metadata
gh pr view <PR_NUMBER> --json title,body,url,author,files
# Get the full diff for detailed analysis
gh pr diff <PR_NUMBER>
What to look for:
PR scope and purpose
Number and types of files changed
Size of changes (additions/deletions)
Author and any existing comments
2. Code Analysis Framework
Analyze the code changes using this priority framework:
π΄ Critical Issues (Must Fix)
Type Safety: TypeScript type errors, any usage, incorrect generics
**High Priority**: Variable naming doesn't convey purpose.
`data` and `result` are too generic. Consider more descriptive names like `userPreferences` and `validationResult` to make the code self-documenting.
**Critical**: This function is doing too many things and is hard to follow.
Consider breaking this 50-line function into smaller, focused functions:
-`validateUserInput()`-`processPayment()`-`updateUserAccount()`
Each function should have a single, clear responsibility.
**High Priority**: Complex conditional logic is hard to parse.
Consider extracting boolean expressions to well-named variables:
```javascript// Instead of:if (user.age>=18&&user.hasValidId&&!user.isBlocked&&user.subscription.active)
// Use:constisEligibleUser=user.age>=18&&user.hasValidId&&!user.isBlockedconsthasActiveSubscription=user.subscription.activeif (isEligibleUser && hasActiveSubscription)
Respectful tone: Professional and constructive language
7. Common Tool Usage Patterns
Multiple Comments in Sequence
# Add multiple line comments for different issues
gh api repos/OWNER/REPO/pulls/PR_NUMBER/comments -X POST --field body="..." --field commit_id="..." --field path="..." --field line=N
gh api repos/OWNER/REPO/pulls/PR_NUMBER/comments -X POST --field body="..." --field commit_id="..." --field path="..." --field line=M
# etc.
Getting Commit SHA for Comments
# Get the latest commit SHA for the PR branch
gh api repos/OWNER/REPO/pulls/PR_NUMBER --jq '.head.sha'
Checking for Existing Comments
# See if there are already comments to avoid duplication
gh pr view PR_NUMBER --json comments
Example Review Workflows
Draft Review Workflow (Recommended)
# 1. Get PR info
gh pr view 56 --json title,body,files
gh pr diff 56
# 2. Analyze changes and identify issues# [Manual code analysis using diff output]# 3. Create draft review with all comments at once
gh api repos/postazure/CoTask/pulls/56/reviews -X POST \
--field event=PENDING \
--field body="## Overall AssessmentThis is a well-implemented feature with excellent test coverage and documentation. Main concerns are around TypeScript type safety and configuration management.**Recommendation**: Address the TypeScript issues before merging - otherwise looks great! π" \
--field 'comments=[ { "path": "apps/mobile/src/components/form/TextField.tsx", "line": 143, "body": "**Critical**: The forwardRef generic type signature loses type safety completely.\n\nCurrent code uses `any` which removes all type checking. Consider using a different pattern that preserves the generic type parameter." }, { "path": "apps/api/src/well-known/well-known.controller.ts", "line": 10, "body": "**High Priority**: Hardcoded Team ID should be moved to environment variable.\n\nConsider moving `ZBQMW5JHMN.com.postazure.cotask` to environment variables for better configuration management across environments." }, { "path": "apps/api/test/integration/well-known/well-known.e2e-spec.ts", "line": 22, "body": "β **Excellent**: Comprehensive test coverage with both unit and integration tests.\n\nGreat job covering all important aspects:\n- JSON structure validation\n- Content-Type headers\n- App identifier format validation\n- Public accessibility (crucial for iOS verification)" } ]'# 4. Review is now created as draft - you can:# - View it in GitHub web UI# - Edit comments and overall assessment# - Add/remove comments# - Choose final action (Approve/Request Changes/Comment)# - Submit when ready
Individual Comments Workflow
# 1. Get PR info
gh pr view 56 --json title,body,files
gh pr diff 56
# 2. Add overall comment
gh pr review 56 --comment --body "Overall assessment..."# 3. Add specific line comments one by one
gh api repos/owner/repo/pulls/56/comments -X POST \
--field body="**Critical**: TypeScript issue..." \
--field commit_id="$(gh api repos/owner/repo/pulls/56 --jq '.head.sha')" \
--field path="src/file.ts" \
--field line=143
# 4. Continue with other issues...
Working with Draft Reviews
# List all reviews for a PR (including drafts)
gh api repos/OWNER/REPO/pulls/PR_NUMBER/reviews
# Get specific draft review details
gh api repos/OWNER/REPO/pulls/PR_NUMBER/reviews/REVIEW_ID
# Submit a draft review (via web UI is easier, but possible via API)
gh api repos/OWNER/REPO/pulls/PR_NUMBER/reviews/REVIEW_ID/events -X POST \
--field event=COMMENT # or APPROVE or REQUEST_CHANGES
Best Practices Summary
Readability First: Always prioritize code readability - it's the foundation of maintainable software
Start Positive: Acknowledge good work before diving into issues
Prioritize Correctly: Focus reviewer attention on critical issues first
Be Specific: Provide exact line numbers and concrete suggestions
Include Examples: Show code snippets for complex fixes, especially for readability improvements
Consider Context: Understand existing patterns and constraints
Balance Feedback: Mix criticism with recognition
Stay Professional: Constructive, respectful, and educational tone
Think Like a Reader: Ask "Will someone understand this code in 6 months?" for every review
This approach ensures thorough, helpful PR reviews that improve code quality while maintaining positive team dynamics.