Skip to content

Commit 07f235e

Browse files
committed
Add --verbose option
1 parent 9fd40ff commit 07f235e

File tree

2 files changed

+28
-6
lines changed

2 files changed

+28
-6
lines changed

pr-checks/sync-checks.test.ts

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,12 @@ Tests for the sync-checks.ts script
77
import * as assert from "node:assert/strict";
88
import { describe, it } from "node:test";
99

10-
import { CheckInfo, Exclusions, removeExcluded } from "./sync-checks";
10+
import { CheckInfo, Exclusions, Options, removeExcluded } from "./sync-checks";
11+
12+
const defaultOptions: Options = {
13+
apply: false,
14+
verbose: false,
15+
};
1116

1217
const toCheckInfo = (name: string) =>
1318
({ context: name, app_id: -1 }) satisfies CheckInfo;
@@ -27,12 +32,17 @@ const emptyExclusions: Exclusions = {
2732

2833
describe("removeExcluded", async () => {
2934
await it("retains all checks if no exclusions are configured", () => {
30-
const retained = removeExcluded(emptyExclusions, testChecks);
35+
const retained = removeExcluded(
36+
defaultOptions,
37+
emptyExclusions,
38+
testChecks,
39+
);
3140
assert.deepEqual(retained, testChecks);
3241
});
3342

3443
await it("removes exact matches", () => {
3544
const retained = removeExcluded(
45+
defaultOptions,
3646
{ ...emptyExclusions, is: ["CodeQL", "Update"] },
3747
testChecks,
3848
);
@@ -41,6 +51,7 @@ describe("removeExcluded", async () => {
4151

4252
await it("removes partial matches", () => {
4353
const retained = removeExcluded(
54+
defaultOptions,
4455
{ ...emptyExclusions, contains: ["https://", "PR Check"] },
4556
testChecks,
4657
);

pr-checks/sync-checks.ts

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,15 @@ import {
1717
} from "./config";
1818

1919
/** Represents the command-line options. */
20-
interface Options {
20+
export interface Options {
2121
/** The token to use to authenticate to the GitHub API. */
2222
token?: string;
2323
/** The git ref to use the checks for. */
2424
ref?: string;
2525
/** Whether to actually apply the changes or not. */
2626
apply: boolean;
27+
/** Whether to output additional information. */
28+
verbose: boolean;
2729
}
2830

2931
/** Identifies the CodeQL Action repository. */
@@ -69,10 +71,13 @@ export interface CheckInfo {
6971

7072
/** Removes entries from `checkInfos` based the configuration. */
7173
export function removeExcluded(
74+
options: Options,
7275
exclusions: Exclusions,
7376
checkInfos: CheckInfo[],
7477
): CheckInfo[] {
75-
console.log(exclusions);
78+
if (options.verbose) {
79+
console.log(exclusions);
80+
}
7681

7782
return checkInfos.filter((checkInfo) => {
7883
if (exclusions.is.includes(checkInfo.context)) {
@@ -98,6 +103,7 @@ export function removeExcluded(
98103

99104
/** Gets a list of check run names for `ref`. */
100105
async function getChecksFor(
106+
options: Options,
101107
client: ApiClient,
102108
ref: string,
103109
): Promise<CheckInfo[]> {
@@ -133,7 +139,7 @@ async function getChecksFor(
133139
// Load the configuration for which checks to exclude and apply it before
134140
// returning the checks.
135141
const exclusions = loadExclusions();
136-
return removeExcluded(exclusions, checkInfos);
142+
return removeExcluded(options, exclusions, checkInfos);
137143
}
138144

139145
/** Gets the current list of release branches. */
@@ -224,6 +230,11 @@ async function main(): Promise<void> {
224230
type: "boolean",
225231
default: false,
226232
},
233+
// Whether to output additional information.
234+
verbose: {
235+
type: "boolean",
236+
default: false,
237+
},
227238
},
228239
strict: true,
229240
});
@@ -244,7 +255,7 @@ async function main(): Promise<void> {
244255

245256
// Find the check runs for the specified `ref` that we will later set as the required checks
246257
// for the main and release branches.
247-
const checkInfos = await getChecksFor(client, options.ref);
258+
const checkInfos = await getChecksFor(options, client, options.ref);
248259
const checkNames = new Set(checkInfos.map((info) => info.context));
249260

250261
// Update the main branch.

0 commit comments

Comments
 (0)