From 74dd691a4550c112056a1b76df8b92a2c53644de Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Fri, 13 Mar 2026 19:10:18 +0000 Subject: [PATCH] Identify changes before applying them --- pr-checks/sync-checks.ts | 42 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pr-checks/sync-checks.ts b/pr-checks/sync-checks.ts index 38a6f599b..b1b2a8dd5 100755 --- a/pr-checks/sync-checks.ts +++ b/pr-checks/sync-checks.ts @@ -130,6 +130,46 @@ async function getReleaseBranches(client: ApiClient): Promise { return refs.data.map((ref) => ref.ref).sort(); } +/** Sets `checkNames` as required checks for `branch`. */ +async function updateBranch( + client: ApiClient, + branch: string, + checkNames: Set, +) { + // 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 { const { values: options } = parseArgs({ options: { @@ -197,7 +237,7 @@ async function main(): Promise { continue; } else { console.info(`Updating '${releaseBranch}'...`); - + await updateBranch(client, releaseBranch, checkNames); } }