Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
timotheeguerin committed May 11, 2024
1 parent 4a9bf4a commit 4dff111
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions eng/common/scripts/sync-labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,10 @@ async function main() {
}

function logLabels(message: string, labels: Label[]) {
if (labels.length === 0) {
console.log(message, pc.cyan("none"));
return;
}
console.log(message);
const max = labels.reduce((max, label) => Math.max(max, label.name.length), 0);
for (const label of labels) {
Expand Down Expand Up @@ -82,16 +86,20 @@ async function updateGithubLabels(labels: Label[], options: UpdateGithubLabelOpt
}
exitingLabelMap.delete(label.name);
}
const labelsToDelete = Array.from(exitingLabelMap.values()).map((x) => x.name);
const labelsToDelete = Array.from(exitingLabelMap.values());
logLabels("Labels to update", labelToUpdate);
logLabels("Labels to create", labelsToCreate);
console.log("Labels to delete", labelsToDelete);
logLabels("Labels to delete", labelsToDelete as any);
console.log("");

logAction("Applying changes", options);
await updateLabels(octokit, labelToUpdate, options);
await createLabels(octokit, labelsToCreate, options);
await deleteLabels(octokit, labelsToDelete, options);
await deleteLabels(
octokit,
labelsToDelete.map((x) => x.name),
options
);
logAction("Done applying changes", options);
}

Expand All @@ -101,7 +109,7 @@ async function fetchAllLabels(octokit: Octokit) {
}

function logAction(message: string, options: UpdateGithubLabelOptions) {
const prefix = options.dryRun ? "[dry-run] " : "";
const prefix = options.dryRun ? `${pc.gray("[dry-run]")} ` : "";
console.log(prefix + message);
}

Expand Down

0 comments on commit 4dff111

Please sign in to comment.