依功能分組為 logger/validate/config/gitea-client/releases/tags 模組, entrypoint.sh 改為呼叫 node /app/index.js,Dockerfile 改用 node:20-alpine 基底。 對外行為(清理舊 release 與未指定 release 的 tag)維持不變。 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
45 lines
1.4 KiB
JavaScript
45 lines
1.4 KiB
JavaScript
// 讀取並驗證環境變數,組出後續流程所需的設定物件。
|
|
// 對應原本 entrypoint.sh 的「參數檢查」區段。
|
|
|
|
import { isEmptyOrNull, requireValue, requireInteger } from './validate.js'
|
|
import { section, info, warn } from './logger.js'
|
|
|
|
/**
|
|
* 從環境變數載入設定並完成驗證。
|
|
* @param {NodeJS.ProcessEnv} env 環境變數來源,預設為 process.env
|
|
* @returns 包含 API 位址、token、保留數量等資訊的設定物件
|
|
*/
|
|
export function loadConfig(env = process.env) {
|
|
section('參數檢查')
|
|
|
|
const serverUrl = env.GITEA_SERVER_URL
|
|
const repository = env.GITEA_REPOSITORY
|
|
const keepCountRaw = env.KEEP_COUNT
|
|
const token = env.GITEA_TOKEN
|
|
|
|
info(`GITEA_SERVER_URL=${serverUrl}`)
|
|
requireValue('GITEA_SERVER_URL', serverUrl)
|
|
|
|
info(`GITEA_REPOSITORY=${repository}`)
|
|
requireValue('GITEA_REPOSITORY', repository)
|
|
|
|
info(`KEEP_COUNT=${keepCountRaw}`)
|
|
requireValue('KEEP_COUNT', keepCountRaw)
|
|
requireInteger('KEEP_COUNT', keepCountRaw)
|
|
|
|
if (isEmptyOrNull(token)) {
|
|
warn('GITEA_TOKEN is empty; release API calls will be anonymous')
|
|
} else {
|
|
info('GITEA_TOKEN=[redacted]')
|
|
}
|
|
|
|
return {
|
|
serverUrl,
|
|
repository,
|
|
token: isEmptyOrNull(token) ? null : token,
|
|
keepCount: Number(keepCountRaw),
|
|
releaseApiUrl: `${serverUrl}/api/v1/repos/${repository}/releases`,
|
|
tagApiUrl: `${serverUrl}/api/v1/repos/${repository}/tags`,
|
|
}
|
|
}
|