Identify changes before applying them

This commit is contained in:
Michael B. Gale
2026-03-13 19:10:18 +00:00
parent a5244bf7dd
commit 74dd691a45
+41 -1
View File
@@ -130,6 +130,46 @@ async function getReleaseBranches(client: ApiClient): Promise<string[]> {
return refs.data.map((ref) => ref.ref).sort();
}
/** Sets `checkNames` as required checks for `branch`. */
async function updateBranch(
client: ApiClient,
branch: string,
checkNames: Set<string>,
) {
// Query the current set of required checks for this branch.
const currentContexts = await client.rest.repos.getAllStatusCheckContexts({
...codeqlActionRepo,
branch,
});
// Identify which required checks we will remove and which ones we will add.
const currentCheckNames = new Set(currentContexts.data);
let additions = 0;
let removals = 0;
let unchanged = 0;
for (const currentCheck of currentCheckNames) {
if (!checkNames.has(currentCheck)) {
console.info(`- Removing '${currentCheck}' for branch '${branch}'`);
removals++;
} else {
unchanged++;
}
}
for (const newCheck of checkNames) {
if (!currentCheckNames.has(newCheck)) {
console.info(`+ Adding '${newCheck}' for branch '${branch}'`);
additions++;
}
}
console.info(
`For '${branch}': ${removals} removals; ${additions} additions; ${unchanged} unchanged`,
);
// TODO: actually perform the update
}
async function main(): Promise<void> {
const { values: options } = parseArgs({
options: {
@@ -197,7 +237,7 @@ async function main(): Promise<void> {
continue;
} else {
console.info(`Updating '${releaseBranch}'...`);
await updateBranch(client, releaseBranch, checkNames);
}
}