Home

Awesome

CodeReview BOT

A code review robot powered by ChatGPT

Translation Versions: ENGLISH | 简体中文 | 繁體中文 | 한국어 | 日本語

Bot Usage

❗️⚠️ Due to cost considerations, BOT is only used for testing purposes and is currently deployed on AWS Lambda with ratelimit restrictions. Therefore, unstable situations are completely normal. It is recommended to deploy an app by yourself.

Install

Install: apps/cr-gpt;

Configuration

  1. Go to the repo homepage which you want integrate this bot
  2. click settings
  3. click actions under secrets and variables
  4. Change to Variables tab, create a new variable OPENAI_API_KEY with the value of your open api key (For Github Action integration, set it in secrets) <img width="1465" alt="image" src="https://user-images.githubusercontent.com/13167934/218533628-3974b70f-c423-44b0-b096-d1ec2ace85ea.png">

Start using

  1. The robot will automatically do the code review when you create a new Pull request, the review information will show in the pr timeline / file changes part.
  2. After git push update the pull request, cr bot will re-review the changed files

example:

ChatGPT-CodeReview/pull/21

<img width="1052" alt="image" src="https://user-images.githubusercontent.com/13167934/218999459-812206e1-d8d2-4900-8ce8-19b5b6e1f5cb.png">

Using Github Actions

actions/chatgpt-codereviewer

  1. add the OPENAI_API_KEY to your github actions secrets
  2. create .github/workflows/cr.yml add bellow content
name: Code Review

permissions:
  contents: read
  pull-requests: write

on:
  pull_request:
    types: [opened, reopened, synchronize]

jobs:
  test:
    # if: ${{ contains(github.event.*.labels.*.name, 'gpt review') }} # Optional; to run only when a label is attached
    runs-on: ubuntu-latest
    steps:
      - uses: anc95/ChatGPT-CodeReview@main
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
          OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
          # Optional
          LANGUAGE: Chinese
          OPENAI_API_ENDPOINT: https://api.openai.com/v1
          MODEL: gpt-3.5-turbo # https://platform.openai.com/docs/models
          PROMPT: # example: Please check if there are any confusions or irregularities in the following code diff:
          top_p: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-top_p
          temperature: 1 # https://platform.openai.com/docs/api-reference/chat/create#chat/create-temperature
          max_tokens: 10000
          MAX_PATCH_LENGTH: 10000 # if the patch/diff length is large than MAX_PATCH_LENGTH, will be ignored and won't review. By default, with no MAX_PATCH_LENGTH set, there is also no limit for the patch/diff length.
          IGNORE_PATTERNS: /node_modules/**/*,*.md # glob pattern or regex pattern to ignore files, separated by comma
          INCLUDE_PATTERNS: *.js,*.ts # glob pattern or regex pattern to include files, separated by comma

          # IF you are using azure openai
          AZURE_API_VERSION: xx
          AZURE_DEPLOYMENT: xx

Self-hosting

  1. clone code
  2. copy .env.example to .env, and fill the env variables
  3. install deps and run
npm i
npm i -g pm2
npm run build
pm2 start pm2.config.cjs

probot for more detail

Dev

Setup

# Install dependencies
npm install

# Build code
npm run build

# Run the bot
npm run start

Docker

# 1. Build container
docker build -t cr-bot .

# 2. Start container
docker run -e APP_ID=<app-id> -e PRIVATE_KEY=<pem-value> cr-bot

Contributing

If you have suggestions for how cr-bot could be improved, or want to report a bug, open an issue! We'd love all and any contributions.

For more, check out the Contributing Guide.

Credit

this project is inpired by codereview.gpt

License

ISC © 2023 anc95