Skip to content

Commit 211b0ad

Browse files
committed
modify changeset generation
1 parent 8378966 commit 211b0ad

3 files changed

Lines changed: 62 additions & 10 deletions

File tree

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
node_modules
2-
packages/*/dist
2+
packages/*/dist
3+
CLAUDE.md

packages/generate-changeset/index.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import * as human_id from "human-id";
1515
import {
1616
create_changeset_comment,
1717
get_frontmatter_versions,
18-
check_for_manual_selection,
18+
check_for_manual_selection_and_approval,
1919
get_type_from_linked_issues,
2020
get_version_from_linked_issues,
2121
get_version_from_label,
@@ -91,6 +91,14 @@ async function run() {
9191
`Changeset file was edited manually. Skipping changeset generation.`
9292
);
9393

94+
let approved = false;
95+
96+
if (comment?.body) {
97+
approved = check_for_manual_selection_and_approval(
98+
comment?.body
99+
).approved;
100+
}
101+
94102
const versions = get_frontmatter_versions(old_changeset_content) || [];
95103

96104
const changelog_entry = old_changeset_content
@@ -116,6 +124,7 @@ async function run() {
116124
changeset_content: old_changeset_content,
117125
changeset_url: `https://github.com/${source_repo_name}/edit/${source_branch_name}/${changeset_path}`,
118126
previous_comment: comment?.body,
127+
approved,
119128
});
120129

121130
if (changes) {
@@ -142,9 +151,9 @@ async function run() {
142151

143152
let packages_versions: undefined | [string, string | boolean][] = undefined;
144153
let manual_package_selection = false;
145-
154+
let approved = false;
146155
if (comment?.body) {
147-
const selection = check_for_manual_selection(comment.body);
156+
const selection = check_for_manual_selection_and_approval(comment.body);
148157

149158
manual_package_selection = selection.manual_package_selection;
150159

@@ -155,6 +164,8 @@ async function run() {
155164
) {
156165
packages_versions = selection.versions;
157166
}
167+
168+
approved = selection.approved;
158169
}
159170

160171
let version =
@@ -225,6 +236,7 @@ async function run() {
225236
manual_package_selection,
226237
changeset_content,
227238
changeset_url: `https://github.com/${source_repo_name}/edit/${source_branch_name}/${changeset_path}`,
239+
approved,
228240
});
229241

230242
// is pr body and generate body different?
@@ -243,6 +255,7 @@ async function run() {
243255

244256
// this always happens
245257
setOutput("skipped", "false");
258+
setOutput("approved", approved.toString());
246259
}
247260

248261
run();

packages/generate-changeset/utils.ts

Lines changed: 44 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ export function create_changeset_comment({
169169
changeset_content,
170170
changeset_url,
171171
previous_comment,
172+
approved,
172173
}: {
173174
packages: [string, string | boolean][];
174175
changelog: string;
@@ -177,6 +178,7 @@ export function create_changeset_comment({
177178
changeset_content: string;
178179
changeset_url: string;
179180
previous_comment?: string;
181+
approved: boolean;
180182
}) {
181183
const new_comment = `<!-- tag=changesets_gradio -->
182184
@@ -189,21 +191,35 @@ export function create_changeset_comment({
189191
}
190192
191193
${create_version_table(packages)}
192-
${manual_package_selection ? create_package_checklist(packages) : ""}
193-
${generate_mode_description(manual_package_selection, manual_mode)}
194194
195-
196-
#### ${packages.length ? "With the following changelog entry." : ""}
195+
---
197196
198197
${format_changelog_preview(changelog, packages)}
199198
199+
---
200+
200201
${
201202
packages.length
202203
? manual_mode
203204
? "⚠️ _The changeset file for this pull request has been modified manually, so the changeset generation bot has been disabled. To go back into automatic mode, delete the changeset file._"
204205
: "_Maintainers or the PR author can modify the PR title to modify this entry._"
205206
: ""
206207
}
208+
209+
---
210+
211+
${
212+
approved
213+
? "✅ Approved by maintainers."
214+
: "‼️ Changeset not approved by maintainers."
215+
}
216+
217+
${
218+
approved
219+
? "- [x] Maintainers can unapprove the changeset by selecting this checkbox."
220+
: "- [ ] Maintainers can approve the changeset by selecting this checkbox."
221+
}
222+
207223
<details><summary>
208224
209225
#### Something isn't right?</summary>
@@ -252,11 +268,12 @@ export function get_frontmatter_versions(
252268
return false;
253269
}
254270

255-
export function check_for_manual_selection(md_src: string): {
271+
export function check_for_manual_selection_and_approval(md_src: string): {
256272
manual_package_selection: boolean;
257273
versions?: [string, boolean][];
274+
approved: boolean;
258275
} {
259-
if (!md_src) return { manual_package_selection: false };
276+
if (!md_src) return { manual_package_selection: false, approved: false };
260277

261278
const new_ast = md_parser.parse(md_src);
262279

@@ -288,9 +305,30 @@ export function check_for_manual_selection(md_src: string): {
288305
});
289306
}
290307

308+
const approved_node: ListItem | undefined = find(new_ast, (node) => {
309+
return (
310+
node.type === "listItem" &&
311+
(node as ListItem)?.checked != null &&
312+
!!find(
313+
//@ts-ignore
314+
(node as ListItem)?.children[0],
315+
(inner_node) =>
316+
(inner_node as Text)?.value
317+
?.trim()
318+
?.startsWith("Maintainers can approve the changeset") ||
319+
(inner_node as Text)?.value
320+
?.trim()
321+
?.startsWith(
322+
"Maintainers can unnaprove the changeset by selecting this checkbox."
323+
)
324+
)
325+
);
326+
}) as ListItem | undefined;
327+
291328
return {
292329
manual_package_selection: !!manual_node?.checked,
293330
versions: manual_node ? versions : undefined,
331+
approved: !!approved_node?.checked,
294332
};
295333
}
296334

0 commit comments

Comments
 (0)