Skip to content

Commit 8638392

Browse files
committed
gap-issues: create the gap-ledger label before filing (it must exist)
gh issue create --label requires the label to exist; the first run failed with 'could not add label: gap-ledger not found'. Ensure it idempotently (ignore the already-exists error) before opening issues.
1 parent 3099c2a commit 8638392

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

test/gap-issues.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ function readGaps(): Gap[] {
4545
function gh(args: string[]): string {
4646
return execFileSync('gh', args, { encoding: 'utf8', stdio: ['ignore', 'pipe', 'pipe'] });
4747
}
48+
// `gh issue create --label X` requires the label to EXIST — create it once (idempotent: ignore the
49+
// "already exists" error so re-runs are a no-op).
50+
function ensureLabel(): void {
51+
try { gh(['label', 'create', LABEL, '--color', 'D4C5F9', '--description', 'A valid-input flat-highlighter divergence found by the generative gap ledger (auto-filed/closed)']); }
52+
catch (e: any) { if (!/already exists/i.test(e?.stderr ?? e?.message ?? '')) throw e; }
53+
}
4854
// open `gap-ledger`-labelled issues → their fingerprint (from the body marker) → issue number
4955
function openIssues(): Map<string, number> {
5056
const raw = gh(['issue', 'list', '--label', LABEL, '--state', 'open', '--json', 'number,body', '--limit', '500']);
@@ -89,6 +95,7 @@ const toClose = [...existing!.entries()].filter(([id]) => !ledgerIds.has(id));
8995

9096
console.log(`gap ledger: ${gaps.length} gap(s) · open issues: ${existing!.size} · to open: ${toOpen.length} · to close: ${toClose.length}${DRY ? ' [DRY-RUN]' : ''}`);
9197

98+
if (!DRY && toOpen.length) ensureLabel();
9299
for (const g of toOpen) {
93100
console.log(` + OPEN ${g.id} ${title(g)}`);
94101
if (!DRY) { const url = gh(['issue', 'create', '--title', title(g), '--body', body(g), '--label', LABEL]).trim(); console.log(` → ${url}`); }

0 commit comments

Comments
 (0)