- This plugin allows you to use ChatGPT for code review in Gerrit conveniently. After submitting a patchSet, OpenAI will provide review feedback in the form of comments.
- You can continue to ask ChatGPT by @{gerritUserName} in the comments to further guide it in generating more targeted review comments.
-
Build: Requires JDK 11 or higher, Maven 3.0 or higher.
mvn -U clean package
Alternatively, you can also download the pre-built packages directly from the 'Releases' page on our GitHub repository. On this page, you will find the released versions and can download the corresponding JAR files. Make sure to select the appropriate JAR file that corresponds to the desired version.
-
Install: Upload the compiled jar file to the $gerrit_site/plugins directory, then refer to configuration parameters for settings, and restart Gerrit.
-
Verify: After installing the plugin, you can see the following information in Gerrit's logs:
INFO com.google.gerrit.server.plugins.PluginLoader : Loaded plugin chatgpt-code-review-gerrit-plugin, version 1.0.0
You can also check the status of the chatgpt-code-review-gerrit-plugin on Gerrit's plugin page as Enabled.
You have the option to establish global settings, or independently configure specific projects. If you choose independent configuration, the corresponding project settings will override the global parameters.
To configure these parameters, you need to modify your Gerrit configuration file (gerrit.config
). The file format is
as follows:
[plugin "chatgpt-code-review-gerrit-plugin"]
# Required parameters
gptToken = {gptToken}
gerritAuthBaseUrl = {gerritAuthBaseUrl}
...
# Optional parameters
gptModel = {gptModel}
gptPrompt = {gptPrompt}
...
It is highly recommended to store sensitive information such as gptToken
and gerritPassword
in the secure.config
file. Please edit the file at $gerrit_site/etc/secure.config
and include the following details:
[plugin "chatgpt-code-review-gerrit-plugin"]
gptToken = {gptToken}
gerritPassword = {gerritPassword}
If you wish to encrypt the information within the secure.config
file, you can refer
to: https://gerrit.googlesource.com/plugins/secure-config
To add the following content, please edit the project.config
file in refs/meta/config
:
[plugin "chatgpt-code-review-gerrit-plugin"]
# Required parameters
gerritUserName = {gerritUserName}
gerritAuthBaseUrl = {gerritAuthBaseUrl}
...
# Optional parameters
gptModel = {gptModel}
gptPrompt = {gptPrompt}
...
Please ensure strict control over the access permissions of refs/meta/config
since sensitive information such as
gptToken
and gerritPassword
is configured in the project.config
file within refs/meta/config
.
gptToken
: OpenAI GPT token.gerritAuthBaseUrl
: The URL of your Gerrit instance. Similar to: https://gerrit.local.team/agerritUserName
: Gerrit username.gerritPassword
: Gerrit password.globalEnable
: Default value is false. The plugin will only review specified repositories. If set to true, the plugin will by default review all pull requests.
gptModel
: The default model is gpt-3.5-turbo. You can also configure it to gpt-3.5-turbo-16k, gpt-4 or gpt-4-32k.gptPrompt
: The default prompt is "Act as a Code Review Helper, please review this patch set:". You can modify it to your preferred prompt.gptTemperature
: The default value is 1. What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.patchSetReduction
: The default value is false. If set to true, the plugin will attempt to reduce patch content by compressing redundant blank lines, tabs, import statements, etc., in order to decrease the token count.maxReviewLines
: The default value is 1000. This sets a limit on the number of lines of code included in the review.enabledProjects (for global configuration only)
: The default value is an empty string. If globalEnable is set to false, the plugin will only run in the repositories specified here. The value should be a comma-separated list of repository names, for example: " project1,project2,project3".isEnabled (for project configuration only)
: The default is false. If set to true, the plugin will review the patchSet of this project.
- You can run the unit tests in the project to familiarize yourself with the plugin's source code.
- If you want to individually test the Gerrit API or the ChatGPT API, you can refer to the test cases in CodeReviewPluginIT.
Apache License 2.0