Set up AI Code Review Plugin
The AI Code Review plugin uses a configurable AI provider to automatically review code changes submitted to Gerrit. Once installed, the plugin can post AI-generated review comments on patchsets.
Prerequisites
- TeamForge-Git integration is installed and running.
- A dedicated Gerrit user account must be created for the plugin. This account is used by the plugin to post review comments and votes. It must have at least Read permission on the repositories where AI reviews are enabled. Do not reuse an administrator or personal account for this purpose.
The AI Code Review plugin requires its own Gerrit user account (for example, ai-code-review). This account is referenced by the gerritUserName configuration key and is used to post all AI-generated review comments and votes. Using an administrator or personal account may cause permission conflicts and makes it difficult to distinguish AI feedback from human reviews.
Install the Plugin
-
Extract the JAR file from
gerrit.war:cd /opt/collabnet/gerrit/bin
mkdir /tmp/unzipped && unzip -q gerrit.war -d /tmp/unzipped -
Copy the JAR into your Gerrit plugins directory:
cd /tmp/unzipped/WEB-INF/plugins
cp ai-code-review.jar /opt/collabnet/gerrit/plugins/ -
Restart Gerrit so the plugin is fully activated. It may take a few minutes for Gerrit to detect and load the plugin.
teamforge restart -s gerrit -
Verify the installation:
ssh -p 29418 <username>@<gerrit-host> gerrit plugin lsYou should see output similar to:
Name Version Api-Version Status File ai-code-review 3.11.0 3.11.8-cn-next-SNAPSHOT ENABLED ai-code-review.jar -
Check
gerrit.system.logto confirm the plugin was loaded successfully.
Reload the Plugin
To reload the plugin without restarting Gerrit:
ssh -p 29418 <username>@<gerrit-host> gerrit plugin reload ai-code-review
Configure the Plugin
The plugin is configured in $gerrit_site/etc/gerrit.config under the [plugin "ai-code-review"] section.
Quick Start (ChatGPT / OpenAI-compatible)
[plugin "ai-code-review"]
gerritUserName = ai-code-review
aiType = CHATGPT
aiDomain = https://api.openai.com
aiChatEndpoint = /v1/chat/completions
aiModel = gpt-4o
aiToken = <your-api-token>
globalEnable = true
enabledVoting = true
aiSystemPrompt = You are an experienced senior software engineer reviewing a Gerrit change. Review diffs like a real code review and focus on correctness, design, maintainability, security, performance, and tests. Prefer established patterns and be concise and actionable.
Quick Start (Custom / Generic AI Service)
For non-standard or in-house AI services, set aiType=GENERIC, provide the service domain and endpoint, and set the correct auth header and token format.
[plugin "ai-code-review"]
aiType = GENERIC
aiDomain = https://api.staging.digital.ai
aiChatEndpoint = /llm/chat/completions
aiAuthHeaderName = Authorization
aiToken = Token <your-api-token>
aiModel = anthropic.claude-3-5-sonnet-20241022-v2:0
gerritUserName = ai-code-review
globalEnable = true
enabledVoting = true
Enable per Project
If you do not want to enable reviews globally, you can enable the plugin for an individual repository by editing refs/meta/config:project.config of that repository and appending:
[plugin "ai-code-review"]
isEnabled = true
Configuration Reference
Project-level values override global values. Unless stated otherwise, keys are valid at both global and project scope — this means different AI services can be used for different projects with separate tokens and prompts.
Core
| Key | Description | Default |
|---|---|---|
gerritUserName | Gerrit username used by the plugin to post reviews. Must be a valid account with at least source code view permissions. | (required) |
globalEnable | Enable AI reviews for all repositories. If false, only repositories listed in enabledProjects (or with project-level isEnabled) are reviewed. Set to false by default, meaning the plugin will review only designated repositories. If enabled, the plugin will automatically review all pull requests by default (not recommended in production environments). | false |
enabledProjects | Comma-separated list of repository names used when globalEnable=false. The plugin will only run in the repositories specified here, for example: "project1,project2,project3". | (empty) |
isEnabled | Project-only switch to enable the plugin for a specific repository. If set to true, the plugin will review the Patch Set of this project. | false |
AI Provider Selection
| Key | Description | Default |
|---|---|---|
aiType | CHATGPT | OLLAMA | AZUREOPENAI | GENERIC | CHATGPT |
aiDomain | Service base URL. Required for OLLAMA and GENERIC. | https://api.openai.com |
aiChatEndpoint | Custom chat API path. Used mainly with GENERIC. | (empty) |
aiAuthHeaderName | Custom authorization header name. Used mainly with GENERIC or hosted OLLAMA. | (empty) |
aiToken | Token or API key. For CHATGPT, sent as Authorization: Bearer <token>. For AZUREOPENAI, sent as api-key. For GENERIC/OLLAMA, sent using aiAuthHeaderName. | (required) |
aiModel | Model identifier. | gpt-4o (CHATGPT), qwen2.5-coder (OLLAMA) |
Behavior
| Key | Description | Default |
|---|---|---|
aiReviewPatchSet | Automatically review when a patch set is created or updated. | true |
aiReviewCommitMessages | Check commit message consistency with the change. | true |
gptFullFileReview | Include unchanged context lines along with diffs. | true |
aiSystemPrompt | System prompt for the reviewer persona. | (empty) |
aiReviewTemperature | Temperature when reviewing a patch set. | 0.2 |
aiCommentTemperature | Temperature when replying to comments. | 1.0 |
Voting and Filtering
| Key | Description | Default |
|---|---|---|
enabledVoting | Allow the plugin to vote on a patch set. | false |
votingMinScore / votingMaxScore | Bounds for voting. | -1 / +1 |
filterNegativeComments | Only show comments below filterCommentsBelowScore. | true |
filterCommentsBelowScore | Minimum score to show when filterNegativeComments is enabled. | 0 |
filterRelevantComments | Only show comments above the relevance threshold. | true |
filterCommentsRelevanceThreshold | Relevance threshold. | 0.6 |
Scope Control
| Key | Description | Default |
|---|---|---|
enabledProjects | Comma-separated repo list used when globalEnable=false. | (empty) |
enabledUsers / disabledUsers | Comma-separated usernames to include or exclude. | ALL / (empty) |
enabledGroups / disabledGroups | Comma-separated group names to include or exclude. | ALL / (empty) |
enabledTopicFilter / disabledTopicFilter | Keywords to include or exclude by change topic. | ALL / (empty) |
enabledFileExtensions | File extensions to consider. | .py,.java,.js,.ts,.html,.css,.cs,.cpp,.c,.h,.php,.rb,.swift,.kt,.r,.jl,.go,.scala,.pl,.pm,.rs,.dart,.lua,.sh,.vb,.bat |
Limits and Resolution
| Key | Description | Default |
|---|---|---|
maxReviewLines | Max number of lines considered across files. | 1000 |
maxReviewFileSize | Max file size considered. | 10000 |
inlineCommentsAsResolved | Mark inline AI comments as resolved. | false |
patchSetCommentsAsResolved | Mark patch-set-level AI comments as resolved. | false |
ignoreOutdatedInlineComments | Ignore inline comments on non-latest patch sets. | false |
ignoreResolvedChatGptComments | Ignore previously resolved AI comments to avoid duplicates. | true |
Security Note
It is recommended to store the aiToken in $gerrit_site/etc/secure.config instead of gerrit.config. For example, /opt/collabnet/gerrit/etc/secure.config:
[plugin "ai-code-review"]
aiToken = <your-api-token>
See the Gerrit secure-config plugin for encryption and management options.
More Information
For full details, examples, and extensibility options, see the official AI Code Review plugin documentation on the Gerrit Google Open Source site.