Skip to content

Latest commit

 

History

History
124 lines (85 loc) · 3.74 KB

README.zh-TW.md

File metadata and controls

124 lines (85 loc) · 3.74 KB

程式碼審查機器人

由 ChatGPT 提供支援的程式碼審查機器人

翻譯版本:English | 簡體中文 | 繁體中文 | 한국어 | 日本語

機器人使用方式

❗️⚠️ 由於成本考量,BOT 目前僅用於測試目的,並部署在有限制的 AWS Lambda 上。因此,不穩定的情況是完全正常的。建議自行部署 app。

安裝

安裝:apps/cr-gpt;

設定

  1. 轉到你要整合此機器人的倉庫首頁
  2. 點選 settings
  3. 點選 actions 在下面的 secrets and variables
  4. 切換到 Variables 選項,建立一個新變數 OPENAI_API_KEY,值為你的 open api key (如果是 Github Action 整合,則設定在 secrets 中) image

開始使用

  1. 當你建立一個新的 Pull request 時,機器人會自動進行程式碼審查,審查訊息將顯示在 pr timeline / file changes 部分。
  2. git push 更新 Pull request 之後,cr bot 將重新審查更改的文件

範例:

ChatGPT-CodeReview/pull/21

image

使用 Github Actions

actions/chatgpt-codereviewer

  1. 新增 OPENAI_API_KEY 到你的 github actions secrets
  2. 建立 .github/workflows/cr.yml 新增以下內容
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.

自我託管

  1. 複製程式碼
  2. 複製 .env.example.env, 並填寫環境變數
  3. 安裝相依性並執行
npm i
npm i -g pm2
npm run build
pm2 start pm2.config.cjs

probot 了解更多詳情

開發

設定

# 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

貢獻

如果您對如何改進 cr-bot 有建議,或者想報告錯誤,請開啟一個問題!我們喜歡所有的貢獻。

有關更多信息,請查看貢獻指南.

靈感

這個項目的靈感來自codereview.gpt

License

ISC© 2023 anc95