Back to Articles

Automating Code Reviews with GitHub Webhooks and Google Gemini

Build an automated AI code reviewer that intercepts GitHub pull requests via webhooks, analyzes diffs with Google Gemini, and posts inline review comments.

Automating Code Reviews with GitHub Webhooks and Google Gemini

Code reviews are critical but time-consuming. We built a bot that reviews every PR automatically using Google Gemini API.


1. Webhook Setup

Register a GitHub webhook that fires on pull_request events. Our Express server validates the signature and processes the diff:

typescript
app.post('/webhook', async (req, res) => { const isValid = verifyGitHubSignature(req); if (!isValid) return res.status(401).send('Invalid signature'); const { action, pull_request } = req.body; if (action === 'opened' || action === 'synchronize') { await reviewPullRequest(pull_request); } res.status(200).send('OK'); });

2. Diff Analysis with Gemini

We fetch the PR diff, chunk it by file, and send each chunk to Gemini with a system prompt focused on security, performance, and code style.


3. Posting Review Comments

The bot posts inline comments on specific lines using the GitHub Checks API, making feedback contextual and actionable.


Summary

Automated AI reviews catch 60% of common issues before human reviewers even start, dramatically reducing review cycle times.