Skip to content

Commit

Permalink
Allow the version of the ML-powered pack to depend on the CLI version
Browse files Browse the repository at this point in the history
  • Loading branch information
henrymercer committed Mar 31, 2022
1 parent dd6b592 commit 2c03704
Show file tree
Hide file tree
Showing 9 changed files with 31 additions and 26 deletions.
5 changes: 2 additions & 3 deletions lib/codeql.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/codeql.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/config-utils.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/config-utils.js.map

Large diffs are not rendered by default.

14 changes: 8 additions & 6 deletions lib/util.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion lib/util.js.map

Large diffs are not rendered by default.

9 changes: 5 additions & 4 deletions src/codeql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import { Logger } from "./logging";
import * as toolcache from "./toolcache";
import { toolrunnerErrorCatcher } from "./toolrunner-error-catcher";
import * as util from "./util";
import { isGoodVersion, ML_POWERED_JS_QUERIES_PACK } from "./util";
import { isGoodVersion } from "./util";

type Options = Array<string | number | boolean>;

Expand Down Expand Up @@ -741,9 +741,10 @@ async function getCodeQLForCmd(
if (config.injectedMlQueries) {
// We need to inject the ML queries into the original user input before
// we pass this on to the CLI, to make sure these get run.
let packString = ML_POWERED_JS_QUERIES_PACK.packName;
if (ML_POWERED_JS_QUERIES_PACK.version)
packString = `${packString}@${ML_POWERED_JS_QUERIES_PACK.version}`;
const pack = await util.getMlPoweredJsQueriesPack(codeql);
const packString =
pack.packName + (pack.version ? `@${pack.version}` : "");

if (augmentedConfig.packs === undefined) augmentedConfig.packs = [];
if (Array.isArray(augmentedConfig.packs)) {
augmentedConfig.packs.push(packString);
Expand Down
7 changes: 4 additions & 3 deletions src/config-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ import { Logger } from "./logging";
import { RepositoryNwo } from "./repository";
import {
codeQlVersionAbove,
getMlPoweredJsQueriesPack,
GitHubVersion,
ML_POWERED_JS_QUERIES_PACK,
ML_POWERED_JS_QUERIES_PACK_NAME,
} from "./util";

// Property names from the user-supplied config file.
Expand Down Expand Up @@ -304,15 +305,15 @@ async function addBuiltinSuiteQueries(
languages.includes("javascript") &&
(found === "security-extended" || found === "security-and-quality") &&
!packs.javascript?.some(
(pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK.packName
(pack) => pack.packName === ML_POWERED_JS_QUERIES_PACK_NAME
) &&
(await featureFlags.getValue(FeatureFlag.MlPoweredQueriesEnabled)) &&
(await codeQlVersionAbove(codeQL, CODEQL_VERSION_ML_POWERED_QUERIES))
) {
if (!packs.javascript) {
packs.javascript = [];
}
packs.javascript.push(ML_POWERED_JS_QUERIES_PACK);
packs.javascript.push(await getMlPoweredJsQueriesPack(codeQL));
injectedMlQueries = true;
}

Expand Down
12 changes: 7 additions & 5 deletions src/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -657,13 +657,15 @@ export const ML_POWERED_JS_QUERIES_PACK_NAME =
"codeql/javascript-experimental-atm-queries";

/**
* The ML-powered JS query pack to add to the analysis if a repo is opted into the ML-powered
* Gets the ML-powered JS query pack to add to the analysis if a repo is opted into the ML-powered
* queries beta.
*/
export const ML_POWERED_JS_QUERIES_PACK: PackWithVersion = {
packName: "codeql/javascript-experimental-atm-queries",
version: "~0.1.0",
};
export async function getMlPoweredJsQueriesPack(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
_codeQL: CodeQL
): Promise<PackWithVersion> {
return { packName: ML_POWERED_JS_QUERIES_PACK_NAME, version: "~0.1.0" };
}

/**
* Get information about ML-powered JS queries to populate status reports with.
Expand Down

0 comments on commit 2c03704

Please sign in to comment.