mirror of
https://github.com/github/codeql-action.git
synced 2026-04-01 01:02:17 +00:00
Add --verbose option
This commit is contained in:
@@ -7,7 +7,12 @@ Tests for the sync-checks.ts script
|
||||
import * as assert from "node:assert/strict";
|
||||
import { describe, it } from "node:test";
|
||||
|
||||
import { CheckInfo, Exclusions, removeExcluded } from "./sync-checks";
|
||||
import { CheckInfo, Exclusions, Options, removeExcluded } from "./sync-checks";
|
||||
|
||||
const defaultOptions: Options = {
|
||||
apply: false,
|
||||
verbose: false,
|
||||
};
|
||||
|
||||
const toCheckInfo = (name: string) =>
|
||||
({ context: name, app_id: -1 }) satisfies CheckInfo;
|
||||
@@ -27,12 +32,17 @@ const emptyExclusions: Exclusions = {
|
||||
|
||||
describe("removeExcluded", async () => {
|
||||
await it("retains all checks if no exclusions are configured", () => {
|
||||
const retained = removeExcluded(emptyExclusions, testChecks);
|
||||
const retained = removeExcluded(
|
||||
defaultOptions,
|
||||
emptyExclusions,
|
||||
testChecks,
|
||||
);
|
||||
assert.deepEqual(retained, testChecks);
|
||||
});
|
||||
|
||||
await it("removes exact matches", () => {
|
||||
const retained = removeExcluded(
|
||||
defaultOptions,
|
||||
{ ...emptyExclusions, is: ["CodeQL", "Update"] },
|
||||
testChecks,
|
||||
);
|
||||
@@ -41,6 +51,7 @@ describe("removeExcluded", async () => {
|
||||
|
||||
await it("removes partial matches", () => {
|
||||
const retained = removeExcluded(
|
||||
defaultOptions,
|
||||
{ ...emptyExclusions, contains: ["https://", "PR Check"] },
|
||||
testChecks,
|
||||
);
|
||||
|
||||
@@ -17,13 +17,15 @@ import {
|
||||
} from "./config";
|
||||
|
||||
/** Represents the command-line options. */
|
||||
interface Options {
|
||||
export interface Options {
|
||||
/** The token to use to authenticate to the GitHub API. */
|
||||
token?: string;
|
||||
/** The git ref to use the checks for. */
|
||||
ref?: string;
|
||||
/** Whether to actually apply the changes or not. */
|
||||
apply: boolean;
|
||||
/** Whether to output additional information. */
|
||||
verbose: boolean;
|
||||
}
|
||||
|
||||
/** Identifies the CodeQL Action repository. */
|
||||
@@ -69,10 +71,13 @@ export interface CheckInfo {
|
||||
|
||||
/** Removes entries from `checkInfos` based the configuration. */
|
||||
export function removeExcluded(
|
||||
options: Options,
|
||||
exclusions: Exclusions,
|
||||
checkInfos: CheckInfo[],
|
||||
): CheckInfo[] {
|
||||
console.log(exclusions);
|
||||
if (options.verbose) {
|
||||
console.log(exclusions);
|
||||
}
|
||||
|
||||
return checkInfos.filter((checkInfo) => {
|
||||
if (exclusions.is.includes(checkInfo.context)) {
|
||||
@@ -98,6 +103,7 @@ export function removeExcluded(
|
||||
|
||||
/** Gets a list of check run names for `ref`. */
|
||||
async function getChecksFor(
|
||||
options: Options,
|
||||
client: ApiClient,
|
||||
ref: string,
|
||||
): Promise<CheckInfo[]> {
|
||||
@@ -133,7 +139,7 @@ async function getChecksFor(
|
||||
// Load the configuration for which checks to exclude and apply it before
|
||||
// returning the checks.
|
||||
const exclusions = loadExclusions();
|
||||
return removeExcluded(exclusions, checkInfos);
|
||||
return removeExcluded(options, exclusions, checkInfos);
|
||||
}
|
||||
|
||||
/** Gets the current list of release branches. */
|
||||
@@ -224,6 +230,11 @@ async function main(): Promise<void> {
|
||||
type: "boolean",
|
||||
default: false,
|
||||
},
|
||||
// Whether to output additional information.
|
||||
verbose: {
|
||||
type: "boolean",
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
strict: true,
|
||||
});
|
||||
@@ -244,7 +255,7 @@ async function main(): Promise<void> {
|
||||
|
||||
// Find the check runs for the specified `ref` that we will later set as the required checks
|
||||
// for the main and release branches.
|
||||
const checkInfos = await getChecksFor(client, options.ref);
|
||||
const checkInfos = await getChecksFor(options, client, options.ref);
|
||||
const checkNames = new Set(checkInfos.map((info) => info.context));
|
||||
|
||||
// Update the main branch.
|
||||
|
||||
Reference in New Issue
Block a user