Parse lists of queries with a single function

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
Henry Mercer
2026-10-02 14:22:24 +01:00
parent ce28f3e445
commit 1c0814d7d2
3 changed files with 58 additions and 100 deletions

59
lib/entry-points.js generated
View File

@@ -149446,9 +149446,10 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP
languages,
packsInputCombines
);
const queries = parseQueriesInput(rawQueriesInput);
const repoPropertyQueries = parseExtraQueriesProperty(
repositoryProperties["github-codeql-extra-queries" /* EXTRA_QUERIES */]
const queries = parseQueriesFromInput(rawQueriesInput);
const repoPropertyQueries = parseQueriesFromInput(
repositoryProperties["github-codeql-extra-queries" /* EXTRA_QUERIES */],
"github-codeql-extra-queries" /* EXTRA_QUERIES */
);
return {
packsInputCombines,
@@ -149458,47 +149459,28 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP
repoPropertyQueries
};
}
function parseQueriesInput(rawQueriesInput) {
const combines = shouldCombine(rawQueriesInput);
return {
combines,
input: parseQueriesFromInput(rawQueriesInput, combines)
};
}
function parseExtraQueriesProperty(value) {
function parseQueriesFromInput(value, repositoryProperty) {
const combines = shouldCombine(value);
return {
combines,
input: parseQueriesFromInput(
value,
combines,
new ConfigurationError(
getRepoPropertyError(
"github-codeql-extra-queries" /* EXTRA_QUERIES */,
getEmptyCombinesError()
)
)
)
};
}
function parseQueriesFromInput(rawQueriesInput, queriesInputCombines, errorToThrow) {
if (!rawQueriesInput) {
return void 0;
if (!value) {
return { combines, input: void 0 };
}
const trimmedInput = queriesInputCombines ? rawQueriesInput.trim().slice(1).trim() : rawQueriesInput?.trim() ?? "";
if (queriesInputCombines && trimmedInput.length === 0) {
if (errorToThrow) {
throw errorToThrow;
}
const trimmedInput = combines ? value.trim().slice(1).trim() : value.trim();
if (combines && trimmedInput.length === 0) {
throw new ConfigurationError(
getConfigFilePropertyError(
repositoryProperty !== void 0 ? getRepoPropertyError(
repositoryProperty,
getEmptyCombinesError()
) : getConfigFilePropertyError(
void 0,
"queries",
"A '+' was used in the 'queries' input to specify that you wished to add some packs to your CodeQL analysis. However, no packs were specified. Please either remove the '+' or specify some packs."
)
);
}
return trimmedInput.split(",").map((query) => ({ uses: query.trim() }));
return {
combines,
input: trimmedInput.split(",").map((query) => ({ uses: query.trim() }))
};
}
function combineQueries(logger, config, augmentationProperties) {
const result = [];
@@ -151634,13 +151616,16 @@ function getOtherLanguagePacksReason(inputs) {
return "the 'config' input may use queries that need library packs for other languages";
}
const query = findNonBuiltInQuery(
parseQueriesInput(inputs.queriesInput).input
parseQueriesFromInput(inputs.queriesInput).input
);
if (query !== void 0) {
return `the query '${query}' from the 'queries' input may need library packs for other languages`;
}
const extraQuery = findNonBuiltInQuery(
parseExtraQueriesProperty(inputs.extraQueriesProperty).input
parseQueriesFromInput(
inputs.extraQueriesProperty,
"github-codeql-extra-queries" /* EXTRA_QUERIES */
).input
);
if (extraQuery !== void 0) {
return `the query '${extraQuery}' from the '${"github-codeql-extra-queries" /* EXTRA_QUERIES */}' repository property may need library packs for other languages`;

View File

@@ -468,9 +468,10 @@ export async function calculateAugmentation(
languages,
packsInputCombines,
);
const queries = parseQueriesInput(rawQueriesInput);
const repoPropertyQueries = parseExtraQueriesProperty(
const queries = parseQueriesFromInput(rawQueriesInput);
const repoPropertyQueries = parseQueriesFromInput(
repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES],
RepositoryPropertyName.EXTRA_QUERIES,
);
return {
@@ -483,73 +484,43 @@ export async function calculateAugmentation(
}
/**
* Parses the `queries` input, a comma-separated list of queries that's combined with the queries
* from the configuration if it starts with '+'. The `input` of the result is `undefined` if the
* value is unset or empty. Entries aren't validated, so an empty entry becomes `{ uses: "" }`.
* Parses a comma-separated list of queries, which may start with '+'. `combines` is whether it
* starts with '+', and `input` holds the queries, or is `undefined` if `value` is unset or empty.
* Entries aren't validated, so an empty entry becomes `{ uses: "" }`.
*
* @throws A `ConfigurationError` if the input is a '+' with no queries after it.
* @param value The list of queries.
* @param repositoryProperty The repository property that `value` comes from, if any. Errors name
* this property, or the `queries` input if it's unset.
* @throws A `ConfigurationError` if `value` is a '+' with no queries after it.
*/
export function parseQueriesInput(
rawQueriesInput: string | undefined,
): Augmentation<QuerySpec[]> {
const combines = shouldCombine(rawQueriesInput);
return {
combines,
input: parseQueriesFromInput(rawQueriesInput, combines),
};
}
/**
* Parses the `github-codeql-extra-queries` repository property, which has the same format as the
* `queries` input. The `input` of the result is `undefined` if the value is unset or empty. Entries
* aren't validated, so an empty entry becomes `{ uses: "" }`.
*
* @throws A `ConfigurationError` if the value is a '+' with no queries after it.
*/
export function parseExtraQueriesProperty(
export function parseQueriesFromInput(
value: string | undefined,
repositoryProperty?: RepositoryPropertyName,
): Augmentation<QuerySpec[]> {
const combines = shouldCombine(value);
return {
combines,
input: parseQueriesFromInput(
value,
combines,
new ConfigurationError(
errorMessages.getRepoPropertyError(
RepositoryPropertyName.EXTRA_QUERIES,
errorMessages.getEmptyCombinesError(),
),
),
),
};
}
function parseQueriesFromInput(
rawQueriesInput: string | undefined,
queriesInputCombines: boolean,
errorToThrow?: ConfigurationError,
) {
if (!rawQueriesInput) {
return undefined;
if (!value) {
return { combines, input: undefined };
}
const trimmedInput = queriesInputCombines
? rawQueriesInput.trim().slice(1).trim()
: (rawQueriesInput?.trim() ?? "");
if (queriesInputCombines && trimmedInput.length === 0) {
if (errorToThrow) {
throw errorToThrow;
}
const trimmedInput = combines ? value.trim().slice(1).trim() : value.trim();
if (combines && trimmedInput.length === 0) {
throw new ConfigurationError(
errorMessages.getConfigFilePropertyError(
undefined,
"queries",
"A '+' was used in the 'queries' input to specify that you wished to add some packs to your CodeQL analysis. However, no packs were specified. Please either remove the '+' or specify some packs.",
),
repositoryProperty !== undefined
? errorMessages.getRepoPropertyError(
repositoryProperty,
errorMessages.getEmptyCombinesError(),
)
: errorMessages.getConfigFilePropertyError(
undefined,
"queries",
"A '+' was used in the 'queries' input to specify that you wished to add some packs to your CodeQL analysis. However, no packs were specified. Please either remove the '+' or specify some packs.",
),
);
}
return trimmedInput.split(",").map((query) => ({ uses: query.trim() }));
return {
combines,
input: trimmedInput.split(",").map((query) => ({ uses: query.trim() })),
};
}
/**

View File

@@ -5,8 +5,7 @@ import { isGitHubHostedRunner } from "./actions-util";
import {
defaultSuites,
matchesDefaultSetupConfigSchema,
parseExtraQueriesProperty,
parseQueriesInput,
parseQueriesFromInput,
QuerySpec,
} from "./config/db-config";
import { Feature } from "./feature-flags";
@@ -88,13 +87,16 @@ export function getOtherLanguagePacksReason(
// loading it, and CodeQL resolves the library packs for every configured query, including those
// for languages that aren't being analyzed.
const query = findNonBuiltInQuery(
parseQueriesInput(inputs.queriesInput).input,
parseQueriesFromInput(inputs.queriesInput).input,
);
if (query !== undefined) {
return `the query '${query}' from the 'queries' input may need library packs for other languages`;
}
const extraQuery = findNonBuiltInQuery(
parseExtraQueriesProperty(inputs.extraQueriesProperty).input,
parseQueriesFromInput(
inputs.extraQueriesProperty,
RepositoryPropertyName.EXTRA_QUERIES,
).input,
);
if (extraQuery !== undefined) {
return (