refactor(calculate-version): 將驗證常數抽離為具名常數

- config 將每段長度上限與允許字元抽為 MAX_REPO_NAME_LENGTH / REPO_SEGMENT_PATTERN(regex 提升至模組層級,避免每次重編譯)
- releases 將片段截斷長度抽為 API_ERROR_SNIPPET_LENGTH

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-26 14:11:36 +08:00
co-authored by Claude Opus 4.8
parent 8ee3638be5
commit d8a86e90ea
2 changed files with 11 additions and 4 deletions
+4 -1
View File
@@ -3,6 +3,9 @@
// 每頁取得的 release 筆數
const RELEASES_PER_PAGE = 10;
// JSON 解析失敗時,附在錯誤訊息中的回應內容片段最大字元數
const API_ERROR_SNIPPET_LENGTH = 200;
/**
* 以分頁方式取得指定 Gitea repo 的所有 release,並回傳合併後的陣列。
*
@@ -64,7 +67,7 @@ async function fetchReleases(baseUrl, options = {}) {
pageJson = JSON.parse(text);
} catch {
// 以字元(而非 UTF-16 碼元)截斷回傳內容片段,避免拆分多位元組字元造成亂碼
const contentSnippet = Array.from(text).slice(0, 200).join('');
const contentSnippet = Array.from(text).slice(0, API_ERROR_SNIPPET_LENGTH).join('');
throw new Error(`release API 回傳資料無法解析 (page=${page}),回應內容片段:「${contentSnippet}`);
}