Merge branch 'main' into henrymercer/bump-minimum-codeql-version
This commit is contained in:
commit
5246291397
5356 changed files with 662479 additions and 473046 deletions
|
|
@ -175,6 +175,8 @@ test("status report fields and search path setting", async (t) => {
|
|||
if (builtinStatusReport.event_reports) {
|
||||
for (const eventReport of builtinStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties!);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -214,6 +216,8 @@ test("status report fields and search path setting", async (t) => {
|
|||
if (customStatusReport.event_reports) {
|
||||
for (const eventReport of customStatusReport.event_reports) {
|
||||
t.deepEqual(eventReport.event, "codeql database interpret-results");
|
||||
t.true("properties" in eventReport);
|
||||
t.true("alertCounts" in eventReport.properties!);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -372,7 +372,9 @@ export async function runQueries(
|
|||
completed_at: endTimeInterpretResults.toISOString(),
|
||||
exit_status: "success",
|
||||
language,
|
||||
properties: perQueryAlertCounts,
|
||||
properties: {
|
||||
alertCounts: perQueryAlertCounts,
|
||||
},
|
||||
};
|
||||
|
||||
if (statusReport["event_reports"] === undefined) {
|
||||
|
|
|
|||
|
|
@ -23,7 +23,7 @@ import {
|
|||
createFeatures,
|
||||
mockLanguagesInRepo as mockLanguagesInRepo,
|
||||
} from "./testing-utils";
|
||||
import * as util from "./util";
|
||||
import { GitHubVariant, GitHubVersion, UserError, withTmpDir } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ const sampleApiDetails = {
|
|||
registriesAuthTokens: undefined,
|
||||
};
|
||||
|
||||
const gitHubVersion = { type: util.GitHubVariant.DOTCOM } as util.GitHubVersion;
|
||||
const gitHubVersion = { type: GitHubVariant.DOTCOM } as GitHubVersion;
|
||||
|
||||
// Returns the filepath of the newly-created file
|
||||
function createConfigFile(inputFileContents: string, tmpDir: string): string {
|
||||
|
|
@ -55,7 +55,7 @@ function mockGetContents(
|
|||
data: content,
|
||||
};
|
||||
const spyGetContents = sinon
|
||||
.stub(client.repos, "getContent")
|
||||
.stub(client.rest.repos, "getContent")
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
.resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
|
|
@ -73,12 +73,12 @@ function mockListLanguages(languages: string[]) {
|
|||
response.data[language] = 123;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
sinon.stub(client.repos, "listLanguages").resolves(response as any);
|
||||
sinon.stub(client.rest.repos, "listLanguages").resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
}
|
||||
|
||||
test("load empty config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
const languages = "javascript,python";
|
||||
|
||||
|
|
@ -145,7 +145,7 @@ test("load empty config", async (t) => {
|
|||
});
|
||||
|
||||
test("loading config saves config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const logger = getRunnerLogger(true);
|
||||
|
||||
const codeQL = setCodeQL({
|
||||
|
|
@ -207,7 +207,7 @@ test("loading config saves config", async (t) => {
|
|||
});
|
||||
|
||||
test("load input outside of workspace", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
try {
|
||||
await configUtils.initConfig(
|
||||
undefined,
|
||||
|
|
@ -234,7 +234,7 @@ test("load input outside of workspace", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(
|
||||
new UserError(
|
||||
configUtils.getConfigFileOutsideWorkspaceErrorMessage(
|
||||
path.join(tmpDir, "../input")
|
||||
)
|
||||
|
|
@ -245,7 +245,7 @@ test("load input outside of workspace", async (t) => {
|
|||
});
|
||||
|
||||
test("load non-local input with invalid repo syntax", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
// no filename given, just a repo
|
||||
const configFile = "octo-org/codeql-config@main";
|
||||
|
||||
|
|
@ -275,7 +275,7 @@ test("load non-local input with invalid repo syntax", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(
|
||||
new UserError(
|
||||
configUtils.getConfigFileRepoFormatInvalidMessage(
|
||||
"octo-org/codeql-config@main"
|
||||
)
|
||||
|
|
@ -286,7 +286,7 @@ test("load non-local input with invalid repo syntax", async (t) => {
|
|||
});
|
||||
|
||||
test("load non-existent input", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const languages = "javascript";
|
||||
const configFile = "input";
|
||||
t.false(fs.existsSync(path.join(tmpDir, configFile)));
|
||||
|
|
@ -317,7 +317,7 @@ test("load non-existent input", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(
|
||||
new UserError(
|
||||
configUtils.getConfigFileDoesNotExistErrorMessage(
|
||||
path.join(tmpDir, "input")
|
||||
)
|
||||
|
|
@ -328,7 +328,7 @@ test("load non-existent input", async (t) => {
|
|||
});
|
||||
|
||||
test("load non-empty input", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
|
|
@ -428,7 +428,7 @@ test("load non-empty input", async (t) => {
|
|||
});
|
||||
|
||||
test("Default queries are used", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
// Check that the default behaviour is to add the default queries.
|
||||
// In this case if a config file is specified but does not include
|
||||
// the disable-default-queries field.
|
||||
|
|
@ -523,7 +523,7 @@ function queriesToResolvedQueryForm(queries: string[]) {
|
|||
}
|
||||
|
||||
test("Queries can be specified in config file", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const inputFileContents = `
|
||||
name: my config
|
||||
queries:
|
||||
|
|
@ -598,7 +598,7 @@ test("Queries can be specified in config file", async (t) => {
|
|||
});
|
||||
|
||||
test("Queries from config file can be overridden in workflow file", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const inputFileContents = `
|
||||
name: my config
|
||||
queries:
|
||||
|
|
@ -677,7 +677,7 @@ test("Queries from config file can be overridden in workflow file", async (t) =>
|
|||
});
|
||||
|
||||
test("Queries in workflow file can be used in tandem with the 'disable default queries' option", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env["RUNNER_TEMP"] = tmpDir;
|
||||
process.env["GITHUB_WORKSPACE"] = tmpDir;
|
||||
|
||||
|
|
@ -751,7 +751,7 @@ test("Queries in workflow file can be used in tandem with the 'disable default q
|
|||
});
|
||||
|
||||
test("Multiple queries can be specified in workflow file, no config file required", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
fs.mkdirSync(path.join(tmpDir, "override1"));
|
||||
fs.mkdirSync(path.join(tmpDir, "override2"));
|
||||
|
||||
|
|
@ -829,7 +829,7 @@ test("Multiple queries can be specified in workflow file, no config file require
|
|||
});
|
||||
|
||||
test("Queries in workflow file can be added to the set of queries without overriding config file", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env["RUNNER_TEMP"] = tmpDir;
|
||||
process.env["GITHUB_WORKSPACE"] = tmpDir;
|
||||
|
||||
|
|
@ -926,7 +926,7 @@ test("Queries in workflow file can be added to the set of queries without overri
|
|||
});
|
||||
|
||||
test("Queries can be specified using config input", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const configInput = `
|
||||
name: my config
|
||||
queries:
|
||||
|
|
@ -1009,7 +1009,7 @@ test("Queries can be specified using config input", async (t) => {
|
|||
});
|
||||
|
||||
test("Using config input and file together, config input should be used.", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env["RUNNER_TEMP"] = tmpDir;
|
||||
process.env["GITHUB_WORKSPACE"] = tmpDir;
|
||||
|
||||
|
|
@ -1101,7 +1101,7 @@ test("Using config input and file together, config input should be used.", async
|
|||
});
|
||||
|
||||
test("Invalid queries in workflow file handled correctly", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const queries = "foo/bar@v1@v3";
|
||||
const languages = "javascript";
|
||||
|
||||
|
|
@ -1148,14 +1148,16 @@ test("Invalid queries in workflow file handled correctly", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(configUtils.getQueryUsesInvalid(undefined, "foo/bar@v1@v3"))
|
||||
new UserError(
|
||||
configUtils.getQueryUsesInvalid(undefined, "foo/bar@v1@v3")
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("API client used when reading remote config", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
|
|
@ -1222,7 +1224,7 @@ test("API client used when reading remote config", async (t) => {
|
|||
});
|
||||
|
||||
test("Remote config handles the case where a directory is provided", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const dummyResponse = []; // directories are returned as arrays
|
||||
mockGetContents(dummyResponse);
|
||||
|
||||
|
|
@ -1253,14 +1255,16 @@ test("Remote config handles the case where a directory is provided", async (t) =
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(configUtils.getConfigFileDirectoryGivenMessage(repoReference))
|
||||
new UserError(
|
||||
configUtils.getConfigFileDirectoryGivenMessage(repoReference)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("Invalid format of remote config handled correctly", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const dummyResponse = {
|
||||
// note no "content" property here
|
||||
};
|
||||
|
|
@ -1293,14 +1297,16 @@ test("Invalid format of remote config handled correctly", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(configUtils.getConfigFileFormatInvalidMessage(repoReference))
|
||||
new UserError(
|
||||
configUtils.getConfigFileFormatInvalidMessage(repoReference)
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("No detected languages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
mockListLanguages([]);
|
||||
const codeQL = setCodeQL({
|
||||
async resolveLanguages() {
|
||||
|
|
@ -1335,13 +1341,13 @@ test("No detected languages", async (t) => {
|
|||
);
|
||||
throw new Error("initConfig did not throw error");
|
||||
} catch (err) {
|
||||
t.deepEqual(err, new Error(configUtils.getNoLanguagesError()));
|
||||
t.deepEqual(err, new UserError(configUtils.getNoLanguagesError()));
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("Unknown languages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const languages = "rubbish,english";
|
||||
|
||||
try {
|
||||
|
|
@ -1370,14 +1376,16 @@ test("Unknown languages", async (t) => {
|
|||
} catch (err) {
|
||||
t.deepEqual(
|
||||
err,
|
||||
new Error(configUtils.getUnknownLanguagesError(["rubbish", "english"]))
|
||||
new UserError(
|
||||
configUtils.getUnknownLanguagesError(["rubbish", "english"])
|
||||
)
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
test("Config specifies packages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
|
|
@ -1431,7 +1439,7 @@ test("Config specifies packages", async (t) => {
|
|||
});
|
||||
|
||||
test("Config specifies packages for multiple languages", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
|
|
@ -1518,7 +1526,7 @@ function doInvalidInputTest(
|
|||
expectedErrorMessageGenerator: (configFile: string) => string
|
||||
) {
|
||||
test(`load invalid input - ${testName}`, async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async resolveQueries() {
|
||||
return {
|
||||
|
|
@ -1561,7 +1569,10 @@ function doInvalidInputTest(
|
|||
);
|
||||
throw new Error("initConfig did not throw error");
|
||||
} catch (err) {
|
||||
t.deepEqual(err, new Error(expectedErrorMessageGenerator(inputFile)));
|
||||
t.deepEqual(
|
||||
err,
|
||||
new UserError(expectedErrorMessageGenerator(inputFile))
|
||||
);
|
||||
}
|
||||
});
|
||||
});
|
||||
|
|
@ -2104,7 +2115,7 @@ const mlPoweredQueriesMacro = test.macro({
|
|||
queriesInput: string | undefined,
|
||||
expectedVersionString: string | undefined
|
||||
) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const codeQL = setCodeQL({
|
||||
async getVersion() {
|
||||
return codeQLVersion;
|
||||
|
|
@ -2409,7 +2420,7 @@ test(
|
|||
);
|
||||
|
||||
test("downloadPacks-no-registries", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const packDownloadStub = sinon.stub();
|
||||
packDownloadStub.callsFake((packs) => ({
|
||||
packs,
|
||||
|
|
@ -2446,7 +2457,7 @@ test("downloadPacks-no-registries", async (t) => {
|
|||
test("downloadPacks-with-registries", async (t) => {
|
||||
// same thing, but this time include a registries block and
|
||||
// associated env vars
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_TOKEN = "not-a-token";
|
||||
process.env.CODEQL_REGISTRIES_AUTH = undefined;
|
||||
const logger = getRunnerLogger(true);
|
||||
|
|
@ -2537,7 +2548,7 @@ test("downloadPacks-with-registries", async (t) => {
|
|||
test("downloadPacks-with-registries fails on 2.10.3", async (t) => {
|
||||
// same thing, but this time include a registries block and
|
||||
// associated env vars
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_TOKEN = "not-a-token";
|
||||
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
|
||||
const logger = getRunnerLogger(true);
|
||||
|
|
@ -2579,7 +2590,7 @@ test("downloadPacks-with-registries fails on 2.10.3", async (t) => {
|
|||
test("downloadPacks-with-registries fails with invalid registries block", async (t) => {
|
||||
// same thing, but this time include a registries block and
|
||||
// associated env vars
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.GITHUB_TOKEN = "not-a-token";
|
||||
process.env.CODEQL_REGISTRIES_AUTH = "not-a-registries-auth";
|
||||
const logger = getRunnerLogger(true);
|
||||
|
|
@ -2621,7 +2632,7 @@ test("downloadPacks-with-registries fails with invalid registries block", async
|
|||
// the happy path for generateRegistries is already tested in downloadPacks.
|
||||
// these following tests are for the error cases and when nothing is generated.
|
||||
test("no generateRegistries when CLI is too old", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const registriesInput = yaml.dump([
|
||||
{
|
||||
// no slash
|
||||
|
|
@ -2649,7 +2660,7 @@ test("no generateRegistries when CLI is too old", async (t) => {
|
|||
});
|
||||
});
|
||||
test("no generateRegistries when registries is undefined", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
const registriesInput = undefined;
|
||||
const codeQL = setCodeQL({
|
||||
// Accepted CLI versions are 2.10.4 or higher
|
||||
|
|
@ -2670,7 +2681,7 @@ test("no generateRegistries when registries is undefined", async (t) => {
|
|||
});
|
||||
|
||||
test("generateRegistries prefers original CODEQL_REGISTRIES_AUTH", async (t) => {
|
||||
return await util.withTmpDir(async (tmpDir) => {
|
||||
return await withTmpDir(async (tmpDir) => {
|
||||
process.env.CODEQL_REGISTRIES_AUTH = "original";
|
||||
const registriesInput = yaml.dump([
|
||||
{
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import {
|
|||
logCodeScanningConfigInCli,
|
||||
ML_POWERED_JS_QUERIES_PACK_NAME,
|
||||
useCodeScanningConfigInCli,
|
||||
UserError,
|
||||
} from "./util";
|
||||
|
||||
// Property names from the user-supplied config file.
|
||||
|
|
@ -299,7 +300,7 @@ function validateQueries(resolvedQueries: ResolveQueriesOutput) {
|
|||
const noDeclaredLanguage = resolvedQueries.noDeclaredLanguage;
|
||||
const noDeclaredLanguageQueries = Object.keys(noDeclaredLanguage);
|
||||
if (noDeclaredLanguageQueries.length !== 0) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`${
|
||||
"The following queries do not declare a language. " +
|
||||
"Their qlpack.yml files are either missing or is invalid.\n"
|
||||
|
|
@ -312,7 +313,7 @@ function validateQueries(resolvedQueries: ResolveQueriesOutput) {
|
|||
multipleDeclaredLanguages
|
||||
);
|
||||
if (multipleDeclaredLanguagesQueries.length !== 0) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`${
|
||||
"The following queries declare multiple languages. " +
|
||||
"Their qlpack.yml files are either missing or is invalid.\n"
|
||||
|
|
@ -403,7 +404,7 @@ async function addBuiltinSuiteQueries(
|
|||
let injectedMlQueries = false;
|
||||
const found = builtinSuites.find((suite) => suite === suiteName);
|
||||
if (!found) {
|
||||
throw new Error(getQueryUsesInvalid(configFile, suiteName));
|
||||
throw new UserError(getQueryUsesInvalid(configFile, suiteName));
|
||||
}
|
||||
if (
|
||||
suiteName === "security-experimental" &&
|
||||
|
|
@ -412,7 +413,7 @@ async function addBuiltinSuiteQueries(
|
|||
CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE
|
||||
))
|
||||
) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`The 'security-experimental' suite is not supported on CodeQL CLI versions earlier than
|
||||
${CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE}. Please upgrade to CodeQL CLI version
|
||||
${CODEQL_VERSION_SECURITY_EXPERIMENTAL_SUITE} or later.`
|
||||
|
|
@ -462,7 +463,7 @@ async function addLocalQueries(
|
|||
|
||||
// Check the file exists
|
||||
if (!fs.existsSync(absoluteQueryPath)) {
|
||||
throw new Error(getLocalPathDoesNotExist(configFile, localQueryPath));
|
||||
throw new UserError(getLocalPathDoesNotExist(configFile, localQueryPath));
|
||||
}
|
||||
|
||||
// Call this after checking file exists, because it'll fail if file doesn't exist
|
||||
|
|
@ -474,7 +475,7 @@ async function addLocalQueries(
|
|||
fs.realpathSync(workspacePath) + path.sep
|
||||
)
|
||||
) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getLocalPathOutsideOfRepository(configFile, localQueryPath)
|
||||
);
|
||||
}
|
||||
|
|
@ -503,7 +504,7 @@ async function addRemoteQueries(
|
|||
) {
|
||||
let tok = queryUses.split("@");
|
||||
if (tok.length !== 2) {
|
||||
throw new Error(getQueryUsesInvalid(configFile, queryUses));
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
|
||||
const ref = tok[1];
|
||||
|
|
@ -513,11 +514,11 @@ async function addRemoteQueries(
|
|||
// The second token is the repo
|
||||
// The rest is a path, if there is more than one token combine them to form the full path
|
||||
if (tok.length < 2) {
|
||||
throw new Error(getQueryUsesInvalid(configFile, queryUses));
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
// Check none of the parts of the repository name are empty
|
||||
if (tok[0].trim() === "" || tok[1].trim() === "") {
|
||||
throw new Error(getQueryUsesInvalid(configFile, queryUses));
|
||||
throw new UserError(getQueryUsesInvalid(configFile, queryUses));
|
||||
}
|
||||
const nwo = `${tok[0]}/${tok[1]}`;
|
||||
|
||||
|
|
@ -566,7 +567,7 @@ async function parseQueryUses(
|
|||
): Promise<boolean> {
|
||||
queryUses = queryUses.trim();
|
||||
if (queryUses === "") {
|
||||
throw new Error(getQueryUsesInvalid(configFile));
|
||||
throw new UserError(getQueryUsesInvalid(configFile));
|
||||
}
|
||||
|
||||
// Check for the local path case before we start trying to parse the repository name
|
||||
|
|
@ -643,7 +644,7 @@ export function validateAndSanitisePath(
|
|||
|
||||
// An empty path is not allowed as it's meaningless
|
||||
if (newPath === "") {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getConfigFilePropertyError(
|
||||
configFile,
|
||||
propertyName,
|
||||
|
|
@ -655,7 +656,7 @@ export function validateAndSanitisePath(
|
|||
|
||||
// Check for illegal uses of **
|
||||
if (newPath.match(pathStarsRegex)) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getConfigFilePropertyError(
|
||||
configFile,
|
||||
propertyName,
|
||||
|
|
@ -682,7 +683,7 @@ export function validateAndSanitisePath(
|
|||
// This may not play nicely with project layouts.
|
||||
// This restriction can be lifted later if we determine they are ok.
|
||||
if (newPath.indexOf("\\") !== -1) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getConfigFilePropertyError(
|
||||
configFile,
|
||||
propertyName,
|
||||
|
|
@ -881,7 +882,7 @@ export async function getLanguagesInRepo(
|
|||
logger: Logger
|
||||
): Promise<LanguageOrAlias[]> {
|
||||
logger.debug(`GitHub repo ${repository.owner} ${repository.repo}`);
|
||||
const response = await api.getApiClient().repos.listLanguages({
|
||||
const response = await api.getApiClient().rest.repos.listLanguages({
|
||||
owner: repository.owner,
|
||||
repo: repository.repo,
|
||||
});
|
||||
|
|
@ -893,7 +894,7 @@ export async function getLanguagesInRepo(
|
|||
// Since sets in javascript maintain insertion order, using a set here and then splatting it
|
||||
// into an array gives us an array of languages ordered by popularity
|
||||
const languages: Set<LanguageOrAlias> = new Set();
|
||||
for (const lang of Object.keys(response.data)) {
|
||||
for (const lang of Object.keys(response.data as Record<string, number>)) {
|
||||
const parsedLang = parseLanguage(lang);
|
||||
if (parsedLang !== undefined) {
|
||||
languages.add(parsedLang);
|
||||
|
|
@ -938,7 +939,7 @@ export async function getLanguages(
|
|||
// If the languages parameter was not given and no languages were
|
||||
// detected then fail here as this is a workflow configuration error.
|
||||
if (languages.length === 0) {
|
||||
throw new Error(getNoLanguagesError());
|
||||
throw new UserError(getNoLanguagesError());
|
||||
}
|
||||
|
||||
// Make sure they are supported
|
||||
|
|
@ -957,7 +958,7 @@ export async function getLanguages(
|
|||
// Any unknown languages here would have come directly from the input
|
||||
// since we filter unknown languages coming from the GitHub API.
|
||||
if (unknownLanguages.length > 0) {
|
||||
throw new Error(getUnknownLanguagesError(unknownLanguages));
|
||||
throw new UserError(getUnknownLanguagesError(unknownLanguages));
|
||||
}
|
||||
|
||||
return parsedLanguages;
|
||||
|
|
@ -1186,10 +1187,10 @@ async function loadConfig(
|
|||
// even though we don't use the value yet.
|
||||
if (NAME_PROPERTY in parsedYAML) {
|
||||
if (typeof parsedYAML[NAME_PROPERTY] !== "string") {
|
||||
throw new Error(getNameInvalid(configFile));
|
||||
throw new UserError(getNameInvalid(configFile));
|
||||
}
|
||||
if (parsedYAML[NAME_PROPERTY]!.length === 0) {
|
||||
throw new Error(getNameInvalid(configFile));
|
||||
throw new UserError(getNameInvalid(configFile));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1213,7 +1214,7 @@ async function loadConfig(
|
|||
let disableDefaultQueries = false;
|
||||
if (DISABLE_DEFAULT_QUERIES_PROPERTY in parsedYAML) {
|
||||
if (typeof parsedYAML[DISABLE_DEFAULT_QUERIES_PROPERTY] !== "boolean") {
|
||||
throw new Error(getDisableDefaultQueriesInvalid(configFile));
|
||||
throw new UserError(getDisableDefaultQueriesInvalid(configFile));
|
||||
}
|
||||
disableDefaultQueries = parsedYAML[DISABLE_DEFAULT_QUERIES_PROPERTY]!;
|
||||
}
|
||||
|
|
@ -1259,11 +1260,11 @@ async function loadConfig(
|
|||
) {
|
||||
const queriesArr = parsedYAML[QUERIES_PROPERTY];
|
||||
if (!Array.isArray(queriesArr)) {
|
||||
throw new Error(getQueriesInvalid(configFile));
|
||||
throw new UserError(getQueriesInvalid(configFile));
|
||||
}
|
||||
for (const query of queriesArr) {
|
||||
if (typeof query[QUERIES_USES_PROPERTY] !== "string") {
|
||||
throw new Error(getQueriesMissingUses(configFile));
|
||||
throw new UserError(getQueriesMissingUses(configFile));
|
||||
}
|
||||
await parseQueryUses(
|
||||
languages,
|
||||
|
|
@ -1283,11 +1284,11 @@ async function loadConfig(
|
|||
|
||||
if (PATHS_IGNORE_PROPERTY in parsedYAML) {
|
||||
if (!Array.isArray(parsedYAML[PATHS_IGNORE_PROPERTY])) {
|
||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||
throw new UserError(getPathsIgnoreInvalid(configFile));
|
||||
}
|
||||
for (const ignorePath of parsedYAML[PATHS_IGNORE_PROPERTY]!) {
|
||||
if (typeof ignorePath !== "string" || ignorePath === "") {
|
||||
throw new Error(getPathsIgnoreInvalid(configFile));
|
||||
throw new UserError(getPathsIgnoreInvalid(configFile));
|
||||
}
|
||||
pathsIgnore.push(
|
||||
validateAndSanitisePath(
|
||||
|
|
@ -1302,11 +1303,11 @@ async function loadConfig(
|
|||
|
||||
if (PATHS_PROPERTY in parsedYAML) {
|
||||
if (!Array.isArray(parsedYAML[PATHS_PROPERTY])) {
|
||||
throw new Error(getPathsInvalid(configFile));
|
||||
throw new UserError(getPathsInvalid(configFile));
|
||||
}
|
||||
for (const includePath of parsedYAML[PATHS_PROPERTY]!) {
|
||||
if (typeof includePath !== "string" || includePath === "") {
|
||||
throw new Error(getPathsInvalid(configFile));
|
||||
throw new UserError(getPathsInvalid(configFile));
|
||||
}
|
||||
paths.push(
|
||||
validateAndSanitisePath(includePath, PATHS_PROPERTY, configFile, logger)
|
||||
|
|
@ -1398,7 +1399,7 @@ function parseQueriesFromInput(
|
|||
? rawQueriesInput.trim().slice(1).trim()
|
||||
: rawQueriesInput?.trim() ?? "";
|
||||
if (queriesInputCombines && trimmedInput.length === 0) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getConfigFilePropertyError(
|
||||
undefined,
|
||||
"queries",
|
||||
|
|
@ -1438,13 +1439,13 @@ export function parsePacksFromConfig(
|
|||
} else {
|
||||
// this is an error since multi-language analysis requires
|
||||
// packs split by language
|
||||
throw new Error(getPacksInvalidSplit(configFile));
|
||||
throw new UserError(getPacksInvalidSplit(configFile));
|
||||
}
|
||||
}
|
||||
|
||||
for (const [lang, packsArr] of Object.entries(packsByLanguage)) {
|
||||
if (!Array.isArray(packsArr)) {
|
||||
throw new Error(getPacksInvalid(configFile));
|
||||
throw new UserError(getPacksInvalid(configFile));
|
||||
}
|
||||
if (!languages.includes(lang as Language)) {
|
||||
// This particular language is not being analyzed in this run.
|
||||
|
|
@ -1455,7 +1456,7 @@ export function parsePacksFromConfig(
|
|||
continue;
|
||||
} else {
|
||||
// This language is invalid, probably a misspelling
|
||||
throw new Error(getPacksRequireLanguage(configFile, lang));
|
||||
throw new UserError(getPacksRequireLanguage(configFile, lang));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1476,18 +1477,20 @@ function parsePacksFromInput(
|
|||
}
|
||||
|
||||
if (languages.length > 1) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
"Cannot specify a 'packs' input in a multi-language analysis. Use a codeql-config.yml file instead and specify packs by language."
|
||||
);
|
||||
} else if (languages.length === 0) {
|
||||
throw new Error("No languages specified. Cannot process the packs input.");
|
||||
throw new UserError(
|
||||
"No languages specified. Cannot process the packs input."
|
||||
);
|
||||
}
|
||||
|
||||
rawPacksInput = rawPacksInput.trim();
|
||||
if (packsInputCombines) {
|
||||
rawPacksInput = rawPacksInput.trim().substring(1).trim();
|
||||
if (!rawPacksInput) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
getConfigFilePropertyError(
|
||||
undefined,
|
||||
"packs",
|
||||
|
|
@ -1528,7 +1531,7 @@ export function parsePacksSpecification(
|
|||
configFile?: string
|
||||
): Pack {
|
||||
if (typeof packStr !== "string") {
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
throw new UserError(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
|
||||
packStr = packStr.trim();
|
||||
|
|
@ -1556,14 +1559,14 @@ export function parsePacksSpecification(
|
|||
: undefined;
|
||||
|
||||
if (!PACK_IDENTIFIER_PATTERN.test(packName)) {
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
throw new UserError(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
if (version) {
|
||||
try {
|
||||
new semver.Range(version);
|
||||
} catch (e) {
|
||||
// The range string is invalid. OK to ignore the caught error
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
throw new UserError(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1577,12 +1580,12 @@ export function parsePacksSpecification(
|
|||
path.normalize(packPath).split(path.sep).join("/") !==
|
||||
packPath.split(path.sep).join("/"))
|
||||
) {
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
throw new UserError(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
|
||||
if (!packPath && pathStart) {
|
||||
// 0 length path
|
||||
throw new Error(getPacksStrInvalid(packStr, configFile));
|
||||
throw new UserError(getPacksStrInvalid(packStr, configFile));
|
||||
}
|
||||
|
||||
return {
|
||||
|
|
@ -1628,7 +1631,7 @@ export function parsePacks(
|
|||
}
|
||||
if (!packsInputCombines) {
|
||||
if (!packsFromInput) {
|
||||
throw new Error(getPacksInvalid(configFile));
|
||||
throw new UserError(getPacksInvalid(configFile));
|
||||
}
|
||||
return packsFromInput;
|
||||
}
|
||||
|
|
@ -1768,7 +1771,7 @@ export async function initConfig(
|
|||
const hasCustomQueries = config.queries[language]?.custom.length > 0;
|
||||
const hasPacks = (config.packs[language]?.length || 0) > 0;
|
||||
if (!hasPacks && !hasBuiltinQueries && !hasCustomQueries) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`Did not detect any queries to run for ${language}. ` +
|
||||
"Please make sure that the default queries are enabled, or you are specifying queries to run."
|
||||
);
|
||||
|
|
@ -1799,7 +1802,7 @@ function parseRegistries(
|
|||
? (yaml.load(registriesInput) as RegistryConfigWithCredentials[])
|
||||
: undefined;
|
||||
} catch (e) {
|
||||
throw new Error("Invalid registries input. Must be a YAML string.");
|
||||
throw new UserError("Invalid registries input. Must be a YAML string.");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1815,12 +1818,12 @@ function isLocal(configPath: string): boolean {
|
|||
function getLocalConfig(configFile: string, workspacePath: string): UserConfig {
|
||||
// Error if the config file is now outside of the workspace
|
||||
if (!(configFile + path.sep).startsWith(workspacePath + path.sep)) {
|
||||
throw new Error(getConfigFileOutsideWorkspaceErrorMessage(configFile));
|
||||
throw new UserError(getConfigFileOutsideWorkspaceErrorMessage(configFile));
|
||||
}
|
||||
|
||||
// Error if the file does not exist
|
||||
if (!fs.existsSync(configFile)) {
|
||||
throw new Error(getConfigFileDoesNotExistErrorMessage(configFile));
|
||||
throw new UserError(getConfigFileDoesNotExistErrorMessage(configFile));
|
||||
}
|
||||
|
||||
return yaml.load(fs.readFileSync(configFile, "utf8")) as UserConfig;
|
||||
|
|
@ -1837,12 +1840,12 @@ async function getRemoteConfig(
|
|||
const pieces = format.exec(configFile);
|
||||
// 5 = 4 groups + the whole expression
|
||||
if (pieces === null || pieces.groups === undefined || pieces.length < 5) {
|
||||
throw new Error(getConfigFileRepoFormatInvalidMessage(configFile));
|
||||
throw new UserError(getConfigFileRepoFormatInvalidMessage(configFile));
|
||||
}
|
||||
|
||||
const response = await api
|
||||
.getApiClientWithExternalAuth(apiDetails)
|
||||
.repos.getContent({
|
||||
.rest.repos.getContent({
|
||||
owner: pieces.groups.owner,
|
||||
repo: pieces.groups.repo,
|
||||
path: pieces.groups.path,
|
||||
|
|
@ -1853,9 +1856,9 @@ async function getRemoteConfig(
|
|||
if ("content" in response.data && response.data.content !== undefined) {
|
||||
fileContents = response.data.content;
|
||||
} else if (Array.isArray(response.data)) {
|
||||
throw new Error(getConfigFileDirectoryGivenMessage(configFile));
|
||||
throw new UserError(getConfigFileDirectoryGivenMessage(configFile));
|
||||
} else {
|
||||
throw new Error(getConfigFileFormatInvalidMessage(configFile));
|
||||
throw new UserError(getConfigFileFormatInvalidMessage(configFile));
|
||||
}
|
||||
|
||||
return yaml.load(
|
||||
|
|
@ -1979,7 +1982,7 @@ export async function generateRegistries(
|
|||
if (
|
||||
!(await codeQlVersionAbove(codeQL, CODEQL_VERSION_GHES_PACK_DOWNLOAD))
|
||||
) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
`The 'registries' input is not supported on CodeQL CLI versions earlier than ${CODEQL_VERSION_GHES_PACK_DOWNLOAD}. Please upgrade to CodeQL CLI version ${CODEQL_VERSION_GHES_PACK_DOWNLOAD} or later.`
|
||||
);
|
||||
}
|
||||
|
|
@ -2018,7 +2021,7 @@ function createRegistriesBlock(registries: RegistryConfigWithCredentials[]): {
|
|||
!Array.isArray(registries) ||
|
||||
registries.some((r) => !r.url || !r.packages)
|
||||
) {
|
||||
throw new Error(
|
||||
throw new UserError(
|
||||
"Invalid 'registries' input. Must be an array of objects with 'url' and 'packages' properties."
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"bundleVersion": "codeql-bundle-v2.13.5",
|
||||
"cliVersion": "2.13.5",
|
||||
"priorBundleVersion": "codeql-bundle-v2.13.4",
|
||||
"priorCliVersion": "2.13.4"
|
||||
"bundleVersion": "codeql-bundle-v2.14.0",
|
||||
"cliVersion": "2.14.0",
|
||||
"priorBundleVersion": "codeql-bundle-v2.13.5",
|
||||
"priorCliVersion": "2.13.5"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ class GitHubFeatureFlags {
|
|||
"This run of the CodeQL Action does not have permission to access Code Scanning API endpoints. " +
|
||||
"As a result, it will not be opted into any experimental features. " +
|
||||
"This could be because the Action is running on a pull request from a fork. If not, " +
|
||||
`please ensure the Action has the 'security-events: write' permission. Details: ${e}`
|
||||
`please ensure the Action has the 'security-events: write' permission. Details: ${e.message}`
|
||||
);
|
||||
this.hasAccessedRemoteFeatureFlags = false;
|
||||
return {};
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ export async function tryFindCliVersionDotcomOnly(
|
|||
);
|
||||
const apiClient = api.getApiClient();
|
||||
const codeQLActionRepository = getCodeQLActionRepository(logger);
|
||||
const release = await apiClient.repos.getReleaseByTag({
|
||||
const release = await apiClient.rest.repos.getReleaseByTag({
|
||||
owner: codeQLActionRepository.split("/")[0],
|
||||
repo: codeQLActionRepository.split("/")[1],
|
||||
tag: tagName,
|
||||
|
|
@ -165,7 +165,7 @@ async function getCodeQLBundleDownloadURL(
|
|||
}
|
||||
const [repositoryOwner, repositoryName] = repository.split("/");
|
||||
try {
|
||||
const release = await api.getApiClient().repos.getReleaseByTag({
|
||||
const release = await api.getApiClient().rest.repos.getReleaseByTag({
|
||||
owner: repositoryOwner,
|
||||
repo: repositoryName,
|
||||
tag: tagName,
|
||||
|
|
|
|||
|
|
@ -199,8 +199,10 @@ export function mockLanguagesInRepo(languages: string[]) {
|
|||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
mockClient.returns({
|
||||
repos: {
|
||||
listLanguages,
|
||||
rest: {
|
||||
repos: {
|
||||
listLanguages,
|
||||
},
|
||||
},
|
||||
} as any);
|
||||
return listLanguages;
|
||||
|
|
|
|||
|
|
@ -214,7 +214,7 @@ function mockGetMetaVersionHeader(
|
|||
},
|
||||
};
|
||||
const spyGetContents = sinon
|
||||
.stub(client.meta, "get")
|
||||
.stub(client.rest.meta, "get")
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-argument
|
||||
.resolves(response as any);
|
||||
sinon.stub(api, "getApiClient").value(() => client);
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@ export async function getGitHubVersion(
|
|||
// Doesn't strictly have to be the meta endpoint as we're only
|
||||
// using the response headers which are available on every request.
|
||||
const apiClient = getApiClient();
|
||||
const response = await apiClient.meta.get();
|
||||
const response = await apiClient.rest.meta.get();
|
||||
|
||||
// This happens on dotcom, although we expect to have already returned in that
|
||||
// case. This can also serve as a fallback in cases we haven't foreseen.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue