Skip to content

Commit f04e098

Browse files
committed
feat: update keystatic behavior
1 parent 388dc69 commit f04e098

15 files changed

Lines changed: 1332 additions & 154 deletions

‎.github/CODEOWNERS‎

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,14 @@
1-
# Code and repository configuration default to the current maintainer.
2-
* @hieuddo
1+
# Code, repository configuration, and People updates default to the current maintainer.
2+
* @manhkhanhad
33

4-
# Keep the publishing system and its ownership rules under technical review.
5-
/apps/admin/** @hieuddo
6-
/.github/workflows/nextjs.yml @hieuddo
7-
/.github/workflows/deploy-admin.yml @hieuddo
8-
/.github/** @hieuddo
4+
# Blog posts and post uploads auto-publish after CI and preview checks pass.
5+
/content/posts/**
6+
/public/uploads/**
7+
8+
# People directory and publishing infrastructure require maintainer review.
9+
/content/people/** @manhkhanhad
10+
/public/team/members/** @manhkhanhad
11+
/apps/admin/** @manhkhanhad
12+
/.github/workflows/nextjs.yml @manhkhanhad
13+
/.github/workflows/deploy-admin.yml @manhkhanhad
14+
/.github/** @manhkhanhad

‎.github/scripts/classify-keystatic-changes.mjs‎

Lines changed: 98 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,53 @@ function hasPrefix(filename, prefixes) {
88
return prefixes.some((prefix) => filename.startsWith(prefix));
99
}
1010

11+
function extractSlugs(paths) {
12+
const slugs = new Set();
13+
for (const filename of paths) {
14+
const postMatch = filename.match(/^content\/posts\/([^/]+)\.md$/);
15+
if (postMatch) {
16+
slugs.add(postMatch[1]);
17+
continue;
18+
}
19+
const uploadMatch = filename.match(/^public\/uploads\/([^/]+)\//);
20+
if (uploadMatch && !/^\d{4}$/.test(uploadMatch[1])) {
21+
slugs.add(uploadMatch[1]);
22+
continue;
23+
}
24+
const personMatch = filename.match(/^content\/people\/([^/]+)\.json$/);
25+
if (personMatch) {
26+
slugs.add(personMatch[1]);
27+
continue;
28+
}
29+
const memberPhotoMatch = filename.match(
30+
/^public\/team\/members\/([^/]+)\//,
31+
);
32+
if (memberPhotoMatch) {
33+
slugs.add(memberPhotoMatch[1]);
34+
}
35+
}
36+
return [...slugs].sort();
37+
}
38+
39+
function buildSummaryTitle(kind, slugs) {
40+
const prefixByKind = {
41+
blog: "Keystatic (Blog)",
42+
people: "Keystatic (People)",
43+
mixed: "Keystatic (Editorial)",
44+
ineligible: "Keystatic (Manual review)",
45+
empty: "Keystatic",
46+
};
47+
const prefix = prefixByKind[kind] || "Keystatic";
48+
if (slugs.length === 0) {
49+
return `${prefix}: publish changes`;
50+
}
51+
const shown = slugs.slice(0, 3).join(", ");
52+
const suffix = slugs.length > 3 ? ` (+${slugs.length - 3} more)` : "";
53+
return `${prefix}: ${shown}${suffix}`;
54+
}
55+
1156
export function classifyPaths(inputPaths) {
12-
const paths = [...new Set(inputPaths)].sort();
57+
const paths = [...new Set(inputPaths.filter(Boolean))].sort();
1358
const blogPaths = paths.filter((filename) =>
1459
hasPrefix(filename, BLOG_PREFIXES),
1560
);
@@ -28,12 +73,19 @@ export function classifyPaths(inputPaths) {
2873
else if (peoplePaths.length > 0) kind = "people";
2974
else if (blogPaths.length > 0) kind = "blog";
3075

76+
const eligible = paths.length > 0 && ineligiblePaths.length === 0;
77+
const hasPeople = peoplePaths.length > 0;
78+
const slugs = extractSlugs(paths);
79+
3180
return {
32-
eligible: paths.length > 0 && ineligiblePaths.length === 0,
33-
hasPeople: peoplePaths.length > 0,
81+
autoMergeBlog: eligible && kind === "blog",
82+
eligible,
83+
hasPeople,
3484
kind,
3585
paths,
3686
ineligiblePaths,
87+
slugs,
88+
summaryTitle: buildSummaryTitle(kind, slugs),
3789
};
3890
}
3991

@@ -66,31 +118,52 @@ function writeOutputs(result) {
66118
const outputPath = process.env.GITHUB_OUTPUT;
67119
if (!outputPath) return;
68120

121+
const safeTitle = result.summaryTitle.replace(/[\r\n]+/g, " ").trim();
69122
fs.appendFileSync(
70123
outputPath,
71124
`${[
125+
`auto_merge_blog=${result.autoMergeBlog}`,
72126
`eligible=${result.eligible}`,
73127
`has_people=${result.hasPeople}`,
74128
`kind=${result.kind}`,
75129
`ineligible_count=${result.ineligiblePaths.length}`,
76130
`ineligible_paths=${result.ineligiblePaths.join(", ")}`,
131+
`summary_title=${safeTitle}`,
77132
].join("\n")}\n`,
78133
);
79134
}
80135

81136
function selfTest() {
82-
assert.deepEqual(classifyPaths(["content/posts/hello.md"]).kind, "blog");
83-
assert.deepEqual(
84-
classifyPaths([
85-
"content/people/alex.json",
86-
"public/team/members/alex/photo.jpg",
87-
]).kind,
88-
"people",
89-
);
90-
assert.deepEqual(
91-
classifyPaths(["content/posts/hello.md", "content/people/alex.json"]).kind,
92-
"mixed",
93-
);
137+
const blogOnly = classifyPaths([
138+
"content/posts/hello.md",
139+
"public/uploads/hello/cover.jpg",
140+
]);
141+
assert.equal(blogOnly.kind, "blog");
142+
assert.equal(blogOnly.eligible, true);
143+
assert.equal(blogOnly.hasPeople, false);
144+
assert.equal(blogOnly.autoMergeBlog, true);
145+
assert.equal(blogOnly.summaryTitle, "Keystatic (Blog): hello");
146+
147+
const peopleOnly = classifyPaths([
148+
"content/people/alex.json",
149+
"public/team/members/alex/photo.jpg",
150+
]);
151+
assert.equal(peopleOnly.kind, "people");
152+
assert.equal(peopleOnly.eligible, true);
153+
assert.equal(peopleOnly.hasPeople, true);
154+
assert.equal(peopleOnly.autoMergeBlog, false);
155+
assert.equal(peopleOnly.summaryTitle, "Keystatic (People): alex");
156+
157+
const mixed = classifyPaths([
158+
"content/posts/hello.md",
159+
"content/people/alex.json",
160+
]);
161+
assert.equal(mixed.kind, "mixed");
162+
assert.equal(mixed.eligible, true);
163+
assert.equal(mixed.hasPeople, true);
164+
assert.equal(mixed.autoMergeBlog, false);
165+
assert.equal(mixed.summaryTitle, "Keystatic (Editorial): alex, hello");
166+
94167
assert.equal(
95168
classifyPaths(["content/posts/hello.md", "src/app/page.tsx"]).eligible,
96169
false,
@@ -128,8 +201,17 @@ if (args[0] === "--self-test") {
128201
const result = classifyGitHubFiles(parsed, expectedCount);
129202
writeOutputs(result);
130203
console.log(JSON.stringify(result, null, 2));
204+
} else if (args[0] === "--paths-file" && args[1]) {
205+
const lines = fs
206+
.readFileSync(args[1], "utf8")
207+
.split(/\r?\n/)
208+
.map((line) => line.trim())
209+
.filter(Boolean);
210+
const result = classifyPaths(lines);
211+
writeOutputs(result);
212+
console.log(JSON.stringify(result, null, 2));
131213
} else {
132214
throw new Error(
133-
"Usage: classify-keystatic-changes.mjs --self-test | --github-json <file>",
215+
"Usage: classify-keystatic-changes.mjs --self-test | --github-json <file> | --paths-file <file>",
134216
);
135217
}

0 commit comments

Comments
 (0)