scripts/lib.js 立起所有腳本共用的地基:具名 flag 解析、單行 JSON 輸出
{ok, data, error:{code, message}}、Gitea API 與 git 各自唯一的出口、
四層前置檢查、依標題的冪等查重。
前置檢查依序為執行環境(git/tea 在 PATH 上、plugin 目錄完整)、Gitea 登入
有效、帳號對 issues unit 的寫入權、repo 已開啟時間追蹤;任一層不通過即帶著
可區分的錯誤碼中止,訊息一律指出該去哪裡改設定,前一層沒過就不再往下打。
issues unit 的寫入權採實測而非讀 permissions.push——Gitea 的 team unit 權限
可獨立於 repo 的 push 權限。探針打在不存在的議題 index 0:有寫入權會通過權限
中介層後回 404,沒有則直接 403,兩種結果都不改動任何東西。
認證預設沿用使用者既有的 tea login(讀 tea 的 config.yml),環境變數
TEA_SDLC_API_BASE / TEA_SDLC_TOKEN 只作為測試與 CI 的覆寫出口。
labels-list 為第一支腳本,刻意只讀不寫,呼應「不自動建立 Gitea 標籤」。
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
56 lines
1.3 KiB
JavaScript
56 lines
1.3 KiB
JavaScript
#!/usr/bin/env node
|
|
/**
|
|
* 列出目標 repo 的既有標籤。
|
|
*
|
|
* 這支腳本刻意只讀不寫:本專案不自動建立 Gitea 標籤,上游指令挑標籤時
|
|
* 只能從這裡回傳的清單裡選,選不到就不貼。
|
|
*
|
|
* 用法:node scripts/labels-list.js --repo owner/name [--host <網址>] [--dry-run]
|
|
*/
|
|
import {
|
|
expectOk,
|
|
giteaRequest,
|
|
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 = expectOk(await giteaRequest(login, 'GET', path), `GET ${path}`) ?? [];
|
|
|
|
return {
|
|
repo,
|
|
count: labels.length,
|
|
labels: labels.map((label) => ({
|
|
id: label.id,
|
|
name: label.name,
|
|
color: label.color,
|
|
description: label.description ?? '',
|
|
})),
|
|
};
|
|
});
|