167 lines
5.5 KiB
Markdown
167 lines
5.5 KiB
Markdown
# 簡介
|
||
|
||
這是一個 AI Code Review Action。Gitea Workflow 可以使用此 Action 讓 AI 助理根據不同面向分析 Push Request 中變更的內容後,將問題分級 Commnet 到 Push Request 中。
|
||
|
||
# 流程(新 Push Request、新 Commit (排除 AI 助理的 Commit) 觸發)
|
||
|
||
1. 服務名稱、模型名稱、角色資訊(個性、符合個性的英文名稱、工作內容),Comment 到 Push Request
|
||
2. 每個角色個別分析 Git Diff 的內容產生新問題表格(問題等級、角色名稱、問題位置或行數、修改建議)
|
||
3. 讀取所有未解決的舊問題(問題檔案 `.gitea/ai-review/findings.json` 存在於使用此 Action 的專案固定位置)加上新問題後,去除重複產生本次 Push Request 的問題表格(PR問題表格)覆蓋問題檔案
|
||
4. 讀取排除問題檔案(`.gitea/ai-review/exclusions.json` 存在於使用此 Action 的專案固定位置),用來過濾PR問題表格中不需要處理的問題
|
||
5. 從PR問題表格中取出所有舊問題,依照等級排序後 Comment 到 Push Request
|
||
6. 從PR問題表格中取出所有新問題,排除嚴重等級的問題後 Comment 到 Push Request
|
||
7. 從PR問題表格中取出所有新問題,將每個嚴重等級的問題 Comment 到 Push Request
|
||
8. Commit 問題檔案
|
||
9. 如果PR問題表格中有嚴重問題,則不要讓 workflow 執行成功(exit 1)
|
||
|
||
# 設計
|
||
|
||
1. Gitea 的相關參數如果 inputs 沒有定義,則從 ${{ gitea.* }} 取得
|
||
2. BASE_URL 如果 inputs 沒有定義,則使用預設值
|
||
3. Comment 加上些許 emoji 讓資訊有點活力
|
||
4. 盡量將應用程式放在 ./app,修改 entrypoint.sh 與 Dockerfile 讓程式可以正常運行
|
||
5. 將提示詞放到 ./app/prompts 內供程式讀取
|
||
6. API Key 支援逗號分隔傳入多個,依序嘗試,失敗時自動換下一個,全部失敗則 exit 1
|
||
|
||
# 使用說明
|
||
|
||
1. 在 Gitea 專案中建立 `.gitea/workflows` 資料夾
|
||
2. 在 `.gitea/workflows` 資料夾中建立 `ai-review.yaml'
|
||
3. 在 `ai-review.yaml` 中填入以下內容(選擇一個使用):
|
||
|
||
### 1. OpenAI
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} # 支援逗號分隔多個 Key
|
||
OPENAI_BASE_URL: https://api.openai.com/v1
|
||
OPENAI_MODEL: ${{ vars.OPENAI_MODEL }}
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
issues: write
|
||
```
|
||
|
||
### 2. OpenRouter
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
OPENAI_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} # OpenRouter 使用 OpenAI 相容介面,以 OPENAI_API_KEY 傳入,支援逗號分隔多個 Key
|
||
OPENAI_BASE_URL: https://openrouter.ai/api/v1
|
||
OPENAI_MODEL: ${{ vars.OPENROUTER_MODEL }}
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
issues: write
|
||
```
|
||
|
||
### 3. Anthropic Claude
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
CLAUDE_API_KEY: ${{ secrets.CLAUDE_API_KEY }} # 支援逗號分隔多個 Key
|
||
CLAUDE_BASE_URL: https://api.anthropic.com/v1
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
issues: write
|
||
```
|
||
|
||
### 4. Google Gemini
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }},${{ secrets.GEMINI_API_KEY_1 }},${{ secrets.GEMINI_API_KEY_2 }},${{ secrets.GEMINI_API_KEY_3 }},${{ secrets.GEMINI_API_KEY_4 }},${{ secrets.GEMINI_API_KEY_5 }},${{ secrets.GEMINI_API_KEY_6 }},${{ secrets.GEMINI_API_KEY_7 }},${{ secrets.GEMINI_API_KEY_8 }},${{ secrets.GEMINI_API_KEY_9 }}
|
||
GEMINI_BASE_URL: https://generativelanguage.googleapis.com/v1beta
|
||
GEMINI_MODEL: ${{ vars.GEMINI_MODEL }}
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
issues: write
|
||
```
|
||
|
||
### 5. Amazon Q
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
AMAZONQ_API_KEY: ${{ secrets.AMAZONQ_API_KEY }} # 支援逗號分隔多個 Key
|
||
AMAZONQ_BASE_URL: https://q.api.aws
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
issues: write
|
||
```
|
||
|
||
### - Ollama
|
||
|
||
```yaml
|
||
name: AI
|
||
on:
|
||
pull_request:
|
||
types: [opened, synchronize]
|
||
jobs:
|
||
code-review:
|
||
name: 'Code Review'
|
||
runs-on: ubuntu
|
||
steps:
|
||
- name: AI Code Review
|
||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
|
||
with:
|
||
OLLAMA_BASE_URL: https://ollama.jsc.idv.me/v1
|
||
OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }}
|
||
permissions:
|
||
contents: write
|
||
pull-requests: write
|
||
|
||
issues: write
|
||
``` |