Skip to content

Commit da967b1

Browse files
committed
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.
1 parent 3c45339 commit da967b1

File tree

3 files changed

+35
-10
lines changed

3 files changed

+35
-10
lines changed

src/codeql.ts

+9
Original file line numberDiff line numberDiff line change
@@ -1274,6 +1274,15 @@ async function generateCodeScanningConfig(
12741274
if (Array.isArray(augmentedConfig.packs) && !augmentedConfig.packs.length) {
12751275
delete augmentedConfig.packs;
12761276
}
1277+
1278+
augmentedConfig["query-filters"] = [
1279+
...(config.augmentationProperties.defaultQueryFilters || []),
1280+
...(augmentedConfig["query-filters"] || []),
1281+
];
1282+
if (augmentedConfig["query-filters"]?.length === 0) {
1283+
delete augmentedConfig["query-filters"];
1284+
}
1285+
12771286
logger.info(
12781287
`Writing augmented user configuration file to ${codeScanningConfigFile}`,
12791288
);

src/config-utils.test.ts

+12-6
Original file line numberDiff line numberDiff line change
@@ -809,11 +809,12 @@ const calculateAugmentationMacro = test.macro({
809809
languages: Language[],
810810
expectedAugmentationProperties: configUtils.AugmentationProperties,
811811
) => {
812-
const actualAugmentationProperties = configUtils.calculateAugmentation(
813-
rawPacksInput,
814-
rawQueriesInput,
815-
languages,
816-
);
812+
const actualAugmentationProperties =
813+
await configUtils.calculateAugmentation(
814+
rawPacksInput,
815+
rawQueriesInput,
816+
languages,
817+
);
817818
t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties);
818819
},
819820
title: (_, title) => `Calculate Augmentation: ${title}`,
@@ -830,6 +831,7 @@ test(
830831
queriesInput: undefined,
831832
packsInputCombines: false,
832833
packsInput: undefined,
834+
defaultQueryFilters: [],
833835
} as configUtils.AugmentationProperties,
834836
);
835837

@@ -844,6 +846,7 @@ test(
844846
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
845847
packsInputCombines: false,
846848
packsInput: undefined,
849+
defaultQueryFilters: [],
847850
} as configUtils.AugmentationProperties,
848851
);
849852

@@ -858,6 +861,7 @@ test(
858861
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
859862
packsInputCombines: false,
860863
packsInput: undefined,
864+
defaultQueryFilters: [],
861865
} as configUtils.AugmentationProperties,
862866
);
863867

@@ -872,6 +876,7 @@ test(
872876
queriesInput: undefined,
873877
packsInputCombines: false,
874878
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
879+
defaultQueryFilters: [],
875880
} as configUtils.AugmentationProperties,
876881
);
877882

@@ -886,6 +891,7 @@ test(
886891
queriesInput: undefined,
887892
packsInputCombines: true,
888893
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
894+
defaultQueryFilters: [],
889895
} as configUtils.AugmentationProperties,
890896
);
891897

@@ -898,7 +904,7 @@ const calculateAugmentationErrorMacro = test.macro({
898904
languages: Language[],
899905
expectedError: RegExp | string,
900906
) => {
901-
t.throws(
907+
await t.throwsAsync(
902908
() =>
903909
configUtils.calculateAugmentation(
904910
rawPacksInput,

src/config-utils.ts

+14-4
Original file line numberDiff line numberDiff line change
@@ -173,10 +173,16 @@ export interface AugmentationProperties {
173173
* Whether or not the packs input combines with the packs in the config.
174174
*/
175175
packsInputCombines: boolean;
176+
176177
/**
177178
* The packs input from the `with` block of the action declaration
178179
*/
179180
packsInput?: string[];
181+
182+
/**
183+
* Default query filters to apply to the queries in the config.
184+
*/
185+
defaultQueryFilters?: QueryFilter[];
180186
}
181187

182188
/**
@@ -188,6 +194,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
188194
packsInputCombines: false,
189195
packsInput: undefined,
190196
queriesInput: undefined,
197+
defaultQueryFilters: [],
191198
};
192199
export type Packs = Partial<Record<Language, string[]>>;
193200

@@ -461,7 +468,7 @@ export async function getDefaultConfig({
461468
logger,
462469
);
463470

464-
const augmentationProperties = calculateAugmentation(
471+
const augmentationProperties = await calculateAugmentation(
465472
packsInput,
466473
queriesInput,
467474
languages,
@@ -567,7 +574,7 @@ async function loadConfig({
567574
logger,
568575
);
569576

570-
const augmentationProperties = calculateAugmentation(
577+
const augmentationProperties = await calculateAugmentation(
571578
packsInput,
572579
queriesInput,
573580
languages,
@@ -617,11 +624,11 @@ async function loadConfig({
617624
* not have exactly one language.
618625
*/
619626
// exported for testing.
620-
export function calculateAugmentation(
627+
export async function calculateAugmentation(
621628
rawPacksInput: string | undefined,
622629
rawQueriesInput: string | undefined,
623630
languages: Language[],
624-
): AugmentationProperties {
631+
): Promise<AugmentationProperties> {
625632
const packsInputCombines = shouldCombine(rawPacksInput);
626633
const packsInput = parsePacksFromInput(
627634
rawPacksInput,
@@ -634,11 +641,14 @@ export function calculateAugmentation(
634641
queriesInputCombines,
635642
);
636643

644+
const defaultQueryFilters: QueryFilter[] = [];
645+
637646
return {
638647
packsInputCombines,
639648
packsInput: packsInput?.[languages[0]],
640649
queriesInput,
641650
queriesInputCombines,
651+
defaultQueryFilters,
642652
};
643653
}
644654

0 commit comments

Comments
 (0)