diff --git a/lib/entry-points.js b/lib/entry-points.js index 8e4b26b54..69a12fa1e 100644 --- a/lib/entry-points.js +++ b/lib/entry-points.js @@ -149430,18 +149430,32 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP languages, packsInputCombines ); - const queriesInputCombines = shouldCombine(rawQueriesInput); - const queriesInput = parseQueriesFromInput( - rawQueriesInput, - queriesInputCombines + const queries = parseQueriesInput(rawQueriesInput); + const repoPropertyQueries = parseExtraQueriesProperty( + repositoryProperties["github-codeql-extra-queries" /* EXTRA_QUERIES */] ); - const repoExtraQueries = repositoryProperties["github-codeql-extra-queries" /* EXTRA_QUERIES */]; - const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); - const repoPropertyQueries = { - combines: repoExtraQueriesCombines, + return { + packsInputCombines, + packsInput: packsInput?.[languages[0]], + queriesInput: queries.input, + queriesInputCombines: queries.combines, + repoPropertyQueries + }; +} +function parseQueriesInput(rawQueriesInput) { + const combines = shouldCombine(rawQueriesInput); + return { + combines, + input: parseQueriesFromInput(rawQueriesInput, combines) + }; +} +function parseExtraQueriesProperty(value) { + const combines = shouldCombine(value); + return { + combines, input: parseQueriesFromInput( - repoExtraQueries, - repoExtraQueriesCombines, + value, + combines, new ConfigurationError( getRepoPropertyError( "github-codeql-extra-queries" /* EXTRA_QUERIES */, @@ -149450,13 +149464,6 @@ async function calculateAugmentation(rawPacksInput, rawQueriesInput, repositoryP ) ) }; - return { - packsInputCombines, - packsInput: packsInput?.[languages[0]], - queriesInput, - queriesInputCombines, - repoPropertyQueries - }; } function parseQueriesFromInput(rawQueriesInput, queriesInputCombines, errorToThrow) { if (!rawQueriesInput) { diff --git a/src/config/db-config.ts b/src/config/db-config.ts index 44c671bae..4b1ed5479 100644 --- a/src/config/db-config.ts +++ b/src/config/db-config.ts @@ -446,20 +446,53 @@ export async function calculateAugmentation( languages, packsInputCombines, ); - const queriesInputCombines = shouldCombine(rawQueriesInput); - const queriesInput = parseQueriesFromInput( - rawQueriesInput, - queriesInputCombines, + const queries = parseQueriesInput(rawQueriesInput); + const repoPropertyQueries = parseExtraQueriesProperty( + repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES], ); - const repoExtraQueries = - repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES]; - const repoExtraQueriesCombines = shouldCombine(repoExtraQueries); - const repoPropertyQueries = { - combines: repoExtraQueriesCombines, + return { + packsInputCombines, + packsInput: packsInput?.[languages[0]], + queriesInput: queries.input, + queriesInputCombines: queries.combines, + repoPropertyQueries, + }; +} + +/** + * 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: "" }`. + * + * @throws A `ConfigurationError` if the input is a '+' with no queries after it. + */ +export function parseQueriesInput( + rawQueriesInput: string | undefined, +): Augmentation { + 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( + value: string | undefined, +): Augmentation { + const combines = shouldCombine(value); + return { + combines, input: parseQueriesFromInput( - repoExtraQueries, - repoExtraQueriesCombines, + value, + combines, new ConfigurationError( errorMessages.getRepoPropertyError( RepositoryPropertyName.EXTRA_QUERIES, @@ -468,14 +501,6 @@ export async function calculateAugmentation( ), ), }; - - return { - packsInputCombines, - packsInput: packsInput?.[languages[0]], - queriesInput, - queriesInputCombines, - repoPropertyQueries, - }; } function parseQueriesFromInput(