Skip to main content
Version: Early Access

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.
important

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

  1. Extract the JAR file from gerrit.war:

    cd /opt/collabnet/gerrit/bin
    mkdir /tmp/unzipped && unzip -q gerrit.war -d /tmp/unzipped
  2. Copy the JAR into your Gerrit plugins directory:

    cd /tmp/unzipped/WEB-INF/plugins
    cp ai-code-review.jar /opt/collabnet/gerrit/plugins/
  3. 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
  4. Verify the installation:

    ssh -p 29418 <username>@<gerrit-host> gerrit plugin ls

    You should see output similar to:

    NameVersionApi-VersionStatusFile
    ai-code-review3.11.03.11.8-cn-next-SNAPSHOTENABLEDai-code-review.jar
  5. Check gerrit.system.log to 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

note

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

KeyDescriptionDefault
gerritUserNameGerrit username used by the plugin to post reviews. Must be a valid account with at least source code view permissions.(required)
globalEnableEnable 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
enabledProjectsComma-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)
isEnabledProject-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

KeyDescriptionDefault
aiTypeCHATGPT | OLLAMA | AZUREOPENAI | GENERICCHATGPT
aiDomainService base URL. Required for OLLAMA and GENERIC.https://api.openai.com
aiChatEndpointCustom chat API path. Used mainly with GENERIC.(empty)
aiAuthHeaderNameCustom authorization header name. Used mainly with GENERIC or hosted OLLAMA.(empty)
aiTokenToken or API key. For CHATGPT, sent as Authorization: Bearer <token>. For AZUREOPENAI, sent as api-key. For GENERIC/OLLAMA, sent using aiAuthHeaderName.(required)
aiModelModel identifier.gpt-4o (CHATGPT), qwen2.5-coder (OLLAMA)

Behavior

KeyDescriptionDefault
aiReviewPatchSetAutomatically review when a patch set is created or updated.true
aiReviewCommitMessagesCheck commit message consistency with the change.true
gptFullFileReviewInclude unchanged context lines along with diffs.true
aiSystemPromptSystem prompt for the reviewer persona.(empty)
aiReviewTemperatureTemperature when reviewing a patch set.0.2
aiCommentTemperatureTemperature when replying to comments.1.0

Voting and Filtering

KeyDescriptionDefault
enabledVotingAllow the plugin to vote on a patch set.false
votingMinScore / votingMaxScoreBounds for voting.-1 / +1
filterNegativeCommentsOnly show comments below filterCommentsBelowScore.true
filterCommentsBelowScoreMinimum score to show when filterNegativeComments is enabled.0
filterRelevantCommentsOnly show comments above the relevance threshold.true
filterCommentsRelevanceThresholdRelevance threshold.0.6

Scope Control

KeyDescriptionDefault
enabledProjectsComma-separated repo list used when globalEnable=false.(empty)
enabledUsers / disabledUsersComma-separated usernames to include or exclude.ALL / (empty)
enabledGroups / disabledGroupsComma-separated group names to include or exclude.ALL / (empty)
enabledTopicFilter / disabledTopicFilterKeywords to include or exclude by change topic.ALL / (empty)
enabledFileExtensionsFile 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

KeyDescriptionDefault
maxReviewLinesMax number of lines considered across files.1000
maxReviewFileSizeMax file size considered.10000
inlineCommentsAsResolvedMark inline AI comments as resolved.false
patchSetCommentsAsResolvedMark patch-set-level AI comments as resolved.false
ignoreOutdatedInlineCommentsIgnore inline comments on non-latest patch sets.false
ignoreResolvedChatGptCommentsIgnore 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.