This is a fork of https://github.com/mattzcarey/code-review-gpt specially tuned to work in gitlab ci environment.
It starts discussions the same way as a human code reviewer would do:
It focuses on:
- Adding first-class support for GitLab
- Saving the cost of calls to open.ai model
- Providing users with complete feedback (including information about the files that were not reviewed for any reason)
- Ensuring all the files where review is possible were reviewed
- It does not spend your money to repeat the model calls if the model answered and the answer was not parserable
- It does not spend your money to add a funcy emoji to the feedback summary
- It shows all feedback (not just the three randomly selected comments, as in the original project)
- When one file can't be parsed by the model, it is no longer a reason to skip all the other files from the same bunch
- This fork works when Gitlab runners are not at the same machine where the Gitlab is (it does not work in the original version)
- It supports projects with more than one programming language
- It adds feedback to the files that were too large for sending to the GPT model or were too complicated for the model to understand
- For GitLab, it adds first class review the same way as humans would (via discussion placed using the correct line locations inside the merge request's changes)
To use it with Gitlab CI:
- Create an access token in your gitlab project with "api" permission and at least maintainer level. Copy it.
- Create a variable in Gitlab CI/CD named GITLAB_TOKEN containg the access token.
- Create a variable in Gitlab CI/CD named OPENAI_API_KEY and copy your access token for https://openai.com/ to its value.
- Add following snippet to your .gitlab-ci.yml
gpt-review:
image: scdcompany/code-review-gpt
stage: review
script:
- mv /code-review-gpt $CI_PROJECT_DIR/
- cd ./code-review-gpt && npm run gitlab3
only:
- merge_requests
when: manual
Replace "npm run gitlab3" with "npm run gitlab4" to use GPT4 (note that it is 10 times more expensive)
Original readme follows:
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
See the package documentation for more information.
See the action documentation for more information.
-
Clone the repository:
git clone https://github.com/mattzcarey/code-review-gpt.git cd code-review-gpt && 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!