diff --git a/.gitea/workflows/master.yaml b/.gitea/workflows/master.yaml index b54c903..b37b091 100644 --- a/.gitea/workflows/master.yaml +++ b/.gitea/workflows/master.yaml @@ -1,10 +1,11 @@ +name: CD on: push: branches: - master jobs: version: - name: "CD > 計算版本號" + name: 計算版本號 runs-on: ubuntu outputs: version: ${{ steps.version.outputs.version }} @@ -13,14 +14,14 @@ jobs: id: version uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }} release: - name: "CD > 發布專案" + name: 發布專案 runs-on: ubuntu needs: version steps: - name: 發布專案 uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }} with: - tag_name: "v${{ needs.version.outputs.version }}" + tag_name: v${{ needs.version.outputs.version }} - name: 清理成品 uses: https://gitea.jsc.idv.tw/actions/cleanup-release@${{ vars.ACTION_CLEANUP_RELEASE_VERSION }} with: diff --git a/.gitea/workflows/review.yaml b/.gitea/workflows/review.yaml index 18e356e..3a49860 100644 --- a/.gitea/workflows/review.yaml +++ b/.gitea/workflows/review.yaml @@ -3,15 +3,33 @@ on: pull_request: types: [opened, synchronize] jobs: + version: + name: 計算版本號 + runs-on: ubuntu + outputs: + version: ${{ steps.version.outputs.version }} + steps: + - name: 計算版本號 + id: version + uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }} + with: + IS_BETA: true + - name: 標註版本號 + uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }} + with: + name: code-review v${{ steps.version.outputs.version }} + tag_name: v${{ steps.version.outputs.version }} + target_commitish: ${{ github.head_ref }} code-review: name: 'Code Review' runs-on: ubuntu + needs: [version] steps: - name: AI Code Review - uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ github.head_ref }} + uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }} with: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - OPENAI_BASE_URL: https://api.openai.com/v1 + OPENAI_BASE_URL: https://openrouter.ai/api/v1 permissions: contents: write pull-requests: write diff --git a/README.md b/README.md index 532c85c..e1c2026 100644 --- a/README.md +++ b/README.md @@ -41,8 +41,10 @@ jobs: - name: AI Code Review uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }} with: + # Github (h3285@evertrust.com.tw) + # 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 OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - OPENAI_BASE_URL: https://api.openai.com/v1 + OPENAI_BASE_URL: https://openrouter.ai/api/v1 permissions: contents: write pull-requests: write @@ -262,8 +264,8 @@ jobs: - name: AI Code Review uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }} with: - OLLAMA_BASE_URL: ${{ secrets.OLLAMA_BASE_URL }} - OLLAMA_MODEL: ${{ secrets.OLLAMA_MODEL }} + OLLAMA_BASE_URL: ${{ vars.OLLAMA_BASE_URL }} + OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }} permissions: contents: write pull-requests: write diff --git a/TODO.md b/TODO.md index 791a6a7..d0a4b23 100644 --- a/TODO.md +++ b/TODO.md @@ -3,6 +3,7 @@ ## 階段一:基本流程串接 - 目標:確保 action 可以被觸發,pipeline 各步驟依序執行,log 出每個主要階段的進入與完成。 - 驗收:log 中能看到每個階段(如「Step1: pipeline start」、「Step2: findings merge」等)明確訊息,且流程能走完(即使還沒產生 findings)。 +- 完成 ## 階段二:Findings 產生與合併 - 目標:各角色(style/security/performance/maintainability/testing)能產生 findings,並正確合併新舊 findings。 diff --git a/action.yaml b/action.yaml index 4e28a5c..ce0e7d2 100644 --- a/action.yaml +++ b/action.yaml @@ -29,6 +29,7 @@ inputs: OPENAI_BASE_URL: description: 'OpenAI-compatible Base URL' required: false + default: 'https://openrouter.ai/api/v1' OPENAI_MODEL: description: 'OpenAI-compatible Model Name' required: false diff --git a/app/gitea.js b/app/gitea.js index 787f801..f8b4216 100644 --- a/app/gitea.js +++ b/app/gitea.js @@ -1,15 +1,17 @@ import axios from 'axios'; +import https from 'https'; import { GITEA_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER } from './config.js'; +const httpsAgent = new https.Agent({ rejectUnauthorized: false }); const headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' }); const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`; export async function getPRDiff() { - const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000 }); + const resp = await axios.get(api(`/repos/${GITEA_REPOSITORY}/pulls/${PR_NUMBER}.diff`), { headers: headers(), timeout: 60000, httpsAgent }); return resp.data; } export async function postComment(body) { - const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/issues/${PR_NUMBER}/comments`), { body }, { headers: headers(), timeout: 30000 }); + const resp = await axios.post(api(`/repos/${GITEA_REPOSITORY}/issues/${PR_NUMBER}/comments`), { body }, { headers: headers(), timeout: 30000, httpsAgent }); return resp.data; } diff --git a/app/llm.js b/app/llm.js index f2521d3..db7217b 100644 --- a/app/llm.js +++ b/app/llm.js @@ -1,6 +1,9 @@ import axios from 'axios'; +import https from 'https'; import { getLLMConfig } from './config.js'; +const httpsAgent = new https.Agent({ rejectUnauthorized: false }); + export async function chat(systemPrompt, userContent) { const { provider, apiKey, baseURL, model } = getLLMConfig(); if (!provider) throw new Error('未設定任何 LLM API Key'); @@ -16,7 +19,7 @@ export async function chat(systemPrompt, userContent) { const resp = await axios.post( `${baseURL.replace(/\/$/, '')}/chat/completions`, { model, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }], temperature: 0.2 }, - { headers, timeout: 120000 } + { headers, timeout: 120000, httpsAgent } ); return resp.data.choices[0].message.content; }