forked from catppuccin/userstyles
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlabels.ts
More file actions
98 lines (88 loc) 路 2.89 KB
/
Copy pathlabels.ts
File metadata and controls
98 lines (88 loc) 路 2.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import type { UserstylesSchema } from "@/types/mod.ts";
import { REPO_ROOT } from "@/constants.ts";
import * as path from "@std/path";
import * as yaml from "@std/yaml";
import { type ColorName, flavors } from "@catppuccin/palette";
import { writeWithPreamble } from "@/generate/utils.ts";
/**
* Macchiato color definitions as hex values.
*/
const macchiatoHex = flavors.macchiato.colorEntries
.reduce((acc, [identifier, { hex }]) => {
acc[identifier] = hex;
return acc;
}, {} as Record<ColorName, string>);
const toIssueLabel = (key: string) => `lbl:${key}`;
const toIssueLabelRegex = (key: string) => `/${toIssueLabel(key)}(,.*)?$/gm`;
const toPrLabel = (key: string) => `styles/${key}/**/*`;
export async function syncIssueLabels(userstyles: UserstylesSchema.Userstyles) {
// .github/issue-labeler.yml
await writeWithPreamble(
path.join(REPO_ROOT, ".github/issue-labeler.yml"),
yaml.stringify(
Object.entries(userstyles)
.reduce((acc, [key, { supports }]) => {
acc[key.toString()] = [toIssueLabelRegex(key)];
Object.keys(supports ?? {}).forEach((key) => {
acc[key.toString()] = [toIssueLabelRegex(key)];
});
return acc;
}, {} as Record<string, string[]>),
),
);
// .github/ISSUE_TEMPLATE/userstyle.yml
const userstyleIssueTemplate = Deno.readTextFileSync(path.join(
REPO_ROOT,
"scripts/generate/templates/userstyle-issue.yml",
));
await Deno.writeTextFile(
path.join(REPO_ROOT, ".github/ISSUE_TEMPLATE/userstyle.yml"),
userstyleIssueTemplate.replace(
`"$LABELS"`,
`${
Object.entries(userstyles)
.flatMap(([slug, { supports }]) =>
[slug, ...Object.keys(supports ?? {})].map((key) =>
`"${toIssueLabel(key)}"`
)
)
.sort()
.join(", ")
}`,
),
);
// .github/pr-labeler.yml
await writeWithPreamble(
path.join(REPO_ROOT, ".github/pr-labeler.yml"),
yaml.stringify(
Object.entries(userstyles)
.reduce((acc, [key, { supports }]) => {
acc[key] = toPrLabel(key);
Object.keys(supports ?? {}).forEach((supportedKey) => {
acc[supportedKey] = toPrLabel(key);
});
return acc;
}, {} as Record<string, string>),
),
);
// .github/labels.yml
await writeWithPreamble(
path.join(REPO_ROOT, ".github/labels.yml"),
yaml.stringify(
Object.entries(userstyles).flatMap(([key, style]) => [
{
name: key,
description: style.name,
color: style.color ? macchiatoHex[style.color] : macchiatoHex.blue,
},
...Object.entries(style.supports ?? {}).map((
[supportedKey, { name }],
) => ({
name: supportedKey,
description: name,
color: style.color ? macchiatoHex[style.color] : macchiatoHex.blue,
})),
]),
),
);
}