Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
AugmentationProperties: add defaultQueryFilters
This commit adds a defaultQueryFilters field to AugmentationProperties
and incorporates its value into the augmented Code Scanning config.
However, in this commit defaultQueryFilters is always empty, so there is
not yet any actual behavior change.
  • Loading branch information
cklin committed Mar 27, 2025
commit da967b1adeb377e391d8fcc4acedc6775f3e22f6
9 changes: 9 additions & 0 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1274,6 +1274,15 @@ async function generateCodeScanningConfig(
if (Array.isArray(augmentedConfig.packs) && !augmentedConfig.packs.length) {
delete augmentedConfig.packs;
}

augmentedConfig["query-filters"] = [
...(config.augmentationProperties.defaultQueryFilters || []),
...(augmentedConfig["query-filters"] || []),
];
if (augmentedConfig["query-filters"]?.length === 0) {
delete augmentedConfig["query-filters"];
}

logger.info(
`Writing augmented user configuration file to ${codeScanningConfigFile}`,
);
Expand Down
18 changes: 12 additions & 6 deletions src/config-utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -809,11 +809,12 @@ const calculateAugmentationMacro = test.macro({
languages: Language[],
expectedAugmentationProperties: configUtils.AugmentationProperties,
) => {
const actualAugmentationProperties = configUtils.calculateAugmentation(
rawPacksInput,
rawQueriesInput,
languages,
);
const actualAugmentationProperties =
await configUtils.calculateAugmentation(
rawPacksInput,
rawQueriesInput,
languages,
);
t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties);
},
title: (_, title) => `Calculate Augmentation: ${title}`,
Expand All @@ -830,6 +831,7 @@ test(
queriesInput: undefined,
packsInputCombines: false,
packsInput: undefined,
defaultQueryFilters: [],
} as configUtils.AugmentationProperties,
);

Expand All @@ -844,6 +846,7 @@ test(
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
packsInputCombines: false,
packsInput: undefined,
defaultQueryFilters: [],
} as configUtils.AugmentationProperties,
);

Expand All @@ -858,6 +861,7 @@ test(
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
packsInputCombines: false,
packsInput: undefined,
defaultQueryFilters: [],
} as configUtils.AugmentationProperties,
);

Expand All @@ -872,6 +876,7 @@ test(
queriesInput: undefined,
packsInputCombines: false,
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
defaultQueryFilters: [],
} as configUtils.AugmentationProperties,
);

Expand All @@ -886,6 +891,7 @@ test(
queriesInput: undefined,
packsInputCombines: true,
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
defaultQueryFilters: [],
} as configUtils.AugmentationProperties,
);

Expand All @@ -898,7 +904,7 @@ const calculateAugmentationErrorMacro = test.macro({
languages: Language[],
expectedError: RegExp | string,
) => {
t.throws(
await t.throwsAsync(
() =>
configUtils.calculateAugmentation(
rawPacksInput,
Expand Down
18 changes: 14 additions & 4 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,10 +173,16 @@ export interface AugmentationProperties {
* Whether or not the packs input combines with the packs in the config.
*/
packsInputCombines: boolean;

/**
* The packs input from the `with` block of the action declaration
*/
packsInput?: string[];

/**
* Default query filters to apply to the queries in the config.
*/
defaultQueryFilters?: QueryFilter[];
}

/**
Expand All @@ -188,6 +194,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
packsInputCombines: false,
packsInput: undefined,
queriesInput: undefined,
defaultQueryFilters: [],
};
export type Packs = Partial<Record<Language, string[]>>;

Expand Down Expand Up @@ -461,7 +468,7 @@ export async function getDefaultConfig({
logger,
);

const augmentationProperties = calculateAugmentation(
const augmentationProperties = await calculateAugmentation(
packsInput,
queriesInput,
languages,
Expand Down Expand Up @@ -567,7 +574,7 @@ async function loadConfig({
logger,
);

const augmentationProperties = calculateAugmentation(
const augmentationProperties = await calculateAugmentation(
packsInput,
queriesInput,
languages,
Expand Down Expand Up @@ -617,11 +624,11 @@ async function loadConfig({
* not have exactly one language.
*/
// exported for testing.
export function calculateAugmentation(
export async function calculateAugmentation(
rawPacksInput: string | undefined,
rawQueriesInput: string | undefined,
languages: Language[],
): AugmentationProperties {
): Promise<AugmentationProperties> {
const packsInputCombines = shouldCombine(rawPacksInput);
const packsInput = parsePacksFromInput(
rawPacksInput,
Expand All @@ -634,11 +641,14 @@ export function calculateAugmentation(
queriesInputCombines,
);

const defaultQueryFilters: QueryFilter[] = [];

return {
packsInputCombines,
packsInput: packsInput?.[languages[0]],
queriesInput,
queriesInputCombines,
defaultQueryFilters,
};
}

Expand Down