Compare commits
8 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0b39e6a580 | |||
| 199fdf059f | |||
| 2c7fd24db8 | |||
| 70a0fb7660 | |||
| baa5d0cb64 | |||
| ba46224209 | |||
| c69fe4a8a4 | |||
| c275261ed1 |
@@ -0,0 +1,7 @@
|
||||
[
|
||||
{
|
||||
"role": "Rex",
|
||||
"location": "app/git.js",
|
||||
"suggestion": "請避免將敏感資料(如 GITEA_TOKEN)直接寫入環境變數"
|
||||
}
|
||||
]
|
||||
@@ -2,8 +2,8 @@
|
||||
{
|
||||
"level": "critical",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:11",
|
||||
"suggestion": "GITEA_TOKEN 直接嵌入 URL 中,可能導致憑證洩漏。建議使用環境變數或安全的憑證管理方式來處理敏感資訊。",
|
||||
"location": "app/config.js:7",
|
||||
"suggestion": "請確保 EXCLUSIONS_PATH 的值不包含敏感資訊,並使用環境變數來管理敏感資料。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
@@ -15,44 +15,58 @@
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:25",
|
||||
"suggestion": "在使用 fs.existsSync 檢查目錄是否存在時,應考慮使用非同步方法以避免阻塞事件循環。",
|
||||
"role": "Zara",
|
||||
"location": "app/findings.js:40",
|
||||
"suggestion": "在 applyExclusions 函數中,使用 filter 和 some 方法的組合可能會導致效能問題,特別是當 findings 和 exclusions 的數量很大時。考慮使用更有效的資料結構(如 HashSet)來加速查詢。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:29",
|
||||
"suggestion": "在 git clone 時使用 --depth=1 可能會導致未來需要完整歷史紀錄時的性能問題,建議根據實際需求調整。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:11",
|
||||
"suggestion": "在使用 fs.copyFileSync 時,未檢查目標檔案是否存在,可能會覆蓋重要資料。建議在複製之前檢查檔案是否存在。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:11",
|
||||
"suggestion": "在 commitAndPush 函數中,對於 git 操作的錯誤處理不夠完善,應該添加更多的測試來驗證不同情況下的行為。",
|
||||
"role": "Rex",
|
||||
"location": "app/findings.js:40",
|
||||
"suggestion": "在讀取排除問題檔案時,建議加入對檔案內容的驗證,以防止不正確的格式導致潛在的錯誤或漏洞。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Leo",
|
||||
"location": ".gitea/workflows/review.yaml:5",
|
||||
"suggestion": "建議在 'branches-ignore' 前加上空行,以提高可讀性。",
|
||||
"location": "app/findings.js:1",
|
||||
"suggestion": "建議在檔案開頭添加檔案的功能描述,以提高可讀性。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Leo",
|
||||
"location": "app/git.js:45",
|
||||
"suggestion": "考慮使用 async/await 來處理 fs.copyFileSync,以提高可讀性和錯誤處理能力。",
|
||||
"location": "app/findings.js:40",
|
||||
"suggestion": "建議為 loadExclusions 函式添加詳細的文件說明,以便未來的開發者能更快理解其功能。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Leo",
|
||||
"location": "app/findings.js:93",
|
||||
"suggestion": "建議為 deduplicateWithAI 函式添加詳細的文件說明,以便未來的開發者能更快理解其功能。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "README.md:10",
|
||||
"suggestion": "建議在每個步驟後添加簡短的描述,以提高可讀性和理解性。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "app/config.js:7",
|
||||
"suggestion": "建議在常數命名中使用全大寫字母和底線分隔,以提高可讀性。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Maya",
|
||||
"location": "app/main.js:50",
|
||||
"suggestion": "建議在發佈 comment 失敗時,記錄具體的錯誤原因,以便後續調試。",
|
||||
"is_new": true
|
||||
}
|
||||
]
|
||||
@@ -7,11 +7,12 @@
|
||||
1. 服務名稱、模型名稱、角色資訊(個性、符合個性的英文名稱、工作內容),Comment 到 Push Request
|
||||
2. 每個角色個別分析 Git Diff 的內容產生新問題表格(問題等級、角色名稱、問題位置或行數、修改建議)
|
||||
3. 讀取所有未解決的舊問題(問題檔案存在於使用此 Action 的專案固定位置)加上新問題後,去除重複產生本次 Push Request 的問題表格(PR問題表格)覆蓋問題檔案
|
||||
4. 從PR問題表格中取出所有舊問題,依照等級排序後 Comment 到 Push Request
|
||||
5. 從PR問題表格中取出所有新問題,排除嚴重等級的問題後 Comment 到 Push Request
|
||||
6. 從PR問題表格中取出所有新問題,將每個嚴重等級的問題 Comment 到 Push Request
|
||||
7. Commit 問題檔案
|
||||
8. 如果PR問題表格中有嚴重問題,則不要讓 workflow 執行成功(exit 1)
|
||||
4. 讀取排除問題檔案,用來過濾PR問題表格中不需要處理的問題
|
||||
5. 從PR問題表格中取出所有舊問題,依照等級排序後 Comment 到 Push Request
|
||||
6. 從PR問題表格中取出所有新問題,排除嚴重等級的問題後 Comment 到 Push Request
|
||||
7. 從PR問題表格中取出所有新問題,將每個嚴重等級的問題 Comment 到 Push Request
|
||||
8. Commit 問題檔案
|
||||
9. 如果PR問題表格中有嚴重問題,則不要讓 workflow 執行成功(exit 1)
|
||||
|
||||
# 設計
|
||||
|
||||
@@ -139,116 +140,6 @@ jobs:
|
||||
issues: write
|
||||
```
|
||||
|
||||
### 6. Kilo Code
|
||||
```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:
|
||||
KILO_API_KEY: ${{ secrets.KILO_API_KEY }}
|
||||
KILO_BASE_URL: https://api.kilocode.com/v1
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
### 7. Roo Code
|
||||
```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:
|
||||
ROO_API_KEY: ${{ secrets.ROO_API_KEY }}
|
||||
ROO_BASE_URL: https://api.roocode.com/v1
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
### 8. Cline
|
||||
```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:
|
||||
CLINE_API_KEY: ${{ secrets.CLINE_API_KEY }}
|
||||
CLINE_BASE_URL: https://api.cline.dev/v1
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
### 9. Continue
|
||||
```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:
|
||||
CONTINUE_API_KEY: ${{ secrets.CONTINUE_API_KEY }}
|
||||
CONTINUE_BASE_URL: https://api.continue.dev/v1
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
### 10. Kade
|
||||
```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:
|
||||
KADE_API_KEY: ${{ secrets.KADE_API_KEY }}
|
||||
KADE_BASE_URL: https://api.kade.dev/v1
|
||||
permissions:
|
||||
contents: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
```
|
||||
|
||||
### - Ollama
|
||||
|
||||
```yaml
|
||||
|
||||
@@ -8,26 +8,33 @@
|
||||
## 階段二:Findings 產生與合併
|
||||
- 目標:各角色(style/security/performance/maintainability/testing)能產生 findings,並正確合併新舊 findings。
|
||||
- 驗收:log 中能看到每個角色 findings 數量、合併後 findings 統計,並有「Step3: merged findings total=...」等訊息。
|
||||
- 完成
|
||||
|
||||
## 階段三:AI 去重與角色確認
|
||||
- 目標:嘗試呼叫 LLM 進行 findings 去重與角色確認,API 額度不足時要有降級處理 log。
|
||||
- 驗收:log 中能看到 deduplication/resolution confirmation 成功或失敗(如 402),降級時有「保留所有問題」等明確訊息。
|
||||
- 完成
|
||||
|
||||
## 階段四:findings 寫入與 comment 發布
|
||||
## 階段四:排除問題過濾
|
||||
- 目標:讀取排除問題檔案,過濾 PR 問題表格中不需要處理的問題。
|
||||
- 驗收:log 中能看到排除問題檔案讀取成功或不存在的訊息,以及過濾後 findings 數量變化。
|
||||
- 完成
|
||||
|
||||
## 階段五:findings 寫入與 comment 發布
|
||||
- 目標:findings.jsonl 正確寫入,comment 發布順序正確(舊問題→非嚴重→嚴重),每步有 log。
|
||||
- 驗收:log 中能看到 findings 寫入、comment sync 的詳細訊息與順序。
|
||||
- 完成
|
||||
|
||||
## 階段五:記憶區 commit/push 與錯誤處理
|
||||
## 階段六:記憶區 commit/push 與錯誤處理
|
||||
- 目標:記憶區能成功 commit/push,錯誤時有明確 log,流程結束有總結訊息。
|
||||
- 驗收:log 有「persisted findings」、「commit=...」、「push=...」等訊息,錯誤時有「Runner failed: ...」等明確錯誤說明。
|
||||
- 完成
|
||||
|
||||
## 階段六:阻擋嚴重問題 PR(第 8 點)
|
||||
## 階段七:阻擋嚴重問題 PR(第 8 點)
|
||||
- 目標:如果 PR 問題表格中有嚴重(critical)問題,workflow 需直接 exit 1,不讓流程成功。
|
||||
- 驗收:log 中能看到「critical 問題存在,workflow 結束(exit 1)」等明確訊息,且 workflow 狀態為失敗。
|
||||
- 完成
|
||||
|
||||
---
|
||||
|
||||
|
||||
每個階段都會加上明確的 log,並確保即使部分功能未完成也能降級執行、不會中斷 pipeline。
|
||||
|
||||
每次執行後請貼 log,我會協助 debug。
|
||||
所有階段驗收通過。
|
||||
|
||||
@@ -6,6 +6,7 @@ export const PR_HEAD_BRANCH = process.env.PR_HEAD_BRANCH || '';
|
||||
export const PR_BASE_BRANCH = process.env.PR_BASE_BRANCH || '';
|
||||
|
||||
export const FINDINGS_PATH = '.gitea/ai-review/findings.json';
|
||||
export const EXCLUSIONS_PATH = '.gitea/ai-review/exclusions.json';
|
||||
|
||||
export function getLLMConfig() {
|
||||
const checks = [
|
||||
|
||||
+38
-1
@@ -1,7 +1,7 @@
|
||||
import fs from 'fs';
|
||||
import path from 'path';
|
||||
import { chatJSON } from './llm.js';
|
||||
import { FINDINGS_PATH } from './config.js';
|
||||
import { FINDINGS_PATH, EXCLUSIONS_PATH } from './config.js';
|
||||
|
||||
const LEVELS = ['critical', 'warning', 'info'];
|
||||
|
||||
@@ -93,3 +93,40 @@ export async function deduplicateWithAI(findings) {
|
||||
return findings;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 讀取排除問題檔案(從 workspace 的 EXCLUSIONS_PATH)
|
||||
* 格式:[{ role, location, suggestion }],欄位可部分省略,省略表示萬用
|
||||
*/
|
||||
export function loadExclusions(workspace) {
|
||||
const fullPath = path.join(workspace, EXCLUSIONS_PATH);
|
||||
if (!fs.existsSync(fullPath)) {
|
||||
console.log(' 排除問題檔案不存在,跳過過濾');
|
||||
return [];
|
||||
}
|
||||
try {
|
||||
const data = JSON.parse(fs.readFileSync(fullPath, 'utf8'));
|
||||
const exclusions = Array.isArray(data) ? data : [];
|
||||
console.log(` 讀取排除問題: ${exclusions.length} 筆`);
|
||||
return exclusions;
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ 讀取排除問題失敗: ${e.message},跳過過濾`);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 套用排除規則,過濾掉符合排除條件的 findings
|
||||
* 排除條件:role/location/suggestion 皆符合(省略的欄位視為萬用)
|
||||
*/
|
||||
export function applyExclusions(findings, exclusions) {
|
||||
if (exclusions.length === 0) return findings;
|
||||
const before = findings.length;
|
||||
const filtered = findings.filter(f => !exclusions.some(ex =>
|
||||
(!ex.role || ex.role === f.role) &&
|
||||
(!ex.location || ex.location === f.location) &&
|
||||
(!ex.suggestion || String(f.suggestion).startsWith(String(ex.suggestion).slice(0, 50)))
|
||||
));
|
||||
console.log(` 排除過濾: ${before} -> ${filtered.length} 筆(排除 ${before - filtered.length} 筆)`);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
+21
-17
@@ -1,7 +1,7 @@
|
||||
import { GITEA_REPOSITORY, PR_NUMBER, PR_HEAD_BRANCH, PR_BASE_BRANCH, getLLMConfig } from './config.js';
|
||||
import { loadRoles, getRoleIntro } from './roles.js';
|
||||
import { getPRDiff, postComment } from './gitea.js';
|
||||
import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel, deduplicateWithAI } from './findings.js';
|
||||
import { analyzeWithRole, loadOldFindings, mergeFindings, sortByLevel, deduplicateWithAI, loadExclusions, applyExclusions } from './findings.js';
|
||||
import { saveFindings, postOldFindingsComment, postNewNonCriticalComment, postNewCriticalComments } from './comments.js';
|
||||
import { commitAndPush } from './git.js';
|
||||
|
||||
@@ -26,7 +26,6 @@ async function main() {
|
||||
console.log(` 已載入 ${roles.length} 個角色: [${roles.map(r => r.name).join(', ')}]`);
|
||||
|
||||
// 取得 PR diff
|
||||
console.log('\n📋 Step1: 取得 PR Diff');
|
||||
let diff;
|
||||
try {
|
||||
diff = await getPRDiff();
|
||||
@@ -42,7 +41,6 @@ async function main() {
|
||||
}
|
||||
|
||||
// 發布角色介紹 comment
|
||||
console.log('\n💬 Step1: 發布角色介紹 Comment');
|
||||
try {
|
||||
const intro = getRoleIntro(roles) + `\n\n> 🔍 服務:${provider} 模型:${model}`;
|
||||
await postComment(intro);
|
||||
@@ -50,6 +48,7 @@ async function main() {
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ comment 發布失敗(繼續執行): ${e.message}`);
|
||||
}
|
||||
console.log(' Step1 完成');
|
||||
|
||||
// Step2: 各角色分析 diff 產生新 findings
|
||||
console.log('\n📊 Step2: Findings 產生');
|
||||
@@ -64,38 +63,43 @@ async function main() {
|
||||
}
|
||||
console.log(` Step2 完成: 新 findings 總計 ${newFindings.length} 筆`);
|
||||
|
||||
// Step3: 讀取舊 findings,合併去重
|
||||
// Step3: 讀取舊 findings,合併去重(含 AI 語意去重)
|
||||
console.log('\n🔀 Step3: Findings 合併');
|
||||
const oldFindings = loadOldFindings(WORKSPACE);
|
||||
const mergedFindings = mergeFindings(oldFindings, newFindings);
|
||||
console.log(` Step3 merged findings total=${mergedFindings.length}`);
|
||||
|
||||
// Step3b: AI 語意去重
|
||||
console.log('\n🤖 Step3b: AI 語意去重');
|
||||
const deduped = await deduplicateWithAI(mergedFindings);
|
||||
const sorted = sortByLevel(deduped);
|
||||
console.log(` Step3b dedup findings total=${sorted.length} (critical=${sorted.filter(f=>f.level==='critical').length} warning=${sorted.filter(f=>f.level==='warning').length} info=${sorted.filter(f=>f.level==='info').length})`);
|
||||
|
||||
// Step4: 寫入 findings.json,依序發布 comment
|
||||
console.log('\n📝 Step4: Findings 寫入與 Comment 發布');
|
||||
saveFindings(WORKSPACE, sorted);
|
||||
// Step4: 讀取排除問題檔案,過濾 PR 問題表格
|
||||
console.log('\n🚫 Step4: 排除問題過濾');
|
||||
const exclusions = loadExclusions(WORKSPACE);
|
||||
const filtered = applyExclusions(sorted, exclusions);
|
||||
console.log(` Step4 完成: findings total=${filtered.length}`);
|
||||
|
||||
// Step5: 寫入 findings.json,依序發布 comment
|
||||
console.log('\n📝 Step5: Findings 寫入與 Comment 發布');
|
||||
saveFindings(WORKSPACE, filtered);
|
||||
|
||||
try {
|
||||
await postOldFindingsComment(sorted);
|
||||
await postNewNonCriticalComment(sorted);
|
||||
await postNewCriticalComments(sorted);
|
||||
console.log(' Step4 完成');
|
||||
await postOldFindingsComment(filtered);
|
||||
await postNewNonCriticalComment(filtered);
|
||||
await postNewCriticalComments(filtered);
|
||||
console.log(' Step5 完成');
|
||||
} catch (e) {
|
||||
console.log(` ⚠️ comment 發布失敗(繼續執行): ${e.message}`);
|
||||
}
|
||||
|
||||
// Step5: commit/push findings.json 到來源分支
|
||||
console.log('\n💾 Step5: 記憶區 Commit/Push');
|
||||
// Step6: commit/push findings.json 到來源分支
|
||||
console.log('\n💾 Step6: 記憶區 Commit/Push');
|
||||
await commitAndPush(WORKSPACE);
|
||||
|
||||
// Step6: 有 critical 問題則 exit 1
|
||||
console.log('\n🚦 Step6: 嚴重問題檢查');
|
||||
const criticalCount = sorted.filter(f => f.level === 'critical').length;
|
||||
// Step7: 有 critical 問題則 exit 1
|
||||
console.log('\n🚦 Step7: 嚴重問題檢查');
|
||||
const criticalCount = filtered.filter(f => f.level === 'critical').length;
|
||||
if (criticalCount > 0) {
|
||||
console.log(` ❌ 發現 ${criticalCount} 個嚴重問題,workflow 結束(exit 1)`);
|
||||
console.log('='.repeat(60));
|
||||
|
||||
Reference in New Issue
Block a user