Skip to content

Your personal code reviewer powered by LLMs (OpenAI GPT-3.5/4, Llama, Falcon, Azure AI) & Embeddings ⚑️ Improve code quality and catch bugs before you break production πŸš€

License

Notifications You must be signed in to change notification settings

tomchapin/code-review-gpt

Β 
Β 

Repository files navigation

Code Review GPT

NPM Contributors Pulse License Twitter

We give engineers their weekends back

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.

Demo

code-review-gpt-3.mp4

Prerequisites

  • Node.js
  • Git
  • Github or Gitlab CLI (optional for configure tool)

Easy Setup in CI πŸš€

In the root of your git repository run:

Github Actions

npm install code-review-gpt
npx code-review-gpt configure --setupTarget=github

Gitlab CI

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.

Local Usage 🌈

Code Review GPT works locally to review files staged for commit:

Scoped Install

Run npm i code-review-gpt && npx code-review-gpt review in the root directory of a git repository.

Global Install

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.

Commands

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

Options

  • --ci - Used with the review 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 the configure 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 to gpt-4. You can use any openai model you have access to.

  • --debug - Runs the application in debug mode. This will enable debug logging.

Getting Started Contributing πŸ’«

  1. Clone the repository:

    git clone https://github.com/mattzcarey/code-review-gpt.git
    cd code-review-gpt
  2. Install dependencies:

    npm install
  3. 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.

  1. Run the application:

    npm start

See the package.json file for all the npm commands you can run.

  1. Make a package release πŸŽ‰

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.

Roadmap (see projects tab) 🌏

Sponsors ❀️

quivr logo aleios logo

Star History ⭐️

Star History Chart

About

Your personal code reviewer powered by LLMs (OpenAI GPT-3.5/4, Llama, Falcon, Azure AI) & Embeddings ⚑️ Improve code quality and catch bugs before you break production πŸš€

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 96.8%
  • JavaScript 2.7%
  • CSS 0.5%