Skip to content

Commit 7288701

Browse files
fix: respect stripped versions of outcome labels (#689)
## PR Checklist - [x] Addresses an existing open issue: fixes #687 - [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 Also checks for outcome labels whose stripped version (no prefix) matches the existing label.
1 parent 8514891 commit 7288701

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/steps/labels/getExistingEquivalentLabel.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ export function getExistingEquivalentLabel(
1313
return (
1414
existingLabel === outcomeLabel ||
1515
existingLabel === outcomeTrimmed ||
16-
aliases.get(existingLabel) === outcomeLabel
16+
aliases.get(existingLabel) === outcomeLabel ||
17+
existingLabel.replace(/\w+: (\w+)/, "$1") === outcomeLabel
1718
);
1819
});
1920
}

src/steps/labels/initializeRepositoryLabels.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,12 @@ describe("migrateRepositoryLabels", () => {
5757
await initializeRepositoryLabels();
5858

5959
expect(mock$).toHaveBeenCalledWith(
60-
["gh label ", " ", " --color ", " --description ", ""],
60+
["gh label ", " ", " --color ", " --description ", " --name ", ""],
6161
"edit",
6262
"abc",
6363
"000000",
6464
"def ghi",
65+
"abc",
6566
);
6667
});
6768

src/steps/labels/initializeRepositoryLabels.ts

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ export async function initializeRepositoryLabels() {
1515
(await $`gh label list --json name`).stdout || "[]",
1616
) as GhLabelData[]
1717
).map(getLabelName);
18+
const allowedLabels = new Set(outcomeLabels.map(getLabelName));
1819

1920
for (const outcome of outcomeLabels) {
2021
const existingEquivalent = getExistingEquivalentLabel(
@@ -25,11 +26,14 @@ export async function initializeRepositoryLabels() {
2526
? ["edit", existingEquivalent]
2627
: ["create", outcome.name];
2728

28-
await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description}`;
29+
if (existingEquivalent) {
30+
allowedLabels.add(existingEquivalent);
31+
await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description} --name ${outcome.name}`;
32+
} else {
33+
await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description}`;
34+
}
2935
}
3036

31-
const allowedLabels = new Set(outcomeLabels.map(getLabelName));
32-
3337
for (const existingLabel of existingLabels) {
3438
if (!allowedLabels.has(existingLabel)) {
3539
await $`gh label delete ${existingLabel} --yes`;

0 commit comments

Comments
 (0)