Automated GitLab Merge Request code review powered by Google Gemini AI. This bot analyzes code changes, identifies issues, and posts inline comments directly on your MRs.
- π Intelligent Code Analysis: Focuses on logic errors, security vulnerabilities, crash risks, and performance issues
- π Inline Comments: Posts comments directly on the affected lines
- π Smart Review Strategy: Full review for new MRs, incremental review for updates
- π Approval Notifications: Notifies previous approvers when code changes after approval
- β‘ Real-time Processing: Webhook-driven automation
- Node.js (v14 or higher)
- GitLab account with a project
- Google Gemini API key
- Server with public URL or tunneling solution (ngrok, Cloudflare Tunnel, etc.)
git clone git@github.com:bokri/gitlab-ai-code-reviewer.git
cd gitlab-ai-code-reviewer
npm installCopy the example environment file:
cp .env.example .envEdit .env with your credentials:
# Server Configuration
PORT=5678
# GitLab Configuration
GITLAB_URL=https://gitlab.com
GITLAB_TOKEN=your_gitlab_personal_access_token_here
# Gemini AI Configuration
GEMINI_API_KEY=your_gemini_api_key_here- Go to GitLab β Settings β Access Tokens
- Create a new token with these scopes:
api(full API access)read_apiwrite_repository
- Copy the token to your
.envfile asGITLAB_TOKEN
- Visit Google AI Studio
- Click Get API Key or Create API Key
- Copy the key to your
.envfile asGEMINI_API_KEY
Development mode (with auto-restart):
npm run devProduction mode:
npm startThe server will start on http://localhost:5678 (or your configured PORT).
-
Install ngrok:
brew install ngrok # macOS # or download from https://ngrok.com/download
-
Start ngrok tunnel:
ngrok http 5678
Copy the HTTPS forwarding URL (e.g.,
https://abc123.ngrok.io)
Deploy to your server and note the public URL (e.g., https://your-domain.com)
-
Go to your GitLab project
-
Navigate to Settings β Webhooks
-
Add a new webhook with these settings:
URL:
https://your-public-url/webhook/gitlab- Replace with your ngrok URL or production server URL
- Example:
https://abc123.ngrok.io/webhook/gitlab
Trigger: Select Merge request events
SSL verification: Enable (recommended)
-
Click Add webhook
-
Test the webhook by clicking Test β Merge request events
ai-code-review/
βββ src/
β βββ server.js # Server entry point
β βββ app.js # Express app configuration
β βββ config/
β β βββ index.js # Environment configuration
β βββ ai/
β β βββ gemini.js # Gemini AI integration
β βββ gitlab/
β β βββ api.js # GitLab API client
β β βββ comments.js # Comment posting logic
β β βββ helpers.js # Helper functions
β βββ webhook/
β βββ handler.js # Webhook event processor
βββ .env # Environment variables (not in git)
βββ .env.example # Environment template
βββ package.json
βββ README.md
- Create a new branch in your GitLab project
- Make some code changes
- Create a Merge Request
- The bot should automatically:
- Analyze the code
- Post inline comments on issues found
- Update on subsequent pushes
| Variable | Description | Default | Required |
|---|---|---|---|
PORT |
Server port | 5678 | No |
GITLAB_URL |
GitLab instance URL | https://gitlab.com | Yes |
GITLAB_TOKEN |
GitLab Personal Access Token | - | Yes |
GEMINI_API_KEY |
Google Gemini API key | - | Yes |
The bot uses gemini-2.0-flash by default. You can change this in src/config/index.js.
- Webhook Trigger: GitLab sends a webhook when MR events occur
- Event Filtering: Bot checks if the event involves code changes
- Review Strategy:
- Full Review: For new MRs (analyzes all changes)
- Incremental Review: For updates (analyzes only new changes)
- AI Analysis: Gemini AI reviews the code for:
- Logic errors
- Security vulnerabilities
- Crash risks
- Performance issues
- Comment Posting: Inline comments are posted on specific lines
- Approval Tracking: Notifies previous approvers of new changes
- Check that the webhook URL is publicly accessible
- Verify the webhook is enabled in GitLab settings
- Check server logs for incoming requests
- Verify your GitLab token has the correct permissions
- Check your Gemini API key is valid and has quota
- Ensure
GITLAB_URLmatches your GitLab instance
- Check server logs for errors
- Verify the bot user has permissions to comment on MRs
- Ensure the GitLab token has
apiscope
npm start- Run the server in production modenpm run dev- Run with auto-restart on file changes (requires nodemon)
Contributions are welcome! Please feel free to submit issues or pull requests.
MIT License - see LICENSE file for details