Review Pull Requests
How to set up automated pull request review with CodeSpar's Review Agent, including webhook triggers, manual review commands, auto-approve configuration, and review output format.
Review Pull Requests
CodeSpar's Review Agent analyzes pull requests for code quality, potential bugs, security issues, and best practices. Reviews can be triggered automatically via webhooks or manually via chat commands.
Prerequisites
- Repository linked — see Link a Repository
GITHUB_TOKENconfigured withreposcope (to read PR diffs and post comments)- Webhook configured (for automatic triggers) — auto-configured when linking with
WEBHOOK_BASE_URLset
How It Works
Automatic Review (Webhook)
When a pull request is opened or updated, GitHub sends a pull_request webhook event to CodeSpar. The agent's behavior depends on the autonomy level:
| Level | Behavior |
|---|---|
| L0 | Ignored |
| L1 | Notification: "PR #42 opened by @alice" |
| L2 | Notification + suggestion: "I can review this PR. Approve with: @codespar approve sg-..." |
| L3+ | Review Agent spawns automatically, review is posted to channel and (optionally) as a GitHub PR comment |
Enable Auto-Review
Set autonomy to L3 or higher:
From this point, every new PR on the linked repository will be automatically reviewed.
Manual Review
Trigger a review on any PR at any time, regardless of autonomy level:
You can also use natural language:
Review Output
The Review Agent analyzes the PR diff and produces a structured review:
Verdict Values
| Verdict | Meaning |
|---|---|
| Approve | No issues found, PR is good to merge |
| Approve with suggestions | Minor improvements suggested, not blocking |
| Request changes | Issues found that should be addressed before merge |
| Needs discussion | Architectural or design decisions need team input |
Review Criteria
The Review Agent evaluates:
| Category | What It Checks |
|---|---|
| Code quality | Readability, naming, structure, DRY violations |
| Bugs | Potential runtime errors, null references, edge cases |
| Security | SQL injection, XSS, credential exposure, input validation |
| Performance | N+1 queries, unnecessary allocations, algorithm complexity |
| Tests | Test coverage for new code, edge case testing |
| Types | TypeScript type safety, any usage, missing types |
| Best practices | Framework conventions, error handling, logging |
Auto-Approve Configuration
At L3+ autonomy, the Review Agent can be configured to auto-approve low-risk PRs:
What Qualifies as Low-Risk
A PR is considered low-risk when:
- Changes fewer than 50 lines
- Only modifies non-critical files (docs, configs, styles, tests)
- No changes to security-sensitive files (auth, permissions, crypto)
- No changes to database schemas or migrations
- All existing tests pass
- No new dependencies added
Auto-Approve Behavior by Level
| Level | Auto-Approve | Notification |
|---|---|---|
| L3 | Only for low-risk PRs meeting all criteria | Posts review summary to channel |
| L4 | For low and medium-risk PRs | Posts review summary to channel |
| L5 | For all PRs except security-sensitive | Posts review summary to channel |
At all levels, PRs touching security-sensitive files are never auto-approved.
GitHub Integration
When GITHUB_TOKEN has write access, the Review Agent can post its review directly as a GitHub PR review:
- PR comment — Summary posted as a PR comment
- Inline comments — Suggestions posted on specific lines
- Review status — GitHub review status set (Approve, Request Changes)
Example GitHub Review
The agent posts a review with inline annotations:
Customizing the Review Model
By default, reviews use the REVIEW_MODEL (Claude Sonnet). You can change this:
Examples
Review a specific PR
Review the latest PR
List PRs then review
Check review history
Look for review entries in the activity log.
Troubleshooting
Reviews not triggering automatically
- Verify autonomy is L3+:
@codespar status agent - Check webhook is configured: look at GitHub repo Settings > Webhooks
- Check webhook deliveries in GitHub for errors
- Verify
GITHUB_TOKENhasreposcope
Review quality is poor
- Consider using a more capable model:
REVIEW_MODEL=claude-sonnet-4-20250514 - Ensure the repository has been indexed (check
@codespar context) - For large PRs, the review may be truncated — consider splitting the PR
Reviews not posted to GitHub
- Verify
GITHUB_TOKENhas write access to the repository - Check CodeSpar logs for GitHub API errors
- The review is always posted to the chat channel even if GitHub posting fails
Next Steps
- Deploy Pipeline — Set up deployment orchestration
- Graduated Autonomy — Configure auto-review levels
- Webhook API — How webhook events are processed