An automated code review service that integrates with GitHub webhooks to provide AI-powered code reviews on pull requests. The service uses Ollama for AI analysis and performs static code analysis to generate comprehensive review comments.
- š¤ AI-Powered Code Reviews: Uses Ollama (default: qwen2.5-coder:7b) to analyze code and generate intelligent review comments
- š Static Code Analysis: Integrates ESLint and Flake8 for automated code quality checks
- š GitHub Webhook Integration: Automatically processes pull request events via GitHub webhooks
- š GitHub App Authentication: Secure authentication using GitHub App credentials
- š Smee Integration: Local development support with Smee for webhook forwarding
- š Automated PR Comments: Posts review comments directly to GitHub pull requests
- š ļø TypeScript: Fully typed with TypeScript for better developer experience
- Node.js 20 or higher
- npm or yarn
- GitHub App with the following permissions:
- Repository access (read/write)
- Pull requests (read/write)
- Contents (read)
- Ollama installed and running (for AI code reviews)
- Default model:
qwen2.5-coder:7b - Default URL:
http://localhost:11434
- Default model:
- Clone the repository:
git clone <repository-url> cd charliecodereviewer
- Install dependencies:
npm install
- Create a
.envfile in the root directory:
cp .env.example .env
-
Configure environment variables (see Configuration section below)
-
Build the project:
npm run build
Create a .env file in the project root with the following variables:
GITHUB_APP_ID: Your GitHub App ID (numeric)GITHUB_APP_PRIVATE_KEY_PATH: Path to your GitHub App private key file (PEM format)
GITHUB_WEBHOOK_SECRET: Secret for webhook signature verification (recommended for production)OLLAMA_URL: Ollama API URL (default:http://localhost:11434)AI_MODEL: AI model to use for code reviews (default:qwen2.5-coder:7b)AI_MAX_COMMENTS: Maximum number of review comments per file (default:10)SMEE_URL: Smee channel URL for local development (e.g.,https://smee.io/your-channel-id)PORT: Server port (default:3000)
GITHUB_APP_ID=123456 GITHUB_APP_PRIVATE_KEY_PATH=./private-key.pem GITHUB_WEBHOOK_SECRET=your-webhook-secret OLLAMA_URL=http://localhost:11434 AI_MODEL=qwen2.5-coder:7b AI_MAX_COMMENTS=10 SMEE_URL=https://smee.io/your-channel-id PORT=3000
-
Create a GitHub App:
- Go to your organization or personal account settings
- Navigate to Developer settings ā GitHub Apps ā New GitHub App
- Fill in the basic information (name, description, homepage URL)
-
Set Permissions:
- Repository permissions:
- Contents: Read
- Pull requests: Read & Write
- Metadata: Read-only
- Subscribe to events:
- ā Pull request
- Repository permissions:
-
Configure Webhook:
- For Local Development (using Smee):
- Set Webhook URL to your Smee channel URL (e.g.,
https://smee.io/your-channel-id) - See Local Development with Smee section for detailed instructions
- Set Webhook URL to your Smee channel URL (e.g.,
- For Production:
- Set Webhook URL to your production server endpoint (e.g.,
https://your-domain.com/webhooks/github) - Set Webhook secret (use the same value as
GITHUB_WEBHOOK_SECRETin your.env)
- Set Webhook URL to your production server endpoint (e.g.,
- For Local Development (using Smee):
-
Save and Install:
- Click "Create GitHub App" or "Update" if editing existing app
- Download the private key and save it to a file (e.g.,
private-key.pem) - Note your App ID from the GitHub App settings page
- Install the app on repositories or organizations where you want code reviews
Run the server in development mode with hot reload:
npm run dev
The server will start on http://localhost:3000 (or your configured PORT).
- Build the project:
npm run build
- Start the server:
npm start
For local development, you can use Smee to forward webhooks from GitHub to your local server:
-
Create a Smee channel:
- Go to https://smee.io
- Click "Start a new channel" or use an existing channel
- Copy the channel URL (e.g.,
https://smee.io/your-channel-id)
-
Configure your
.envfile:- Add the Smee channel URL to your
.envfile:SMEE_URL=https://smee.io/your-channel-id
- Add the Smee channel URL to your
-
Configure GitHub App Webhook:
- Go to your GitHub App settings (Settings ā Developer settings ā GitHub Apps ā Your App)
- Navigate to the "Webhook" section
- Set the Webhook URL to your Smee channel URL (the same URL from step 1)
- Set the Webhook secret (optional, but recommended) - use the same value as
GITHUB_WEBHOOK_SECRETin your.envif you set one - Under "Which events would you like to trigger this webhook?", select:
- ā Pull request (required)
- Click "Update webhook" or "Save changes"
-
Start the server:
npm run dev
The server will automatically:
- Connect to the Smee channel
- Forward webhooks from Smee to
http://localhost:3000/webhooks/github - Process incoming GitHub webhook events
-
Verify the connection:
- Check Smee connection status:
GET http://localhost:3000/smee/status - The response should show
status: "connected" - Test by creating a pull request in a repository where your GitHub App is installed
- Check Smee connection status:
Note: The Smee client automatically forwards all webhooks from your Smee channel to the local endpoint. Make sure your local server is running before webhooks are sent, or they will be lost.
GET /health- Returns server status
GET /smee/status- Returns Smee connection statusGET /smee/refresh- Refreshes Smee connection state
GET /webhooks/github- Webhook endpoint statusPOST /webhooks/github- Receives GitHub webhook eventsPOST /webhooks/github/test- Test endpoint for webhook verification
POST /api/webhook/receive- Generic webhook receiverPOST /api/webhook/verify- Webhook signature verification
- Webhook Reception: The server receives GitHub webhook events, particularly
pull_requestevents - Event Processing: When a pull request is opened or updated, the service:
- Fetches the pull request details and file changes
- Clones the repository to a temporary directory
- Analyzes each changed file
- Code Analysis:
- Static Analysis: Runs ESLint (for JavaScript/TypeScript) and Flake8 (for Python)
- AI Analysis: Sends code to Ollama for intelligent code review
- Comment Generation: Combines static analysis results with AI insights to generate review comments
- GitHub Integration: Posts comments directly to the pull request using GitHub API
charliecodereviewer/
āāā src/
ā āāā controllers/ # Request controllers
ā ā āāā smee-webhook.controller.ts
ā ā āāā webhook.controller.ts
ā āāā models/ # Data models and types
ā ā āāā github.model.ts
ā ā āāā webhook.model.ts
ā āāā routes/ # Express routes
ā ā āāā webhook.routes.ts
ā āāā services/ # Business logic services
ā ā āāā ai-review.service.ts # AI code review service
ā ā āāā github-api.service.ts # GitHub API integration
ā ā āāā github-webhook.service.ts # Webhook processing
ā ā āāā smee.service.ts # Smee client
ā ā āāā static-analysis.service.ts # Static code analysis
ā ā āāā webhook-verification.service.ts
ā ā āāā webhook.service.ts
ā āāā example-usage.ts # Example usage documentation
ā āāā server.ts # Express server setup
āāā .github/
ā āāā workflows/ # GitHub Actions workflows
ā āāā ci.yml
ā āāā codeql-analysis.yml
ā āāā dependency-review.yml
āāā package.json
āāā tsconfig.json
āāā README.md
Run TypeScript type checking without building:
npm run type-check
npm run dev- Start development server with hot reloadnpm run build- Build TypeScript to JavaScriptnpm start- Start production servernpm run type-check- Run TypeScript type checking
The project includes GitHub Actions workflows for:
- CI: Type checking and building on push/PR
- CodeQL Analysis: Security vulnerability scanning
- Dependency Review: Dependency security review
-
Check GitHub App Webhook Configuration:
- Verify the webhook URL in GitHub App settings matches your Smee channel URL (for local dev) or production URL
- Ensure "Pull request" event is selected
- Check webhook delivery logs in GitHub App settings to see if events are being sent
-
Verify Smee Connection (for local development):
- Check Smee connection status:
GET http://localhost:3000/smee/status - The response should show
status: "connected"andconnected: true - If disconnected, try refreshing:
GET http://localhost:3000/smee/refresh - Verify
SMEE_URLin.envmatches your Smee channel URL exactly
- Check Smee connection status:
-
Check Server Logs:
- Look for "Received webhook request" messages in server logs
- Check for any error messages related to webhook processing
-
Test Webhook Endpoint:
- Test the endpoint directly:
POST http://localhost:3000/webhooks/github/test - This verifies the endpoint is accessible
- Test the endpoint directly:
- Ensure Ollama is running:
curl http://localhost:11434/api/tags - Verify the model is installed:
ollama list - Check
OLLAMA_URLandAI_MODELenvironment variables
- Verify
GITHUB_APP_IDis correct - Check that
GITHUB_APP_PRIVATE_KEY_PATHpoints to a valid PEM file - Ensure the private key file is readable and in correct format
- Verify the GitHub App has necessary permissions
ISC
Contributions are welcome! Please feel free to submit a Pull Request.