fix(gitea TLS): 固定略過憑證驗證並改用 Gitea context

This commit is contained in:
2026-06-25 10:28:30 +00:00
parent 65f27f544b
commit 8315e1da2a
5 changed files with 13 additions and 45 deletions
-1
View File
@@ -4,7 +4,6 @@ export const GITEA_TOKEN = process.env.GITEA_TOKEN || '';
export const GITEA_COMMENT_TOKEN = process.env.GITEA_COMMENT_TOKEN || '';
export const GITEA_SERVER_URL = process.env.GITEA_SERVER_URL || 'https://gitea.com';
export const GITEA_REPOSITORY = process.env.GITEA_REPOSITORY || '';
export const GITEA_SKIP_TLS_VERIFY = process.env.GITEA_SKIP_TLS_VERIFY === 'true';
export const PR_NUMBER = process.env.PR_NUMBER || '';
export const PR_HEAD_SHA = process.env.PR_HEAD_SHA || '';
export const PR_HEAD_BRANCH = process.env.PR_HEAD_BRANCH || '';
+2 -2
View File
@@ -1,9 +1,9 @@
import axios from 'axios';
import https from 'https';
import { GITEA_TOKEN, GITEA_COMMENT_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, GITEA_SKIP_TLS_VERIFY, PR_NUMBER, PR_HEAD_SHA, PR_HEAD_BRANCH } from './config.js';
import { GITEA_TOKEN, GITEA_COMMENT_TOKEN, GITEA_SERVER_URL, GITEA_REPOSITORY, PR_NUMBER, PR_HEAD_SHA, PR_HEAD_BRANCH } from './config.js';
import { line, warn } from './log.js';
const httpsAgent = GITEA_SKIP_TLS_VERIFY ? new https.Agent({ rejectUnauthorized: false }) : undefined;
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
const headers = (token = GITEA_TOKEN) => ({ Authorization: `token ${token}`, 'Content-Type': 'application/json' });
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
+2 -2
View File
@@ -37,14 +37,14 @@ describe('gitea', () => {
assert.ok(capturedOpts.headers['Authorization'].startsWith('token '));
});
it('does not set httpsAgent by default (GITEA_SKIP_TLS_VERIFY not true)', async () => {
it('sets an insecure httpsAgent by default', async () => {
let capturedOpts;
mock.method(axios, 'get', async (_url, opts) => {
capturedOpts = opts;
return { data: '' };
});
await getPRDiff();
assert.equal(capturedOpts.httpsAgent, undefined);
assert.equal(capturedOpts.httpsAgent.options.rejectUnauthorized, false);
});
it('getPRDiff propagates axios errors', async () => {
+1 -2
View File
@@ -5,7 +5,6 @@ import {
GITEA_COMMENT_TOKEN,
GITEA_SERVER_URL,
GITEA_REPOSITORY,
GITEA_SKIP_TLS_VERIFY,
PR_NUMBER,
getOpenCodeHttpsAgent,
getLLMConfig,
@@ -13,7 +12,7 @@ import {
import { verifyRemoteAccess } from './git.js';
import { step, line, ok, error, result } from './log.js';
const httpsAgent = GITEA_SKIP_TLS_VERIFY ? new https.Agent({ rejectUnauthorized: false }) : undefined;
const httpsAgent = new https.Agent({ rejectUnauthorized: false });
const api = (path) => `${GITEA_SERVER_URL.replace(/\/$/, '')}/api/v1${path}`;
const giteaHeaders = (token) => ({ Authorization: `token ${token}`, 'Content-Type': 'application/json' });
const opencodeModelConfig = (model) => {