Skip to content

Commit 177631c

Browse files
committed
changes
1 parent 95eae13 commit 177631c

2 files changed

Lines changed: 54 additions & 54 deletions

File tree

packages/generate-changeset/index.ts

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type PackageJson = Packages["packages"][0]["packageJson"] & {
4343
};
4444

4545
async function run() {
46-
console.log(JSON.stringify(context, null, 2));
46+
// console.log(JSON.stringify(context, null, 2));
4747
const branch_name = getInput("branch_name");
4848

4949
if (branch_name.startsWith("changeset-release/")) {
@@ -91,12 +91,10 @@ async function run() {
9191
`Changeset file was edited manually. Skipping changeset generation.`
9292
);
9393

94-
// Check if PR has the approved label
9594
const has_approved_label = labels.some(
9695
(l) => l.name === "changeset:approved"
9796
);
98-
99-
// Variables for tracking state changes
97+
10098
let updated_has_approved_label = has_approved_label;
10199
let selection: any = null;
102100

@@ -144,7 +142,6 @@ async function run() {
144142
)
145143
);
146144

147-
// Handle label toggling if needed
148145
if (selection.should_toggle_label) {
149146
const approved_label_id = await client.get_or_create_label(
150147
"changeset:approved"
@@ -187,11 +184,11 @@ async function run() {
187184
return;
188185
}
189186

190-
// Use the updated label state after potential toggling
191-
const final_has_approved_label = comment?.body && selection?.should_toggle_label
192-
? updated_has_approved_label
193-
: has_approved_label;
194-
187+
const final_has_approved_label =
188+
comment?.body && selection?.should_toggle_label
189+
? updated_has_approved_label
190+
: has_approved_label;
191+
195192
const { pr_comment_content, changes } = create_changeset_comment({
196193
packages: versions,
197194
changelog: !valid ? message : changelog_entry_message,
@@ -228,12 +225,10 @@ async function run() {
228225
let packages_versions: undefined | [string, string | boolean][] = undefined;
229226
let manual_package_selection = false;
230227

231-
// Check if PR has the approved label
232228
const has_approved_label = labels.some(
233229
(l) => l.name === "changeset:approved"
234230
);
235-
236-
// Variables for tracking state changes
231+
237232
let updated_has_approved_label = has_approved_label;
238233
let selection: any = null;
239234

@@ -293,7 +288,6 @@ async function run() {
293288
info(`[Normal Mode] Using manual package versions from comment`);
294289
}
295290

296-
// Handle label toggling if needed
297291
if (selection.should_toggle_label) {
298292
const approved_label_id = await client.get_or_create_label(
299293
"changeset:approved"
@@ -378,11 +372,11 @@ async function run() {
378372
await exec("git", ["push"]);
379373
}
380374

381-
// Use the updated label state after potential toggling
382-
const final_has_approved_label = comment?.body && selection?.should_toggle_label
383-
? updated_has_approved_label
384-
: has_approved_label;
385-
375+
const final_has_approved_label =
376+
comment?.body && selection?.should_toggle_label
377+
? updated_has_approved_label
378+
: has_approved_label;
379+
386380
const { pr_comment_content, changes } = create_changeset_comment({
387381
packages: packages_versions,
388382
changelog: title,
@@ -394,7 +388,6 @@ async function run() {
394388
changelog_entry_type: type || "unknown",
395389
});
396390

397-
// Check if the comment needs updating
398391
if (changes) {
399392
info("[Normal Mode] Changeset comment has changes, updating...");
400393
const url = await client.upsert_comment({

packages/generate-changeset/utils.ts

Lines changed: 41 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -257,16 +257,18 @@ ${
257257
</details>
258258
`.trim();
259259

260-
// Check if the new comment is different from the previous comment
261-
// We normalize by removing URLs that might change
262-
const normalize = (text: string) => text.replace(/\(https:\/\/github.com[^]*\.md\)/g, "").trim();
263-
264-
const changes = !previous_comment || normalize(previous_comment) !== normalize(new_comment);
265-
260+
const normalize = (text: string) =>
261+
text.replace(/\(https:\/\/github.com[^]*\.md\)/g, "").trim();
262+
263+
const changes =
264+
!previous_comment || normalize(previous_comment) !== normalize(new_comment);
265+
266266
if (!changes && previous_comment) {
267-
console.log(`[create_changeset_comment] No changes detected, skipping comment update`);
267+
console.log(
268+
`[create_changeset_comment] No changes detected, skipping comment update`
269+
);
268270
}
269-
271+
270272
return {
271273
pr_comment_content: new_comment,
272274
changes,
@@ -310,7 +312,8 @@ export function check_for_manual_selection_and_approval(
310312
checkbox_checked: boolean;
311313
should_toggle_label?: boolean;
312314
} {
313-
if (!md_src) return { manual_package_selection: false, checkbox_checked: false };
315+
if (!md_src)
316+
return { manual_package_selection: false, checkbox_checked: false };
314317

315318
const new_ast = md_parser.parse(md_src);
316319

@@ -342,7 +345,6 @@ export function check_for_manual_selection_and_approval(
342345
});
343346
}
344347

345-
// Find the approval checkbox
346348
const approved_node: ListItem | undefined = find(new_ast, (node) => {
347349
return (
348350
node.type === "listItem" &&
@@ -351,38 +353,38 @@ export function check_for_manual_selection_and_approval(
351353
//@ts-ignore
352354
(node as ListItem)?.children[0],
353355
(inner_node) =>
354-
(inner_node as Text)?.value
355-
?.trim()
356-
?.includes("approve") &&
357-
(inner_node as Text)?.value
358-
?.trim()
359-
?.includes("checkbox")
356+
(inner_node as Text)?.value?.trim()?.includes("approve") &&
357+
(inner_node as Text)?.value?.trim()?.includes("checkbox")
360358
)
361359
);
362360
}) as ListItem | undefined;
363361

364362
const checkbox_checked = !!approved_node?.checked;
365-
363+
366364
// Determine if we should toggle the label
367365
// We should toggle if:
368366
// 1. The comment was edited by a human (not gradio-pr-bot)
369367
// 2. The checkbox state doesn't match the label state
370368
let should_toggle_label = false;
371-
372-
if (wasEdited && editor && editor !== 'gradio-pr-bot') {
373-
// Human edit - check if checkbox state differs from label state
374-
if (has_approved_label !== undefined && checkbox_checked !== has_approved_label) {
369+
370+
if (wasEdited && editor && editor !== "gradio-pr-bot") {
371+
if (
372+
has_approved_label !== undefined &&
373+
checkbox_checked !== has_approved_label
374+
) {
375375
should_toggle_label = true;
376-
console.log(`[check_for_manual_selection_and_approval] Label toggle needed: checkbox=${checkbox_checked}, label=${has_approved_label}`);
376+
console.log(
377+
`[check_for_manual_selection_and_approval] Label toggle needed: checkbox=${checkbox_checked}, label=${has_approved_label}`
378+
);
377379
}
378380
}
379-
381+
380382
console.log(`[check_for_manual_selection_and_approval] States:`, {
381383
manual_package_selection: !!manual_node?.checked,
382384
checkbox_checked,
383385
has_approved_label,
384386
should_toggle_label,
385-
editor
387+
editor,
386388
});
387389

388390
return {
@@ -556,33 +558,38 @@ export function get_client(token: string, owner: string, repo: string) {
556558
return url;
557559
}
558560
},
559-
561+
560562
async get_or_create_label(label_name: string): Promise<string | null> {
561563
try {
562-
const { repository: { label } } = await octokit.graphql<Record<string, any>>(
563-
GQL_GET_LABEL,
564-
{ owner, name: repo, label_name }
565-
);
564+
const {
565+
repository: { label },
566+
} = await octokit.graphql<Record<string, any>>(GQL_GET_LABEL, {
567+
owner,
568+
name: repo,
569+
label_name,
570+
});
566571
return label?.id || null;
567572
} catch (error) {
568-
console.log(`Label "${label_name}" not found, will need to be created manually`);
573+
console.log(
574+
`Label "${label_name}" not found, will need to be created manually`
575+
);
569576
return null;
570577
}
571578
},
572-
579+
573580
async add_label(pr_id: string, label_id: string) {
574581
console.log(`Adding label with ID ${label_id} to PR`);
575582
await octokit.graphql(GQL_ADD_LABELS, {
576583
pr_id,
577-
label_ids: [label_id]
584+
label_ids: [label_id],
578585
});
579586
},
580-
587+
581588
async remove_label(pr_id: string, label_id: string) {
582589
console.log(`Removing label with ID ${label_id} from PR`);
583590
await octokit.graphql(GQL_REMOVE_LABELS, {
584591
pr_id,
585-
label_ids: [label_id]
592+
label_ids: [label_id],
586593
});
587594
},
588595
};

0 commit comments

Comments
 (0)