• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
ianvph

ianvph

pr-reviewer

Public
Like
2
pr-reviewer
Home
Code
10
README.md
claude.ts
H
debug.ts
example-env.md
github.ts
H
index.ts
main.ts
H
test.ts
utils.ts
H
webhook-test.ts
Branches
1
Pull requests
Remixes
1
History
Environment variables
3
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
README.md
Code
/
README.md
Search
11/20/2025
Viewing readonly version of main branch: v25
View latest version
README.md

Code Review Bot πŸ€–

An intelligent GitHub code review bot built for Val Town that automatically analyzes pull requests using Claude AI and posts detailed review comments.

✨ Features

  • Automatic PR Analysis: Responds to GitHub pull request webhooks instantly
  • AI-Powered Reviews: Uses Anthropic's Claude 3.5 Sonnet for intelligent code analysis
  • Secure Integration: Webhook signature verification for security
  • Smart File Filtering: Only reviews code files, skips documentation and config files
  • Detailed Feedback: Provides structured reviews covering code quality, security, and best practices
  • Easy Setup: Simple configuration with environment variables
  • Debug Tools: Built-in endpoints to test API connections and troubleshoot issues

πŸš€ Quick Start

  1. Fork/Copy this project to your Val Town account
  2. Set environment variables (see setup section below)
  3. Configure GitHub webhook in your repository
  4. Create a test PR and watch the magic happen!

πŸ“‹ What You Get

When someone opens a pull request, the bot will:

  1. πŸ”„ Post an initial "review in progress" comment
  2. πŸ“ Fetch and analyze changed code files (up to 8 files)
  3. 🧠 Generate a comprehensive review using Claude AI
  4. πŸ’¬ Post a structured review comment with:
    • Summary of changes
    • Code strengths and good practices
    • Issues found with specific file references
    • Improvement suggestions
    • Security and best practice notes

Setup

1. Get Required API Keys

GitHub Token: Create a fine-grained personal access token at https://github.com/settings/personal-access-tokens/new with:

  • Repository access: Select the specific repository you want to review
  • Permissions > Repository permissions:
    • Metadata: Read-only (required)
    • Contents: Read-only (required to fetch file contents)
    • Pull requests: Read and write (required to post review comments)

Anthropic API Key: Get your API key from Anthropic Console

2. Configure Environment Variables

In Val Town, set these environment variables:

  • GITHUB_TOKEN: Your GitHub personal access token
  • ANTHROPIC_API_KEY: Your Anthropic API key
  • WEBHOOK_SECRET: A random secret string (generate with: openssl rand -hex 32)

3. Get Your Webhook URL

Your webhook URL will be: https://[your-username]--[val-id].web.val.run/webhook

You can find this URL by:

  1. Opening your index.ts val in Val Town
  2. Looking at the URL in your browser
  3. Adding /webhook to the end

Example: If your val URL is https://alice--abc123.web.val.run, your webhook URL is https://alice--abc123.web.val.run/webhook

4. Test Your Configuration (Optional but Recommended)

Before setting up the webhook, test your API connections:

  1. Open your debug val: https://[your-username]--[debug-val-id].web.val.run
  2. Check that all environment variables show "βœ… Set"
  3. Test GitHub API: Visit /test-github endpoint
  4. Test Claude API: Visit /test-claude endpoint

All tests should return "success": true.

5. Configure GitHub Webhook

In your GitHub repository:

  1. Go to Settings > Webhooks > Add webhook
  2. Set Payload URL: Your Val Town webhook URL (from step 3)
  3. Set Content type: application/json
  4. Set Secret: Same value as your WEBHOOK_SECRET environment variable
  5. Select Let me select individual events β†’ Check Pull requests
  6. Ensure Active is checked
  7. Click Add webhook

6. Test the Setup

Create a test pull request in your repository. The bot should:

  1. Post an initial "review in progress" comment
  2. Analyze the changed files
  3. Post a detailed review comment within 30-60 seconds

Usage

The bot automatically reviews pull requests when they are opened or reopened. It will:

  1. Fetch the changed files from the PR
  2. Analyze the code using Claude
  3. Post a review comment with findings

πŸ“ Project Structure

β”œβ”€β”€ index.ts              # Main webhook handler (HTTP endpoint)
β”œβ”€β”€ github.ts             # GitHub API integration and PR processing
β”œβ”€β”€ claude.ts             # Claude AI integration for code analysis
β”œβ”€β”€ utils.ts              # Utility functions (webhook verification, file filtering)
β”œβ”€β”€ debug.ts              # Debug endpoints for testing API connections
β”œβ”€β”€ test.ts               # Webhook signature verification tests
β”œβ”€β”€ webhook-test.ts       # Mock webhook payload testing
β”œβ”€β”€ example-env.md        # Environment variable setup guide
└── README.md            # This file

Key Components

  • Webhook Handler (index.ts): Receives GitHub webhooks, verifies signatures, and triggers reviews
  • GitHub Integration (github.ts): Fetches PR data, file contents, and posts review comments
  • AI Analysis (claude.ts): Generates intelligent code reviews using Claude 3.5 Sonnet
  • Security (utils.ts): HMAC-SHA256 webhook signature verification
  • Debug Tools (debug.ts): Test API connections and troubleshoot configuration issues

Troubleshooting

Bot Not Responding

  1. Check that your webhook URL is correct in GitHub settings
  2. Verify all environment variables are set in Val Town
  3. Check the webhook delivery logs in GitHub (Settings > Webhooks > Recent Deliveries)
  4. Look at the Val Town logs for error messages

Authentication Errors

  • Ensure your GitHub token has the correct permissions
  • Verify the token hasn't expired
  • Check that the repository is accessible with your token

Review Quality Issues

  • The bot analyzes up to 10 files per PR to stay within API limits
  • Only code files are reviewed (JS, TS, Python, etc.)
  • Very large files are truncated to prevent token limit issues

Webhook Signature Errors

  • Ensure the WEBHOOK_SECRET in Val Town matches the secret in GitHub
  • Check that the webhook is configured to send JSON payloads

Limitations

  • Reviews up to 10 files per PR
  • File content is truncated to 2000 characters for analysis
  • Only reviews code files (filters out documentation, images, etc.)
  • Requires internet access to GitHub and Anthropic APIs
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.