Code Review GPT uses Large Language Models to review code in your CI/CD pipeline. It helps streamline the code review process by providing feedback on code that may have issues or areas for improvement.
It should pick up on common issues such as:
- Exposed secrets
- Slow or inefficient code
- Unreadable code
It can also be run locally in your command line to review staged files.
Code Review GPT is in alpha and should be used for fun only. It may provide useful feedback but please check any suggestions thoroughly.
code-review-gpt-3.mp4
- Node.js
- Git
- Github or Gitlab CLI (optional for configure tool)
In the root of your git repository run:
npm install code-review-gpt
npx code-review-gpt configure --setupTarget=github
If you are running this tool in Gitlab, you will need to do some additional setup. You will need to create a access token in Gitlab and store it in your CI/CD variables to allow the bot access to you Gitlab account. Follow the steps below.
- Log in to your GitLab account.
- Go to your Repo settings by clicking on the repository, and selecting Settings -> Access Tokens.
- In this section, you can generate a new access token.
- Name your token something relevant and understandable ie.
CODE_REVIEW-GPT-TOKEN
. Set the scope to beapi
only. - Click the "Create personal access token" button. GitLab will generate the token and display it to you once. Make sure to copy this value, we are going to use it in the next step.
-
Navigate to the project where you want to add the code review bot.
-
In the left sidebar, click the Settings drop down, then click CI/CD
-
Scroll down to the Variables section and click the Expand button.This is where you can manage your CI/CD variables.
-
Create a new variable by clicking the Add Variable button in the CI/CD Variable table.
-
Paste your previously copied access token into the Value box. Name the variable
GITLAB_TOKEN
. Under the Flags section, make sure to tick theMask variable
option.- [Un-tick the
Protect variable
if your branches are not protected, otherwise this variable won't be availiable for the bot to use.]
- [Un-tick the
-
Save you changes. Now you can go ahead and run the following commands in you project directory.
npm install code-review-gpt
npx code-review-gpt configure --setupTarget=gitlab
See templates for example yaml files. Copy and paste them to perform a manual setup.
Code Review GPT works locally to review files staged for commit:
Run npm i code-review-gpt && npx code-review-gpt review
in the root directory of a git repository.
Run npm i -g code-review-gpt
to install the tool globally.
You can now run code-review-gpt review
in the root directory of any git-enabled repository on your machine.
-
code-review-gpt review
- Runs the code review on the staged files. -
code-review-gpt configure
- Runs a setup tool to configure the application. -
code-review-gpt test
- Runs the e2e testing suite used internally in the CI in the tool repo.
-
--ci
- Used with thereview
command. Options are --ci=("github" | "gitlab"). Defaults to "github" if no option is specified. Runs the application in CI mode. This will use the BASE_SHA and GITHUB_SHA environment variables to determine which files to review. It will also use the GITHUB_TOKEN environment variable to create a comment on the pull request with the review results. -
--reviewType
- Used with the 'review' command. The options are --reviewType=("changed" | "full" | "costOptimized). Defaults to "changed" if no option is specified. Specifies whether the review is for the full file or just the changed lines. costOptimized limits the context surrounding the changed lines to 5 lines. -
--commentPerFile
- Used when the--ci
flag is set. Defaults to false. It enables the bot to comment the feedback on a file-by-file basis. -
--setupTarget
- Used with theconfigure
command. Options are --setupTarget=("github" | "gitlab"). Defaults to "github" if no option is specified. Specifies for which platform ('github' or 'gitlab') the project should be configured for. -
--model
- The model to use for the review. Defaults togpt-4
. You can use any openai model you have access to. -
--debug
- Runs the application in debug mode. This will enable debug logging.
-
Clone the repository:
git clone https://github.com/mattzcarey/code-review-gpt.git cd code-review-gpt
-
Install dependencies:
npm install
-
Set up the API key:
- Rename the .env.example file to .env.
- Open the .env file and replace YOUR_API_KEY with your actual OPENAI API key.
When used globally you should run export OPENAI_API_KEY=YOUR_API_KEY
(or similar for your operating system) in your terminal to set the API key.
-
Run the application:
npm start
See the package.json file for all the npm commands you can run.
- Make a PR ๐
We use release-please on this project. If you want to create a new release from your PR, please make sure your PR title follows the Conventional Commits format. The release-please bot will automatically create a new release for you when your PR is merged.
- fix: which represents bug fixes, and correlates to a patch version.
- feat: which represents a new feature, and correlates to a SemVer minor.
- feat!:, or fix!:, refactor!:, etc., which represent a breaking change (indicated by the !) and will result in a major version.
Thanks to our wonderful contributors!
![quivr logo](https://private-user-images.githubusercontent.com/77928207/253061129-30361248-3159-4535-8efb-b114989ae886.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM2NzIzNzMsIm5iZiI6MTcyMzY3MjA3MywicGF0aCI6Ii83NzkyODIwNy8yNTMwNjExMjktMzAzNjEyNDgtMzE1OS00NTM1LThlZmItYjExNDk4OWFlODg2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE0VDIxNDc1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWJiY2E5N2E5MTk4MWU5ZWNmN2JlYTgzZGIxOTdlZGRlNjBmOTRmMzVhZTc3Y2Y4OTNhMDkxMzdhNTBiMDczZGMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.tQcXsxRCoXfhzHmDsnenU9sa6nRAXgA_dbKu5WwQypk)
![aleios logo](https://private-user-images.githubusercontent.com/77928207/253060489-a47c2460-b866-433f-a4c9-efb5737d4fed.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjM2NzIzNzMsIm5iZiI6MTcyMzY3MjA3MywicGF0aCI6Ii83NzkyODIwNy8yNTMwNjA0ODktYTQ3YzI0NjAtYjg2Ni00MzNmLWE0YzktZWZiNTczN2Q0ZmVkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MTQlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODE0VDIxNDc1M1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTU2ZTYyMjQzNTEzY2IwZDU2MjA0Yzk1M2JhNGM0Y2ZlMzBhZGE0YjI2ODhjN2QyNDI3YmYzN2RiZTQzNzQ0MTgmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.TBa2DU1OdNpn8EOkZ-6QxW3cfB8Jz_fBg-eABwlX6LI)