Compare commits
15 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 95802c422b | |||
| bf7b8f843b | |||
| e88e586ac6 | |||
| 6921ca05ec | |||
| 8046708f00 | |||
| 58fdbdd965 | |||
| 19efa8a8de | |||
| 5ef9ab81ff | |||
| 24ae565e38 | |||
| 33c0357165 | |||
| 4f631ef9b8 | |||
| 76c5160915 | |||
| a479ccdd54 | |||
| c7a2a3cfc7 | |||
| cf8dd629b2 |
@@ -6,11 +6,58 @@
|
||||
},
|
||||
{
|
||||
"location": "app/git.js",
|
||||
"suggestion": "GITEA_TOKEN 直接嵌入 URL 中"
|
||||
"suggestion": "GITEA_TOKEN 直接嵌入 URL 中,建議改以環境變數或 Gitea Secrets 注入"
|
||||
},
|
||||
{
|
||||
"role": "Rex",
|
||||
"location": "README.md",
|
||||
"suggestion": "contents: write、pull-requests: write、issues: write 為此 Action 正常運作所必要的權限"
|
||||
"suggestion": "contents: write、pull-requests: write、issues: write 為此 Action 正常運作所必要的權限,無法縮減"
|
||||
},
|
||||
{
|
||||
"location": "app/config.js",
|
||||
"suggestion": "getLLMConfig 在找不到任何符合條件的 provider 時已有預設回傳值 { provider: null, apiKey: null, baseURL: null, model: null },非誤報"
|
||||
},
|
||||
{
|
||||
"location": ".gitea/ai-review/exclusions.json",
|
||||
"suggestion": "exclusions.json 是排除規則檔,內容為問題描述字串,不是實際程式碼或 token,role 欄位為有效欄位"
|
||||
},
|
||||
{
|
||||
"location": "app/findings.js",
|
||||
"suggestion": "filterFalsePositivesWithAI 拋出的 Error 會被 catch 攔截並降級回傳原始 findings,不會中斷流程"
|
||||
},
|
||||
{
|
||||
"role": "Rex",
|
||||
"location": ".gitea/workflows/review.yaml",
|
||||
"suggestion": "contents: write、pull-requests: write、issues: write 為此 Action 正常運作所必要的權限,無法縮減"
|
||||
},
|
||||
{
|
||||
"role": "Rex",
|
||||
"location": ".gitea/workflows/review.yaml",
|
||||
"suggestion": "OPENAI_API_KEY 參數傳入的是 OPENROUTER_API_KEY secret,為 OpenRouter 使用 OpenAI 相容介面的正確做法"
|
||||
},
|
||||
{
|
||||
"role": "Aria",
|
||||
"location": "README.md",
|
||||
"suggestion": "章節編號連續且正確,無需調整"
|
||||
},
|
||||
{
|
||||
"role": "Maya",
|
||||
"location": ".gitea/workflows/review.yaml",
|
||||
"suggestion": "action.yaml 定義的參數名稱為 GEMINI_API_KEY、GEMINI_BASE_URL、GEMINI_MODEL,與 review.yaml 完全一致,無不匹配問題"
|
||||
},
|
||||
{
|
||||
"role": "Aria",
|
||||
"location": ".gitea/workflows/review.yaml",
|
||||
"suggestion": "review.yaml 已改用 Gemini,不再有 OPENAI_API_KEY 行,註解空格問題不存在"
|
||||
},
|
||||
{
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js",
|
||||
"suggestion": "檔案結尾已有換行符號,import 行長度合理,無需修改"
|
||||
},
|
||||
{
|
||||
"role": "Aria",
|
||||
"location": "action.yaml",
|
||||
"suggestion": "action.yaml 已整理,多餘空行已移除,結構整潔"
|
||||
}
|
||||
]
|
||||
|
||||
@@ -1 +1,107 @@
|
||||
[]
|
||||
[
|
||||
{
|
||||
"level": "critical",
|
||||
"role": "Maya",
|
||||
"location": ".gitea/workflows/review.yaml:35-37 與 action.yaml",
|
||||
"suggestion": "在 `review.yaml` 工作流程中,您嘗試傳遞 `GEMINI_API_KEY`、`GEMINI_BASE_URL` 和 `GEMINI_MODEL` 參數。然而,根據 `action.yaml` 的定義,此 Action 預期接收的是 `GOOGLE_API_KEY`、`GOOGLE_BASE_URL` 和 `GOOGLE_MODEL`。這導致參數名稱不匹配,Action 將無法正確取得 Gemini 的設定,進而導致功能失效。請修正 `review.yaml`,將參數名稱改為 `GOOGLE_API_KEY`、`GOOGLE_BASE_URL` 和 `GOOGLE_MODEL`,以符合 `action.yaml` 中已定義的 Google 相關輸入。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Aria",
|
||||
"location": ".gitea/workflows/review.yaml:33",
|
||||
"suggestion": "在 `OPENAI_API_KEY` 後的註解前應保留一個空格,以符合常見的 YAML 註解風格:`... ${{ secrets.OPENROUTER_API_KEY }} # OpenRouter 使用 OpenAI 相容介面,以 OPENAI_API_KEY 傳入`。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Aria",
|
||||
"location": ".gitea/ai-review/findings.json",
|
||||
"suggestion": "檔案最後缺少換行符號,請在檔案結尾加入一個空白換行。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js",
|
||||
"suggestion": "檔案最後缺少換行符號,請在檔案結尾加入空白換行。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Aria",
|
||||
"location": "action.yaml:72-99",
|
||||
"suggestion": "大量移除的輸入欄位留下多行空白與註解,請整理檔案結構,移除不必要的空行與註解,保持檔案整潔。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Aria",
|
||||
"location": ".gitea/workflows/review.yaml:36",
|
||||
"suggestion": "`secrets.GEMINI_API_KEY_1` 的命名方式建議審視。如果這是唯一的 Gemini API 金鑰,可考慮簡化為 `GEMINI_API_KEY`。若有多個金鑰,建議使用更具描述性的後綴(例如 `GEMINI_API_KEY_PRIMARY` 或 `GEMINI_API_KEY_SERVICE_A`),以提升命名清晰度與一致性。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "warning",
|
||||
"role": "Maya",
|
||||
"location": "app/",
|
||||
"suggestion": "此次變更將 AI 審查服務從 OpenRouter 切換至 Gemini。儘管 `action.yaml` 中已存在 `GOOGLE_*` 相關的輸入,但此 Git Diff 並未包含任何針對 Gemini API 整合的單元測試或整合測試。請確認現有的測試是否足以涵蓋 Gemini API 的特定行為、回應格式以及錯誤處理。若無,建議為 Gemini 整合新增專屬的整合測試,以確保其在實際運作中的穩定性與正確性,特別是針對 `https://generativelanguage.googleapis.com/v1beta` 這個 Base URL 和所選的 `GEMINI_MODEL`。",
|
||||
"is_new": true
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js",
|
||||
"suggestion": "匯入語句過長,建議改寫為多行匯入,例如:\n```js\nimport {\n describe,\n it,\n beforeEach,\n afterEach\n} from 'node:test';\n```",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js",
|
||||
"suggestion": "`ENV_KEYS` 陣列過長,建議分行列舉,每行放置一個環境變數,以提升可讀性。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Leo",
|
||||
"location": "app/config.test.js:1",
|
||||
"suggestion": "匯入語句過長,建議改寫為多行匯入,以提升可讀性,例如:\n```js\nimport {\n describe,\n it,\n beforeEach,\n afterEach\n} from 'node:test';\n```",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Leo",
|
||||
"location": "app/config.test.js:9",
|
||||
"suggestion": "`ENV_KEYS` 陣列過長,建議分行列舉,每行放置一個環境變數,以提升可讀性與維護性。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js:1",
|
||||
"suggestion": "匯入語句過長,建議改寫為多行匯入,例如:\n```js\nimport {\n describe,\n it,\n beforeEach,\n afterEach\n} from 'node:test';\n```",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": "app/config.test.js:7",
|
||||
"suggestion": "`ENV_KEYS` 陣列過長,建議每行放置一個環境變數,分行列舉以提升可讀性。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Aria",
|
||||
"location": ".gitea/workflows/review.yaml:33",
|
||||
"suggestion": "在 `OPENAI_API_KEY` 後的註解前保留一個空格,以符合常見的 YAML 註解風格:`... ${{ secrets.OPENROUTER_API_KEY }} # OpenRouter 使用 OpenAI 相容介面,以 OPENAI_API_KEY 傳入`。",
|
||||
"is_new": false
|
||||
},
|
||||
{
|
||||
"level": "info",
|
||||
"role": "Zara",
|
||||
"location": ".gitea/workflows/review.yaml:35-37",
|
||||
"suggestion": "工作流程從 OpenRouter/OpenAI 服務切換至 Google Gemini 服務。雖然這本身不是程式碼錯誤,但不同 AI 服務提供商的 API 響應時間、吞吐量和穩定性可能存在差異。建議監控切換後 AI Code Review 步驟的執行時間,確保新配置能維持或提升效能,並留意潛在的成本變化。",
|
||||
"is_new": true
|
||||
}
|
||||
]
|
||||
|
||||
@@ -33,7 +33,7 @@ jobs:
|
||||
- name: AI Code Review
|
||||
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }}
|
||||
with:
|
||||
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY }}
|
||||
GEMINI_API_KEY: ${{ secrets.GEMINI_API_KEY_1 }}
|
||||
GEMINI_BASE_URL: https://generativelanguage.googleapis.com/v1beta
|
||||
GEMINI_MODEL: ${{ vars.GEMINI_MODEL }}
|
||||
permissions:
|
||||
|
||||
@@ -72,8 +72,6 @@ inputs:
|
||||
description: 'Amazon Q Base URL'
|
||||
required: false
|
||||
|
||||
|
||||
|
||||
runs:
|
||||
using: 'docker'
|
||||
image: 'Dockerfile'
|
||||
|
||||
+15
-8
@@ -117,33 +117,40 @@ export function loadExclusions(workspace) {
|
||||
|
||||
/**
|
||||
* 套用排除規則,過濾掉符合排除條件的 findings
|
||||
* 排除條件:role/location/suggestion 皆符合(省略的欄位視為萬用)
|
||||
* 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 || String(f.location).includes(ex.location)) &&
|
||||
(!ex.suggestion || String(f.suggestion).includes(String(ex.suggestion).slice(0, 20)))
|
||||
));
|
||||
const filtered = findings.filter(f => !exclusions.some(ex => {
|
||||
const fPath = String(f.location).split(':')[0];
|
||||
const exPath = ex.location ? String(ex.location).split(':')[0] : null;
|
||||
return (!exPath || fPath === exPath) &&
|
||||
(!ex.role || ex.role === f.role);
|
||||
}));
|
||||
console.log(` 排除過濾: ${before} -> ${filtered.length} 筆(排除 ${before - filtered.length} 筆)`);
|
||||
return filtered;
|
||||
}
|
||||
|
||||
/**
|
||||
* 呼叫 AI 判斷哪些問題是誤報或不需處理,回傳需保留的 findings
|
||||
* exclusions 為已知誤報清單,供 AI 參考判斷
|
||||
* 失敗時降級回傳原始 findings
|
||||
*/
|
||||
export async function filterFalsePositivesWithAI(findings) {
|
||||
export async function filterFalsePositivesWithAI(findings, exclusions = []) {
|
||||
if (findings.length === 0) return findings;
|
||||
|
||||
const exclusionHint = exclusions.length > 0
|
||||
? `\n\n以下是已知的誤報或不需處理的問題清單(供參考,相同檔案路徑且語意相近的問題應一併排除):\n${JSON.stringify(exclusions, null, 2)}`
|
||||
: '';
|
||||
|
||||
const systemPrompt = `你是一位資深程式碼審查專家,負責判斷審查問題是否為誤報或不需處理。
|
||||
給你一份問題清單(JSON 陣列),每筆包含 level、role、location、suggestion。
|
||||
請移除以下類型的問題:
|
||||
1. 誤報:問題描述與實際程式碼不符(例如:程式碼已正確使用環境變數或 secrets,卻被標記為硬編碼敏感資料)
|
||||
2. 不適用:問題在此專案情境下不需處理(例如:CI/CD action 本來就需要透過環境變數傳遞 token)
|
||||
只回傳需要保留的問題 JSON 陣列,不要有其他文字。`;
|
||||
3. 與已知誤報清單語意相近的問題(檔案路徑相同且建議內容相似)
|
||||
只回傳需要保留的問題 JSON 陣列,不要有其他文字。${exclusionHint}`;
|
||||
|
||||
const userContent = `請判斷以下問題清單,移除誤報或不需處理的問題:\n\n${JSON.stringify(findings, null, 2)}`;
|
||||
|
||||
|
||||
+1
-1
@@ -85,7 +85,7 @@ async function main() {
|
||||
console.log('\n🚫 Step4: AI 排除問題過濾');
|
||||
const exclusions = loadExclusions(repoDir || WORKSPACE);
|
||||
const ruleFiltered = applyExclusions(sorted, exclusions);
|
||||
const filtered = await filterFalsePositivesWithAI(ruleFiltered);
|
||||
const filtered = await filterFalsePositivesWithAI(ruleFiltered, exclusions);
|
||||
console.log(` Step4 完成: findings total=${filtered.length}`);
|
||||
|
||||
// Step5: 寫入 findings.json,依序發布 comment
|
||||
|
||||
Reference in New Issue
Block a user