refactor: 重构部署功能

This commit is contained in:
2026-01-08 19:50:58 +08:00
parent a067d167e9
commit db2b2af0d3
13 changed files with 79 additions and 97 deletions

View File

@@ -1,3 +1,7 @@
import { log } from './logger.ts';
const TAG = 'Gitea';
interface TokenResponse {
access_token: string;
token_type: string;
@@ -43,7 +47,7 @@ class Gitea {
async getToken(code: string) {
const { giteaUrl, clientId, clientSecret, redirectUri } = this.config;
console.log('this.config', this.config);
log.debug(TAG, 'Gitea token request started');
const response = await fetch(`${giteaUrl}/login/oauth/access_token`, {
method: 'POST',
headers: this.getHeaders(),
@@ -56,7 +60,15 @@ class Gitea {
}),
});
if (!response.ok) {
console.log(await response.json());
const payload = await response
.json()
.catch(() => null as unknown);
log.error(
TAG,
'Gitea token request failed: status=%d payload=%o',
response.status,
payload,
);
throw new Error(`Fetch failed: ${response.status}`);
}
return (await response.json()) as TokenResponse;