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}`) ?? []; +} + // ── 冪等查重 ─────────────────────────────────────────────────────── /**