An automated GitHub webhook handler that triggers AI code reviews when bots open pull requests. Built for Val Town deployment.
The PR Bot Reviewer automatically detects when a bot opens a pull request and posts a standardized comment to trigger multiple AI code review services. This ensures consistent code quality checks for automated PRs without manual intervention.
Set the required environment variable in your Val Town project:
GITHUB_TOKEN=your_github_personal_access_token_here
GitHub Token Requirements:
repo scope for posting comments on pull requestswebhook-handler.http.ts into your ValGITHUB_TOKEN environment variablehttps://[username]-[valname].web.val.runapplication/jsongraph LR A[Bot opens PR] --> B[GitHub Webhook] B --> C[Val Town Handler] C --> D{Is Bot User?} D -->|Yes| E[Post Review Comment] D -->|No| F[Skip Processing] E --> G[AI Reviews Triggered]
The system identifies bot users using two criteria:
type: "Bot" in GitHub API[bot] (e.g., dependabot[bot])When a bot PR is detected, the following review triggers are posted:
@coderabbitai review
/gemini review
@cubic-dev-ai review
@greptile review
| Variable | Description | Required | Example |
|---|---|---|---|
GITHUB_TOKEN | GitHub Personal Access Token with repo scope | ā | ghp_xxxxxxxxxxxx |
repo (Full control of private repositories)The handler expects GitHub webhook payloads with the following structure:
interface WebhookPayload {
action: string; // Must be "opened"
number: number; // PR number
pull_request: {
user: {
login: string; // GitHub username
type: string; // User type ("Bot" or "User")
id: number; // User ID
};
};
repository: {
full_name: string; // Repository name (owner/repo)
};
}
Success Response (200):
{ "success": true, "message": "Review comment posted successfully for bot PR #123 by dependabot[bot]", "timestamp": "2024-01-01T12:00:00.000Z" }
Error Response (4xx/5xx):
{ "error": "ERROR_CODE", "message": "Human readable error message", "timestamp": "2024-01-01T12:00:00.000Z" }
The system provides comprehensive error handling for various scenarios:
| Code | Status | Description | Solution |
|---|---|---|---|
MISSING_GITHUB_TOKEN | 500 | GitHub token not configured | Set GITHUB_TOKEN environment variable |
GITHUB_AUTH_FAILED | 401 | Invalid GitHub token | Check token validity and permissions |
GITHUB_RATE_LIMIT | 429 | API rate limit exceeded | Wait and retry, consider token limits |
INVALID_PAYLOAD_TYPE | 400 | Malformed webhook payload | Check webhook configuration |
METHOD_NOT_ALLOWED | 405 | Non-POST request received | Ensure webhook sends POST requests |
Webhook not triggering:
Authentication errors:
GITHUB_TOKEN is set correctlyrepo scopeComments not posting:
āāā webhook-handler.http.ts # Main webhook handler (Val Town entry point)
āāā README.md # This documentation
āāā .kiro/specs/ # Feature specifications
āāā pr-bot-reviewer/
āāā requirements.md # Feature requirements
āāā design.md # Technical design
āāā tasks.md # Implementation tasks
The project includes comprehensive test coverage:
GITHUB_TOKEN in Val settingsDeno.env.get() for environment variablesrepo scope)The system provides detailed logging for troubleshooting:
// Example log output
{
"error": "GitHub API authentication failed",
"timestamp": "2024-01-01T12:00:00.000Z",
"url": "https://api.github.com/repos/owner/repo/issues/123/comments",
"status": 401
}
Monitor these indicators for system health:
This project is open source and available under the MIT License.
For issues and questions: