An intelligent GitHub bot that provides AI-powered code reviews and automatically implements suggested changes across your codebase. Built with TypeScript, Express, Octokit SDK, and Gemini.
- Automatically analyzes code changes in new pull requests
- Provides intelligent, context-aware comments that:
- Identifies bugs and logical errors
- Highlights performance issues and inefficiencies
- Uses AI to holistically implement suggested changes across multiple files
- Built as a GitHub App for easy installation in multiple repositories
- Deployable to Google Cloud Run
- Node.js 22 or higher
- A GitHub account
- Google Cloud account (for deployment)
- Gemini API key
- Go to your GitHub account settings > Developer settings > GitHub Apps
- Click "New GitHub App"
- Fill in the required information:
- GitHub App name:
GitHub PR Bot AI
(or any name you prefer) - Homepage URL: Can be a placeholder URL for now
- Webhook URL: Will be updated after deployment
- Webhook secret: Generate a random string and save it
- Permissions:
- Repository permissions:
- Pull requests: Read & Write (to read PR details and post reviews)
- Issues: Read & Write (to post comments and create issues)
- Metadata: Read (to access repository information)
- Contents: Read & Write (to read files and create branches/PRs)
- Account permissions:
- Email addresses: Read (to identify users)
- Repository permissions:
- Subscribe to events:
- Pull request (opened, synchronize, closed)
- Issue comment (created)
- Pull request review comment (created)
- GitHub App name:
- Create the app
- Generate a private key and download it
- Note your GitHub App ID, Client ID, and Client Secret
- Note the username of your GitHub App (visible in the app settings)
- Clone this repository
- Install dependencies:
npm install
- Create a
.env
file based on.env.example
and fill in your GitHub App details, including theGITHUB_BOT_USERNAME
- Start the development server:
npm run dev
For testing webhooks during local development, you have several options:
-
Using smee.io: Proxy webhook events to your local development server:
npm install -g smee-client smee --url https://smee.io/YOUR_UNIQUE_URL --target http://localhost:3000/webhook
Then update your GitHub App's webhook URL to use the smee.io URL.
-
ngrok: Expose your local server to the internet:
ngrok http 3000
Use the generated ngrok URL as your webhook URL in GitHub App settings.
-
Online Testing Tools:
- HookBox: Real-time webhook debugging
- Webhook.site: Capture and inspect HTTP requests
- Webhook Tester: Test endpoints with custom requests
- Install the Google Cloud CLI
- Authenticate with Google Cloud:
gcloud auth login
- Set your project:
gcloud config set project YOUR_PROJECT_ID
- Build and deploy the container:
# Build the container image gcloud builds submit --tag gcr.io/YOUR_PROJECT_ID/github-pr-bot gcloud run deploy github-pr-bot --image gcr.io/YOUR_PROJECT_ID/github-pr-bot --platform managed
- Set environment variables in Google Cloud Run:
- Go to the Cloud Run service in Google Cloud Console
- Click "Edit & Deploy New Revision"
- Under "Variables & Secrets", add all environment variables from your
.env
file - Deploy the new revision
- Vercel: Deploy using
vercel
CLI - Railway: Connect your GitHub repo and deploy
- Heroku: Use
heroku create
andgit push heroku main
- AWS Lambda: Use the Serverless Framework or AWS SAM
- Get the URL of your deployed Cloud Run service
- Update your GitHub App settings with this URL as the Webhook URL (append
/webhook
to the URL) - Make sure the webhook secret matches what you set in your environment variables
After deployment, test your webhook integration:
- Verify Deliveries: Check webhook deliveries in your GitHub App settings under "Advanced" → "Recent Deliveries"
- Redeliver Webhooks: Use GitHub's interface to redeliver previous webhook events for testing
- View Payload: Inspect the actual payload data sent by GitHub
For comprehensive webhook testing guidance, refer to the GitHub Webhooks Testing Documentation.
- Go to your GitHub App's page
- Click "Install App" in the sidebar
- Choose the repositories where you want to install the bot
- The bot will now provide AI-powered code reviews on all new pull requests in those repositories
The bot automatically analyzes new pull requests and provides detailed code reviews as comments, focusing on errors and performance issues.
When the AI review suggests code changes, you can have the bot automatically implement them:
- After receiving an AI review comment
- Comment on the PR with
/apply-suggestions
or/create-pr-from-suggestions
- The bot will:
- Send the entire review and all relevant files to Gemini
- AI analyzes the review holistically and generates updated file contents
- Create a new branch based on your PR branch
- Apply all suggested changes across multiple files
- Create a new PR targeting your original PR branch
- Comment with a link to the new PR
- Check URL: Ensure webhook URL ends with
/webhook
- Verify Secret: Webhook secret must match environment variable
- Test Delivery: Use GitHub's webhook delivery testing
- Check Logs: Review application logs for errors
- API Key: Verify
GOOGLE_GENERATIVE_AI_API_KEY
is correct and has quota - Rate Limits: Check if you're hitting Gemini API limits
- File Size: Large files may timeout - consider implementing chunking
- App Permissions: Ensure GitHub App has required permissions
- Installation: Verify app is installed on target repositories
- Token Scope: Check if the generated token has proper scopes
- Environment Variables: Ensure all required variables are set
- Memory Limits: Increase memory allocation if experiencing OOM errors
- Cold Starts: Consider using minimum instances for better response times
MIT