From 28dc2ffab87095dd0621d29c71916f521993f04f Mon Sep 17 00:00:00 2001 From: Jeffery Date: Thu, 17 Sep 2026 12:44:22 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=A8=99=E7=B1=A4):=20=E6=8A=8A?= =?UTF-8?q?=E5=88=97=E6=A8=99=E7=B1=A4=E6=8A=BD=E5=88=B0=20lib=EF=BC=8C?= =?UTF-8?q?=E8=AE=93=E8=A6=81=E8=B2=BC=E6=A8=99=E7=B1=A4=E7=9A=84=E8=85=B3?= =?UTF-8?q?=E6=9C=AC=E5=85=B1=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit labels-list 與後續要挑標籤的腳本都要打同一個端點,抽成 lib.listLabels 之後 端點只寫在一個地方。順帶把「本專案不建立標籤,這是取得標籤的唯一途徑」寫進 函式註解,讓下一個要加功能的人先看到這條界線。 Co-Authored-By: Claude Opus 5 (1M context) --- scripts/labels-list.js | 5 ++--- scripts/lib.js | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/scripts/labels-list.js b/scripts/labels-list.js index faf1a1b..483ec60 100644 --- a/scripts/labels-list.js +++ b/scripts/labels-list.js @@ -8,8 +8,7 @@ * 用法:node scripts/labels-list.js --repo owner/name [--host <網址>] [--dry-run] */ import { - expectOk, - giteaRequest, + listLabels, main, parseFlags, parseRepo, @@ -40,7 +39,7 @@ main(async () => { const login = resolveLogin({ host: flags.host }); await preflight(login, repo); - const labels = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? []; + const labels = await listLabels(login, repo); return { repo, diff --git a/scripts/lib.js b/scripts/lib.js index df7b46e..d9cba81 100644 --- a/scripts/lib.js +++ b/scripts/lib.js @@ -418,6 +418,21 @@ function checkTimeTracker(info) { } } +// ── 標籤 ─────────────────────────────────────────────────────────── + +/** + * 取得 repo 上的既有標籤。 + * 本專案不建立標籤,所以這是取得標籤的唯一途徑:要貼標籤的腳本先從這裡拿清單, + * 挑不到合適的就不貼。 + * @param {{base: string, token: string}} login + * @param {string} repo owner/name + * @returns {Promise} + */ +export async function listLabels(login, repo) { + const path = `/repos/${repo}/labels`; + return expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? []; +} + // ── 冪等查重 ─────────────────────────────────────────────────────── /**