Repository: JoshuaKGoldberg/template-typescript-node-package (ts)

Issue:
🐛 Bug: Repo labels don't detect existing labels without prefixes
### Bug Report Checklist

- [X] I have tried restarting my IDE and the issue persists.
- [X] I have pulled the latest `main` branch of the repository.
- [X] I have [searched for related issues](https://github.com/JoshuaKGoldberg/template-typescript-node-package/issues?q=is%3Aissue) and found none that matched my issue.

### Expected

When using `--mode create`, existing labels (e.g. `bug`) that match an outcome label (e.g. `type: bug`) should be edited to have that new name.

### Actual

I'm running through `--mode create` testing and seeing that existing labels like `bug` are getting deleted instead.

### Additional Info

_No response_

Pull request:
fix: respect stripped versions of outcome labels
## 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.

Patch:
diff --git a/src/steps/labels/getExistingEquivalentLabel.ts b/src/steps/labels/getExistingEquivalentLabel.ts
index 966752a..086b601 100644
--- a/src/steps/labels/getExistingEquivalentLabel.ts
+++ b/src/steps/labels/getExistingEquivalentLabel.ts
@@ -13,7 +13,8 @@ export function getExistingEquivalentLabel(
 		return (
 			existingLabel === outcomeLabel ||
 			existingLabel === outcomeTrimmed ||
-			aliases.get(existingLabel) === outcomeLabel
+			aliases.get(existingLabel) === outcomeLabel ||
+			existingLabel.replace(/\w+: (\w+)/, "$1") === outcomeLabel
 		);
 	});
 }
diff --git a/src/steps/labels/initializeRepositoryLabels.ts b/src/steps/labels/initializeRepositoryLabels.ts
index 168feaf..38b4145 100644
--- a/src/steps/labels/initializeRepositoryLabels.ts
+++ b/src/steps/labels/initializeRepositoryLabels.ts
@@ -15,6 +15,7 @@ export async function initializeRepositoryLabels() {
 			(await $`gh label list --json name`).stdout || "[]",
 		) as GhLabelData[]
 	).map(getLabelName);
+	const allowedLabels = new Set(outcomeLabels.map(getLabelName));
 
 	for (const outcome of outcomeLabels) {
 		const existingEquivalent = getExistingEquivalentLabel(
@@ -25,11 +26,14 @@ export async function initializeRepositoryLabels() {
 			? ["edit", existingEquivalent]
 			: ["create", outcome.name];
 
-		await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description}`;
+		if (existingEquivalent) {
+			allowedLabels.add(existingEquivalent);
+			await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description} --name ${outcome.name}`;
+		} else {
+			await $`gh label ${action} ${label} --color ${outcome.color} --description ${outcome.description}`;
+		}
 	}
 
-	const allowedLabels = new Set(outcomeLabels.map(getLabelName));
-
 	for (const existingLabel of existingLabels) {
 		if (!allowedLabels.has(existingLabel)) {
 			await $`gh label delete ${existingLabel} --yes`;


Test patch:
diff --git a/src/steps/labels/initializeRepositoryLabels.test.ts b/src/steps/labels/initializeRepositoryLabels.test.ts
index 0cb99af..940fd0d 100644
--- a/src/steps/labels/initializeRepositoryLabels.test.ts
+++ b/src/steps/labels/initializeRepositoryLabels.test.ts
@@ -57,11 +57,12 @@ describe("migrateRepositoryLabels", () => {
 		await initializeRepositoryLabels();
 
 		expect(mock$).toHaveBeenCalledWith(
-			["gh label ", " ", " --color ", " --description ", ""],
+			["gh label ", " ", " --color ", " --description ", " --name ", ""],
 			"edit",
 			"abc",
 			"000000",
 			"def ghi",
+			"abc",
 		);
 	});