Skip to content

Commit d14a212

Browse files
committed
Include repo property queries in combineQueries
1 parent 1bfb67d commit d14a212

File tree

3 files changed

+56
-19
lines changed

3 files changed

+56
-19
lines changed

lib/init-action.js

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

src/codeql.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -659,15 +659,15 @@ test(
659659
},
660660
{
661661
queries: [
662-
{
663-
uses: "zzz",
664-
},
665662
{
666663
uses: "xxx",
667664
},
668665
{
669666
uses: "yyy",
670667
},
668+
{
669+
uses: "zzz",
670+
},
671671
],
672672
},
673673
);

src/config/db-config.ts

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,25 +364,53 @@ function parseQueriesFromInput(
364364
/**
365365
* Combines queries from various configuration sources.
366366
*
367-
* @param augmentedConfig The loaded configuration file (either `config-file` or `config` input).
367+
* @param config The loaded configuration file (either `config-file` or `config` input).
368368
* @param augmentationProperties Additional configuration data from other sources.
369369
* @returns Returns `augmentedConfig` with `queries` set to the computed array of queries.
370370
*/
371371
function combineQueries(
372-
augmentedConfig: UserConfig,
372+
config: UserConfig,
373373
augmentationProperties: AugmentationProperties,
374-
): QuerySpec[] | undefined {
374+
): QuerySpec[] {
375+
const result: QuerySpec[] = [];
376+
377+
// Query settings obtained from the repository properties have the highest precedence.
378+
if (
379+
augmentationProperties.repoPropertyQueries &&
380+
augmentationProperties.repoPropertyQueries.input
381+
) {
382+
// If there are queries configured as a repository property, these may be organisational
383+
// settings. If they don't allow combining with other query configurations, return just the
384+
// ones configured in the repository properties.
385+
if (!augmentationProperties.repoPropertyQueries.combines) {
386+
return augmentationProperties.repoPropertyQueries.input;
387+
} else {
388+
// Otherwise, add them to the query array and continue.
389+
result.push(...augmentationProperties.repoPropertyQueries.input);
390+
}
391+
}
392+
393+
// If there is a `queries` input to the Action, it has the next highest precedence.
375394
if (augmentationProperties.queriesInput) {
376-
if (augmentationProperties.queriesInputCombines) {
377-
return (augmentedConfig.queries || []).concat(
378-
augmentationProperties.queriesInput,
379-
);
395+
// If there is a `queries` input and `queriesInputCombines` is `false`, then we don't
396+
// combine it with the queries configured in the configuration file (if any). That is the
397+
// original behaviour of this property. However, we DO combine it with any queries that
398+
// we obtained from the repository properties, since that may be enforced by the organisation.
399+
if (!augmentationProperties.queriesInputCombines) {
400+
return result.concat(augmentationProperties.queriesInput);
380401
} else {
381-
return augmentationProperties.queriesInput;
402+
// If they combine, add them to the query array and continue.
403+
result.push(...augmentationProperties.queriesInput);
382404
}
383405
}
384406

385-
return augmentedConfig.queries;
407+
// If we get to this point, we either don't have any extra configuration inputs or all of them
408+
// allow themselves to be combined with the settings from the configuration file.
409+
if (config.queries) {
410+
result.push(...config.queries);
411+
}
412+
413+
return result;
386414
}
387415

388416
export function generateCodeScanningConfig(

0 commit comments

Comments
 (0)