Skip to content

Commit 79e342c

Browse files
feat: delete unnecessary labels on setup (#419)
## PR Checklist - [x] Addresses an existing open issue: fixes #331 - [x] That issue was marked as [`status: accepting prs`](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aopen+is%3Aissue+label%3A%22status%3A+accepting+prs%22) - [x] Steps in [CONTRIBUTING.md](https://github.com/JoshuaKGoldberg/template-typescript-node-package/blob/main/.github/CONTRIBUTING.md) were taken ## Overview After hydrating allowed labels, any remaining (not allowed) existing label is deleted with [`gh label delete`](https://cli.github.com/manual/gh_label_delete).
1 parent ee71bbb commit 79e342c

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

script/setup.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -506,20 +506,30 @@ try {
506506

507507
await withSpinner(
508508
async () => {
509+
const getLabelName = (label) => label.name;
510+
509511
const existingLabels = JSON.parse(
510512
(await $`gh label list --json name`).stdout || "[]"
511-
);
513+
).map(getLabelName);
512514

513515
const outcomeLabels = await readFileAsJSON("./script/labels.json");
514516

515517
for (const outcome of outcomeLabels) {
516518
const action = existingLabels.some(
517-
(existing) => existing.name === outcome.name
519+
(existing) => existing === outcome.name
518520
)
519521
? "edit"
520522
: "create";
521523
await $`gh label ${action} ${outcome.name} --color ${outcome.color} --description ${outcome.description}`;
522524
}
525+
526+
const allowedLabels = new Set(outcomeLabels.map(getLabelName));
527+
528+
for (const existingLabel of existingLabels) {
529+
if (!allowedLabels.has(existingLabel)) {
530+
await $`gh label delete ${existingLabel} --yes`;
531+
}
532+
}
523533
},
524534
{
525535
startText: `Hydrating repository labels...`,

0 commit comments

Comments
 (0)