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.
This commit is contained in:
parent
3c4533916b
commit
da967b1ade
3 changed files with 35 additions and 10 deletions
|
|
@ -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}`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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}`,
|
||||
|
|
@ -830,6 +831,7 @@ test(
|
|||
queriesInput: undefined,
|
||||
packsInputCombines: false,
|
||||
packsInput: undefined,
|
||||
defaultQueryFilters: [],
|
||||
} as configUtils.AugmentationProperties,
|
||||
);
|
||||
|
||||
|
|
@ -844,6 +846,7 @@ test(
|
|||
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
|
||||
packsInputCombines: false,
|
||||
packsInput: undefined,
|
||||
defaultQueryFilters: [],
|
||||
} as configUtils.AugmentationProperties,
|
||||
);
|
||||
|
||||
|
|
@ -858,6 +861,7 @@ test(
|
|||
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
|
||||
packsInputCombines: false,
|
||||
packsInput: undefined,
|
||||
defaultQueryFilters: [],
|
||||
} as configUtils.AugmentationProperties,
|
||||
);
|
||||
|
||||
|
|
@ -872,6 +876,7 @@ test(
|
|||
queriesInput: undefined,
|
||||
packsInputCombines: false,
|
||||
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
|
||||
defaultQueryFilters: [],
|
||||
} as configUtils.AugmentationProperties,
|
||||
);
|
||||
|
||||
|
|
@ -886,6 +891,7 @@ test(
|
|||
queriesInput: undefined,
|
||||
packsInputCombines: true,
|
||||
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
|
||||
defaultQueryFilters: [],
|
||||
} as configUtils.AugmentationProperties,
|
||||
);
|
||||
|
||||
|
|
@ -898,7 +904,7 @@ const calculateAugmentationErrorMacro = test.macro({
|
|||
languages: Language[],
|
||||
expectedError: RegExp | string,
|
||||
) => {
|
||||
t.throws(
|
||||
await t.throwsAsync(
|
||||
() =>
|
||||
configUtils.calculateAugmentation(
|
||||
rawPacksInput,
|
||||
|
|
|
|||
|
|
@ -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[];
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -188,6 +194,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
|
|||
packsInputCombines: false,
|
||||
packsInput: undefined,
|
||||
queriesInput: undefined,
|
||||
defaultQueryFilters: [],
|
||||
};
|
||||
export type Packs = Partial<Record<Language, string[]>>;
|
||||
|
||||
|
|
@ -461,7 +468,7 @@ export async function getDefaultConfig({
|
|||
logger,
|
||||
);
|
||||
|
||||
const augmentationProperties = calculateAugmentation(
|
||||
const augmentationProperties = await calculateAugmentation(
|
||||
packsInput,
|
||||
queriesInput,
|
||||
languages,
|
||||
|
|
@ -567,7 +574,7 @@ async function loadConfig({
|
|||
logger,
|
||||
);
|
||||
|
||||
const augmentationProperties = calculateAugmentation(
|
||||
const augmentationProperties = await calculateAugmentation(
|
||||
packsInput,
|
||||
queriesInput,
|
||||
languages,
|
||||
|
|
@ -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,
|
||||
|
|
@ -634,11 +641,14 @@ export function calculateAugmentation(
|
|||
queriesInputCombines,
|
||||
);
|
||||
|
||||
const defaultQueryFilters: QueryFilter[] = [];
|
||||
|
||||
return {
|
||||
packsInputCombines,
|
||||
packsInput: packsInput?.[languages[0]],
|
||||
queriesInput,
|
||||
queriesInputCombines,
|
||||
defaultQueryFilters,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue