refactor(calculate-version): 抽出 truncateString 並明確化 repository 驗證命名

- releases 將片段截斷邏輯抽為可重用、可獨立測試的 truncateString(text, limit) 並 export
- config 將 assertRepository 更名為 assertGiteaRepositoryFormat,凸顯其驗證 Gitea owner/repo 格式的領域語義

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 15:21:45 +08:00
co-authored by Claude Opus 4.8
parent 84a936a2a4
commit bc4cea6daf
2 changed files with 11 additions and 7 deletions
+2 -2
View File
@@ -68,7 +68,7 @@ function isValidRepoSegment(part) {
}
// 驗證 repository 為 owner/repo 格式(恰兩段,且每段皆為合法區段)
function assertRepository(name, value) {
function assertGiteaRepositoryFormat(name, value) {
const parts = value.split('/');
const isRepoFormatValid = parts.length === 2 && parts.every(isValidRepoSegment);
if (!isRepoFormatValid) {
@@ -91,7 +91,7 @@ function loadConfig(env = process.env) {
const serverUrl = requireEnv('GITEA_SERVER_URL', env.GITEA_SERVER_URL);
assertHttpUrl('GITEA_SERVER_URL', serverUrl);
const repository = requireEnv('GITEA_REPOSITORY', env.GITEA_REPOSITORY);
assertRepository('GITEA_REPOSITORY', repository);
assertGiteaRepositoryFormat('GITEA_REPOSITORY', repository);
const token = isUnset(env.GITEA_TOKEN) ? null : env.GITEA_TOKEN;
const isBeta = normalizeBetaFlag(env.IS_BETA);