Skip to content

Commit 7479f9f

Browse files
committed
Identify changes before applying them
1 parent 99ca431 commit 7479f9f

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

pr-checks/sync-checks.ts

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,46 @@ async function getReleaseBranches(client: ApiClient): Promise<string[]> {
130130
return refs.data.map((ref) => ref.ref).sort();
131131
}
132132

133+
/** Sets `checkNames` as required checks for `branch`. */
134+
async function updateBranch(
135+
client: ApiClient,
136+
branch: string,
137+
checkNames: Set<string>,
138+
) {
139+
// Query the current set of required checks for this branch.
140+
const currentContexts = await client.rest.repos.getAllStatusCheckContexts({
141+
...codeqlActionRepo,
142+
branch,
143+
});
144+
145+
// Identify which required checks we will remove and which ones we will add.
146+
const currentCheckNames = new Set(currentContexts.data);
147+
let additions = 0;
148+
let removals = 0;
149+
let unchanged = 0;
150+
151+
for (const currentCheck of currentCheckNames) {
152+
if (!checkNames.has(currentCheck)) {
153+
console.info(`- Removing '${currentCheck}' for branch '${branch}'`);
154+
removals++;
155+
} else {
156+
unchanged++;
157+
}
158+
}
159+
for (const newCheck of checkNames) {
160+
if (!currentCheckNames.has(newCheck)) {
161+
console.info(`+ Adding '${newCheck}' for branch '${branch}'`);
162+
additions++;
163+
}
164+
}
165+
166+
console.info(
167+
`For '${branch}': ${removals} removals; ${additions} additions; ${unchanged} unchanged`,
168+
);
169+
170+
// TODO: actually perform the update
171+
}
172+
133173
async function main(): Promise<void> {
134174
const { values: options } = parseArgs({
135175
options: {
@@ -197,7 +237,7 @@ async function main(): Promise<void> {
197237
continue;
198238
} else {
199239
console.info(`Updating '${releaseBranch}'...`);
200-
240+
await updateBranch(client, releaseBranch, checkNames);
201241
}
202242
}
203243

0 commit comments

Comments
 (0)