Skip to content

Commit 8cba882

Browse files
committed
Include queries from repo properties in AugmentationProperties
1 parent c24e9e5 commit 8cba882

File tree

5 files changed

+107
-49
lines changed

5 files changed

+107
-49
lines changed

lib/init-action.js

Lines changed: 56 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/config-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,7 @@ export async function initActionState(
459459
const augmentationProperties = await calculateAugmentation(
460460
packsInput,
461461
queriesInput,
462+
repositoryProperties,
462463
languages,
463464
);
464465

src/config/db-config.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import test, { ExecutionContext } from "ava";
22

3+
import { RepositoryProperties } from "../feature-flags/properties";
34
import { KnownLanguage, Language } from "../languages";
45
import { prettyPrintPack } from "../util";
56

@@ -190,11 +191,13 @@ const calculateAugmentationMacro = test.macro({
190191
rawPacksInput: string | undefined,
191192
rawQueriesInput: string | undefined,
192193
languages: Language[],
194+
repositoryProperties: RepositoryProperties,
193195
expectedAugmentationProperties: dbConfig.AugmentationProperties,
194196
) => {
195197
const actualAugmentationProperties = await dbConfig.calculateAugmentation(
196198
rawPacksInput,
197199
rawQueriesInput,
200+
repositoryProperties,
198201
languages,
199202
);
200203
t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties);
@@ -208,6 +211,7 @@ test(
208211
undefined,
209212
undefined,
210213
[KnownLanguage.javascript],
214+
{},
211215
{
212216
...dbConfig.defaultAugmentationProperties,
213217
},
@@ -219,6 +223,7 @@ test(
219223
undefined,
220224
" a, b , c, d",
221225
[KnownLanguage.javascript],
226+
{},
222227
{
223228
...dbConfig.defaultAugmentationProperties,
224229
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
@@ -231,6 +236,7 @@ test(
231236
undefined,
232237
" + a, b , c, d ",
233238
[KnownLanguage.javascript],
239+
{},
234240
{
235241
...dbConfig.defaultAugmentationProperties,
236242
queriesInputCombines: true,
@@ -244,6 +250,7 @@ test(
244250
" codeql/a , codeql/b , codeql/c , codeql/d ",
245251
undefined,
246252
[KnownLanguage.javascript],
253+
{},
247254
{
248255
...dbConfig.defaultAugmentationProperties,
249256
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
@@ -256,6 +263,7 @@ test(
256263
" + codeql/a, codeql/b, codeql/c, codeql/d",
257264
undefined,
258265
[KnownLanguage.javascript],
266+
{},
259267
{
260268
...dbConfig.defaultAugmentationProperties,
261269
packsInputCombines: true,
@@ -270,13 +278,15 @@ const calculateAugmentationErrorMacro = test.macro({
270278
rawPacksInput: string | undefined,
271279
rawQueriesInput: string | undefined,
272280
languages: Language[],
281+
repositoryProperties: RepositoryProperties,
273282
expectedError: RegExp | string,
274283
) => {
275284
await t.throwsAsync(
276285
() =>
277286
dbConfig.calculateAugmentation(
278287
rawPacksInput,
279288
rawQueriesInput,
289+
repositoryProperties,
280290
languages,
281291
),
282292
{ message: expectedError },
@@ -291,6 +301,7 @@ test(
291301
undefined,
292302
" + ",
293303
[KnownLanguage.javascript],
304+
{},
294305
/The workflow property "queries" is invalid/,
295306
);
296307

@@ -300,6 +311,7 @@ test(
300311
" + ",
301312
undefined,
302313
[KnownLanguage.javascript],
314+
{},
303315
/The workflow property "packs" is invalid/,
304316
);
305317

@@ -309,6 +321,7 @@ test(
309321
" + a/b, c/d ",
310322
undefined,
311323
[KnownLanguage.javascript, KnownLanguage.java],
324+
{},
312325
/Cannot specify a 'packs' input in a multi-language analysis/,
313326
);
314327

@@ -318,6 +331,7 @@ test(
318331
" + a/b, c/d ",
319332
undefined,
320333
[],
334+
{},
321335
/No languages specified/,
322336
);
323337

@@ -327,5 +341,6 @@ test(
327341
" a-pack-without-a-scope ",
328342
undefined,
329343
[KnownLanguage.javascript],
344+
{},
330345
/"a-pack-without-a-scope" is not a valid pack/,
331346
);

src/config/db-config.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@ import * as path from "path";
33
import * as semver from "semver";
44

55
import * as errorMessages from "../error-messages";
6+
import {
7+
RepositoryProperties,
8+
RepositoryPropertyName,
9+
} from "../feature-flags/properties";
610
import { Language } from "../languages";
711
import { cloneObject, ConfigurationError, prettyPrintPack } from "../util";
812

@@ -41,6 +45,17 @@ export interface UserConfig {
4145
"query-filters"?: QueryFilter[];
4246
}
4347

48+
/**
49+
* Represents additional configuration data from a source other than
50+
* a configuration file.
51+
*/
52+
interface Augmentation<T> {
53+
/** Whether or not the `input` combines with data in the base config. */
54+
combines: boolean;
55+
/** The additional input data. */
56+
input?: T;
57+
}
58+
4459
/**
4560
* Describes how to augment the user config with inputs from the action.
4661
*
@@ -71,6 +86,11 @@ export interface AugmentationProperties {
7186
* The packs input from the `with` block of the action declaration
7287
*/
7388
packsInput?: string[];
89+
90+
/**
91+
* Extra queries from the corresponding repository property.
92+
*/
93+
repoPropertyQueries?: Augmentation<QuerySpec[]>;
7494
}
7595

7696
/**
@@ -82,6 +102,7 @@ export const defaultAugmentationProperties: AugmentationProperties = {
82102
packsInputCombines: false,
83103
packsInput: undefined,
84104
queriesInput: undefined,
105+
repoPropertyQueries: undefined,
85106
};
86107

87108
/**
@@ -256,6 +277,7 @@ export function parsePacksFromInput(
256277
*
257278
* @param rawPacksInput The packs input from the action configuration.
258279
* @param rawQueriesInput The queries input from the action configuration.
280+
* @param repositoryProperties The dictionary of repository properties.
259281
* @param languages The languages that the config file is for. If the packs input
260282
* is non-empty, then there must be exactly one language. Otherwise, an
261283
* error is thrown.
@@ -265,10 +287,10 @@ export function parsePacksFromInput(
265287
* @throws An error if the packs input is non-empty and the languages input does
266288
* not have exactly one language.
267289
*/
268-
// exported for testing.
269290
export async function calculateAugmentation(
270291
rawPacksInput: string | undefined,
271292
rawQueriesInput: string | undefined,
293+
repositoryProperties: RepositoryProperties,
272294
languages: Language[],
273295
): Promise<AugmentationProperties> {
274296
const packsInputCombines = shouldCombine(rawPacksInput);
@@ -283,11 +305,20 @@ export async function calculateAugmentation(
283305
queriesInputCombines,
284306
);
285307

308+
const repoExtraQueries =
309+
repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES];
310+
const repoExtraQueriesCombines = shouldCombine(repoExtraQueries);
311+
const repoPropertyQueries = {
312+
combines: repoExtraQueriesCombines,
313+
input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines),
314+
};
315+
286316
return {
287317
packsInputCombines,
288318
packsInput: packsInput?.[languages[0]],
289319
queriesInput,
290320
queriesInputCombines,
321+
repoPropertyQueries,
291322
};
292323
}
293324

src/feature-flags/properties.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import { RepositoryNwo } from "../repository";
55
/**
66
* Enumerates repository property names that have some meaning to us.
77
*/
8-
export enum RepositoryPropertyName {}
8+
export enum RepositoryPropertyName {
9+
EXTRA_QUERIES = "github-codeql-extra-queries",
10+
}
911

1012
/**
1113
* A repository property has a name and a value.

0 commit comments

Comments
 (0)