Skip to content

Commit 01d7f67

Browse files
committed
Include custom query help in analysis results
1 parent ff3272d commit 01d7f67

File tree

7 files changed

+86
-3
lines changed

7 files changed

+86
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
## [UNRELEASED]
44

55
- The `init` step of the Action now supports `ram` and `threads` inputs to limit resource use of CodeQL extractors. These inputs also serve as defaults to the subsequent `analyze` step, which finalizes the database and executes queries. [#738](https://github.com/github/codeql-action/pull/738)
6+
- When used with CodeQL 2.7.1 or above, the Action now includes custom query help in the analysis results uploaded to GitHub code scanning, if available. To add help text for a custom query, create a Markdown file next to the `.ql` file containing the query, using the same base name but the file extension `.md`. [#804](https://github.com/github/codeql-action/pull/804)
67

78
## 1.0.21 - 28 Oct 2021
89

lib/codeql.js

+13-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js

+23
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/codeql.test.js.map

+1-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/codeql.test.ts

+35
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import * as path from "path";
22

3+
import * as toolrunner from "@actions/exec/lib/toolrunner";
34
import * as toolcache from "@actions/tool-cache";
45
import test from "ava";
56
import nock from "nock";
7+
import * as sinon from "sinon";
68

79
import * as codeql from "./codeql";
810
import * as defaults from "./defaults.json";
@@ -400,3 +402,36 @@ test("getCodeQLActionRepository", (t) => {
400402
const repoEnv = codeql.getCodeQLActionRepository(logger);
401403
t.deepEqual(repoEnv, "xxx/yyy");
402404
});
405+
406+
test("databaseInterpretResults() does not set --sarif-add-query-help for 2.7.0", async (t) => {
407+
const runnerConstructorStub = stubToolRunnerConstructor();
408+
const codeqlObject = await codeql.getCodeQLForTesting();
409+
sinon.stub(codeqlObject, "getVersion").resolves("2.7.0");
410+
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
411+
t.false(
412+
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
413+
"--sarif-add-query-help is present"
414+
);
415+
});
416+
417+
test("databaseInterpretResults() sets --sarif-add-query-help for 2.7.1", async (t) => {
418+
const runnerConstructorStub = stubToolRunnerConstructor();
419+
const codeqlObject = await codeql.getCodeQLForTesting();
420+
sinon.stub(codeqlObject, "getVersion").resolves("2.7.1");
421+
await codeqlObject.databaseInterpretResults("", [], "", "", "", "");
422+
t.true(
423+
runnerConstructorStub.firstCall.args[1].includes("--sarif-add-query-help"),
424+
"--sarif-add-query-help is present"
425+
);
426+
});
427+
428+
function stubToolRunnerConstructor(): sinon.SinonStub<
429+
any[],
430+
toolrunner.ToolRunner
431+
> {
432+
const runnerObjectStub = sinon.createStubInstance(toolrunner.ToolRunner);
433+
runnerObjectStub.exec.resolves(0);
434+
const runnerConstructorStub = sinon.stub(toolrunner, "ToolRunner");
435+
runnerConstructorStub.returns(runnerObjectStub);
436+
return runnerConstructorStub;
437+
}

src/codeql.ts

+12
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,7 @@ const CODEQL_VERSION_METRICS = "2.5.5";
213213
const CODEQL_VERSION_GROUP_RULES = "2.5.5";
214214
const CODEQL_VERSION_SARIF_GROUP = "2.5.3";
215215
export const CODEQL_VERSION_COUNTS_LINES = "2.6.2";
216+
const CODEQL_VERSION_CUSTOM_QUERY_HELP = "2.7.1";
216217

217218
/**
218219
* Version above which we use the CLI's indirect build tracing and
@@ -599,6 +600,15 @@ export function getCachedCodeQL(): CodeQL {
599600
return cachedCodeQL;
600601
}
601602

603+
/**
604+
* Get a real, newly created CodeQL instance for testing. The instance refers to
605+
* a non-existent placeholder codeql command, so tests that use this function
606+
* should also stub the toolrunner.ToolRunner constructor.
607+
*/
608+
export async function getCodeQLForTesting(): Promise<CodeQL> {
609+
return getCodeQLForCmd("codeql-for-testing", false);
610+
}
611+
602612
async function getCodeQLForCmd(
603613
cmd: string,
604614
checkVersion: boolean
@@ -875,6 +885,8 @@ async function getCodeQLForCmd(
875885
codeqlArgs.push("--print-metrics-summary");
876886
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_GROUP_RULES))
877887
codeqlArgs.push("--sarif-group-rules-by-pack");
888+
if (await util.codeQlVersionAbove(this, CODEQL_VERSION_CUSTOM_QUERY_HELP))
889+
codeqlArgs.push("--sarif-add-query-help");
878890
if (
879891
automationDetailsId !== undefined &&
880892
(await util.codeQlVersionAbove(this, CODEQL_VERSION_SARIF_GROUP))

0 commit comments

Comments
 (0)