Compare commits

...

7 Commits

6 changed files with 18 additions and 11 deletions
+4 -3
View File
@@ -1,10 +1,11 @@
name: CD
on: on:
push: push:
branches: branches:
- master - master
jobs: jobs:
version: version:
name: "CD > 計算版本號" name: 計算版本號
runs-on: ubuntu runs-on: ubuntu
outputs: outputs:
version: ${{ steps.version.outputs.version }} version: ${{ steps.version.outputs.version }}
@@ -13,14 +14,14 @@ jobs:
id: version id: version
uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }} uses: https://gitea.jsc.idv.tw/actions/calculate-version@${{ vars.ACTION_CALCULATE_VERSION }}
release: release:
name: "CD > 發布專案" name: 發布專案
runs-on: ubuntu runs-on: ubuntu
needs: version needs: version
steps: steps:
- name: 發布專案 - name: 發布專案
uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }} uses: akkuman/gitea-release-action@${{ vars.ACTION_RELEASE_VERSION }}
with: with:
tag_name: "v${{ needs.version.outputs.version }}" tag_name: v${{ needs.version.outputs.version }}
- name: 清理成品 - name: 清理成品
uses: https://gitea.jsc.idv.tw/actions/cleanup-release@${{ vars.ACTION_CLEANUP_RELEASE_VERSION }} uses: https://gitea.jsc.idv.tw/actions/cleanup-release@${{ vars.ACTION_CLEANUP_RELEASE_VERSION }}
with: with:
+3 -3
View File
@@ -21,15 +21,15 @@ jobs:
tag_name: v${{ steps.version.outputs.version }} tag_name: v${{ steps.version.outputs.version }}
target_commitish: ${{ github.head_ref }} target_commitish: ${{ github.head_ref }}
code-review: code-review:
name: Code Review name: 'Code Review'
runs-on: ubuntu runs-on: ubuntu
needs: [version] needs: [version]
steps: steps:
- name: AI Code Review - name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }} uses: https://gitea.jsc.idv.tw/jiantw83/code-review@v${{ needs.version.outputs.version }}
with: with:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} OPENAI_API_KEY: ${{ secrets.HF_API_KEY }}
OPENAI_BASE_URL: https://api.openai.com/v1 OPENAI_BASE_URL: https://api-inference.huggingface.co/v1
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
+2 -2
View File
@@ -262,8 +262,8 @@ jobs:
- name: AI Code Review - name: AI Code Review
uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }} uses: https://gitea.jsc.idv.tw/jiantw83/code-review@${{ vars.ACTION_CODE_REVIEW_VERSION }}
with: with:
OLLAMA_BASE_URL: ${{ secrets.OLLAMA_BASE_URL }} OLLAMA_BASE_URL: ${{ vars.OLLAMA_BASE_URL }}
OLLAMA_MODEL: ${{ secrets.OLLAMA_MODEL }} OLLAMA_MODEL: ${{ vars.OLLAMA_MODEL }}
permissions: permissions:
contents: write contents: write
pull-requests: write pull-requests: write
+1
View File
@@ -29,6 +29,7 @@ inputs:
OPENAI_BASE_URL: OPENAI_BASE_URL:
description: 'OpenAI-compatible Base URL' description: 'OpenAI-compatible Base URL'
required: false required: false
default: 'https://openrouter.ai/api/v1'
OPENAI_MODEL: OPENAI_MODEL:
description: 'OpenAI-compatible Model Name' description: 'OpenAI-compatible Model Name'
required: false required: false
+4 -2
View File
@@ -1,15 +1,17 @@
import axios from 'axios'; import axios from 'axios';
import https from 'https';
import { GITEA_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER } from './config.js'; 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 headers = () => ({ Authorization: `token ${GITEA_TOKEN}`, 'Content-Type': 'application/json' });
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`; const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
export async function getPRDiff() { 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; return resp.data;
} }
export async function postComment(body) { 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; return resp.data;
} }
+4 -1
View File
@@ -1,6 +1,9 @@
import axios from 'axios'; import axios from 'axios';
import https from 'https';
import { getLLMConfig } from './config.js'; import { getLLMConfig } from './config.js';
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
export async function chat(systemPrompt, userContent) { export async function chat(systemPrompt, userContent) {
const { provider, apiKey, baseURL, model } = getLLMConfig(); const { provider, apiKey, baseURL, model } = getLLMConfig();
if (!provider) throw new Error('未設定任何 LLM API Key'); if (!provider) throw new Error('未設定任何 LLM API Key');
@@ -16,7 +19,7 @@ export async function chat(systemPrompt, userContent) {
const resp = await axios.post( const resp = await axios.post(
`${baseURL.replace(/\/$/, '')}/chat/completions`, `${baseURL.replace(/\/$/, '')}/chat/completions`,
{ model, messages: [{ role: 'system', content: systemPrompt }, { role: 'user', content: userContent }], temperature: 0.2 }, { 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; return resp.data.choices[0].message.content;
} }