mirror of
https://github.com/github/codeql-action.git
synced 2026-04-27 17:39:15 +00:00
Include queries from repo properties in AugmentationProperties
This commit is contained in:
@@ -459,6 +459,7 @@ export async function initActionState(
|
||||
const augmentationProperties = await calculateAugmentation(
|
||||
packsInput,
|
||||
queriesInput,
|
||||
repositoryProperties,
|
||||
languages,
|
||||
);
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import test, { ExecutionContext } from "ava";
|
||||
|
||||
import { RepositoryProperties } from "../feature-flags/properties";
|
||||
import { KnownLanguage, Language } from "../languages";
|
||||
import { prettyPrintPack } from "../util";
|
||||
|
||||
@@ -190,11 +191,13 @@ const calculateAugmentationMacro = test.macro({
|
||||
rawPacksInput: string | undefined,
|
||||
rawQueriesInput: string | undefined,
|
||||
languages: Language[],
|
||||
repositoryProperties: RepositoryProperties,
|
||||
expectedAugmentationProperties: dbConfig.AugmentationProperties,
|
||||
) => {
|
||||
const actualAugmentationProperties = await dbConfig.calculateAugmentation(
|
||||
rawPacksInput,
|
||||
rawQueriesInput,
|
||||
repositoryProperties,
|
||||
languages,
|
||||
);
|
||||
t.deepEqual(actualAugmentationProperties, expectedAugmentationProperties);
|
||||
@@ -208,6 +211,7 @@ test(
|
||||
undefined,
|
||||
undefined,
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
{
|
||||
...dbConfig.defaultAugmentationProperties,
|
||||
},
|
||||
@@ -219,6 +223,7 @@ test(
|
||||
undefined,
|
||||
" a, b , c, d",
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
{
|
||||
...dbConfig.defaultAugmentationProperties,
|
||||
queriesInput: [{ uses: "a" }, { uses: "b" }, { uses: "c" }, { uses: "d" }],
|
||||
@@ -231,6 +236,7 @@ test(
|
||||
undefined,
|
||||
" + a, b , c, d ",
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
{
|
||||
...dbConfig.defaultAugmentationProperties,
|
||||
queriesInputCombines: true,
|
||||
@@ -244,6 +250,7 @@ test(
|
||||
" codeql/a , codeql/b , codeql/c , codeql/d ",
|
||||
undefined,
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
{
|
||||
...dbConfig.defaultAugmentationProperties,
|
||||
packsInput: ["codeql/a", "codeql/b", "codeql/c", "codeql/d"],
|
||||
@@ -256,6 +263,7 @@ test(
|
||||
" + codeql/a, codeql/b, codeql/c, codeql/d",
|
||||
undefined,
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
{
|
||||
...dbConfig.defaultAugmentationProperties,
|
||||
packsInputCombines: true,
|
||||
@@ -270,6 +278,7 @@ const calculateAugmentationErrorMacro = test.macro({
|
||||
rawPacksInput: string | undefined,
|
||||
rawQueriesInput: string | undefined,
|
||||
languages: Language[],
|
||||
repositoryProperties: RepositoryProperties,
|
||||
expectedError: RegExp | string,
|
||||
) => {
|
||||
await t.throwsAsync(
|
||||
@@ -277,6 +286,7 @@ const calculateAugmentationErrorMacro = test.macro({
|
||||
dbConfig.calculateAugmentation(
|
||||
rawPacksInput,
|
||||
rawQueriesInput,
|
||||
repositoryProperties,
|
||||
languages,
|
||||
),
|
||||
{ message: expectedError },
|
||||
@@ -291,6 +301,7 @@ test(
|
||||
undefined,
|
||||
" + ",
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
/The workflow property "queries" is invalid/,
|
||||
);
|
||||
|
||||
@@ -300,6 +311,7 @@ test(
|
||||
" + ",
|
||||
undefined,
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
/The workflow property "packs" is invalid/,
|
||||
);
|
||||
|
||||
@@ -309,6 +321,7 @@ test(
|
||||
" + a/b, c/d ",
|
||||
undefined,
|
||||
[KnownLanguage.javascript, KnownLanguage.java],
|
||||
{},
|
||||
/Cannot specify a 'packs' input in a multi-language analysis/,
|
||||
);
|
||||
|
||||
@@ -318,6 +331,7 @@ test(
|
||||
" + a/b, c/d ",
|
||||
undefined,
|
||||
[],
|
||||
{},
|
||||
/No languages specified/,
|
||||
);
|
||||
|
||||
@@ -327,5 +341,6 @@ test(
|
||||
" a-pack-without-a-scope ",
|
||||
undefined,
|
||||
[KnownLanguage.javascript],
|
||||
{},
|
||||
/"a-pack-without-a-scope" is not a valid pack/,
|
||||
);
|
||||
|
||||
+35
-1
@@ -3,6 +3,10 @@ import * as path from "path";
|
||||
import * as semver from "semver";
|
||||
|
||||
import * as errorMessages from "../error-messages";
|
||||
import {
|
||||
RepositoryProperties,
|
||||
RepositoryPropertyName,
|
||||
} from "../feature-flags/properties";
|
||||
import { Language } from "../languages";
|
||||
import { cloneObject, ConfigurationError, prettyPrintPack } from "../util";
|
||||
|
||||
@@ -41,6 +45,17 @@ export interface UserConfig {
|
||||
"query-filters"?: QueryFilter[];
|
||||
}
|
||||
|
||||
/**
|
||||
* Represents additional configuration data from a source other than
|
||||
* a configuration file.
|
||||
*/
|
||||
interface Augmentation<T> {
|
||||
/** Whether or not the `input` combines with data in the base config. */
|
||||
combines: boolean;
|
||||
/** The additional input data. */
|
||||
input?: T;
|
||||
}
|
||||
|
||||
/**
|
||||
* Describes how to augment the user config with inputs from the action.
|
||||
*
|
||||
@@ -71,6 +86,11 @@ export interface AugmentationProperties {
|
||||
* The packs input from the `with` block of the action declaration
|
||||
*/
|
||||
packsInput?: string[];
|
||||
|
||||
/**
|
||||
* Extra queries from the corresponding repository property.
|
||||
*/
|
||||
repoPropertyQueries: Augmentation<QuerySpec[]>;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -82,6 +102,10 @@ export const defaultAugmentationProperties: AugmentationProperties = {
|
||||
packsInputCombines: false,
|
||||
packsInput: undefined,
|
||||
queriesInput: undefined,
|
||||
repoPropertyQueries: {
|
||||
combines: false,
|
||||
input: undefined,
|
||||
},
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -256,6 +280,7 @@ export function parsePacksFromInput(
|
||||
*
|
||||
* @param rawPacksInput The packs input from the action configuration.
|
||||
* @param rawQueriesInput The queries input from the action configuration.
|
||||
* @param repositoryProperties The dictionary of repository properties.
|
||||
* @param languages The languages that the config file is for. If the packs input
|
||||
* is non-empty, then there must be exactly one language. Otherwise, an
|
||||
* error is thrown.
|
||||
@@ -265,10 +290,10 @@ export function parsePacksFromInput(
|
||||
* @throws An error if the packs input is non-empty and the languages input does
|
||||
* not have exactly one language.
|
||||
*/
|
||||
// exported for testing.
|
||||
export async function calculateAugmentation(
|
||||
rawPacksInput: string | undefined,
|
||||
rawQueriesInput: string | undefined,
|
||||
repositoryProperties: RepositoryProperties,
|
||||
languages: Language[],
|
||||
): Promise<AugmentationProperties> {
|
||||
const packsInputCombines = shouldCombine(rawPacksInput);
|
||||
@@ -283,11 +308,20 @@ export async function calculateAugmentation(
|
||||
queriesInputCombines,
|
||||
);
|
||||
|
||||
const repoExtraQueries =
|
||||
repositoryProperties[RepositoryPropertyName.EXTRA_QUERIES];
|
||||
const repoExtraQueriesCombines = shouldCombine(repoExtraQueries);
|
||||
const repoPropertyQueries = {
|
||||
combines: repoExtraQueriesCombines,
|
||||
input: parseQueriesFromInput(repoExtraQueries, repoExtraQueriesCombines),
|
||||
};
|
||||
|
||||
return {
|
||||
packsInputCombines,
|
||||
packsInput: packsInput?.[languages[0]],
|
||||
queriesInput,
|
||||
queriesInputCombines,
|
||||
repoPropertyQueries,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -5,7 +5,9 @@ import { RepositoryNwo } from "../repository";
|
||||
/**
|
||||
* Enumerates repository property names that have some meaning to us.
|
||||
*/
|
||||
export enum RepositoryPropertyName {}
|
||||
export enum RepositoryPropertyName {
|
||||
EXTRA_QUERIES = "github-codeql-extra-queries",
|
||||
}
|
||||
|
||||
/**
|
||||
* A repository property has a name and a value.
|
||||
|
||||
Reference in New Issue
Block a user