labels-list 與後續要挑標籤的腳本都要打同一個端點,抽成 lib.listLabels 之後 端點只寫在一個地方。順帶把「本專案不建立標籤,這是取得標籤的唯一途徑」寫進 函式註解,讓下一個要加功能的人先看到這條界線。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
55 lines
1.2 KiB
JavaScript
55 lines
1.2 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 列出目標 repo 的既有標籤。
|
|
*
|
|
* 這支腳本刻意只讀不寫:本專案不自動建立 Gitea 標籤,上游指令挑標籤時
|
|
* 只能從這裡回傳的清單裡選,選不到就不貼。
|
|
*
|
|
* 用法:node scripts/labels-list.js --repo owner/name [--host <網址>] [--dry-run]
|
|
*/
|
|
import {
|
|
listLabels,
|
|
main,
|
|
parseFlags,
|
|
parseRepo,
|
|
preflight,
|
|
referencesDir,
|
|
resolveLogin,
|
|
templatesDir,
|
|
} from './lib.js';
|
|
|
|
main(async () => {
|
|
const flags = parseFlags(process.argv.slice(2), {
|
|
required: ['repo'],
|
|
optional: ['host'],
|
|
booleans: ['dry-run'],
|
|
});
|
|
const repo = parseRepo(flags.repo);
|
|
const path = `/repos/${repo}/labels`;
|
|
|
|
if (flags['dry-run']) {
|
|
return {
|
|
dryRun: true,
|
|
repo,
|
|
requests: [{ method: 'GET', path }],
|
|
paths: { templates: templatesDir(), references: referencesDir() },
|
|
};
|
|
}
|
|
|
|
const login = resolveLogin({ host: flags.host });
|
|
await preflight(login, repo);
|
|
|
|
const labels = await listLabels(login, repo);
|
|
|
|
return {
|
|
repo,
|
|
count: labels.length,
|
|
labels: labels.map((label) => ({
|
|
id: label.id,
|
|
name: label.name,
|
|
color: label.color,
|
|
description: label.description ?? '',
|
|
})),
|
|
};
|
|
});
|