Skip to content

Commit bbc0dc8

Browse files
authored
Merge pull request #2 from github/send-tool-names
Send tool names to upload endpoint
2 parents 606ff65 + 62f756f commit bbc0dc8

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
lines changed

.github/pull_request_template.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
### Merge / deployment checklist
22

3-
- Run test builds as necessary. Can be on this repository or elsewhere as needed in order to test the change - please include links to tests in otehr repos!
3+
- Run test builds as necessary. Can be on this repository or elsewhere as needed in order to test the change - please include links to tests in other repos!
44
- [ ] CodeQL using init/finish actions
55
- [ ] 3rd party tool using upload action
66
- [ ] Confirm this change is backwards compatible with existing workflows.
7-
- [ ] Confirm the [readme](https://github.com/github/codeql-action/blob/master/README.md) has been updated if necessary.
7+
- [ ] Confirm the [readme](https://github.com/github/codeql-action/blob/master/README.md) has been updated if necessary.

lib/upload-lib.js

Lines changed: 3 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/util.js

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/testdata/tool-names.sarif

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{
2+
"$schema": "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
3+
"version": "2.1.0",
4+
"runs": [
5+
{
6+
"tool": {
7+
"driver": {
8+
"name": "CodeQL command-line toolchain"
9+
}
10+
}
11+
},
12+
{
13+
"tool": {
14+
"driver": {
15+
"name": "CodeQL command-line toolchain"
16+
}
17+
}
18+
},
19+
{
20+
"tool": {
21+
"driver": {
22+
"name": "ESLint"
23+
}
24+
}
25+
},
26+
{
27+
"tool": {
28+
"driver": {
29+
"name": ""
30+
}
31+
}
32+
},
33+
{
34+
"tool": {
35+
"driver": {
36+
"name": null
37+
}
38+
}
39+
}
40+
]
41+
}

src/upload-lib.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ async function uploadFiles(sarifFiles: string[]) {
9898
matrix = undefined;
9999
}
100100

101+
const toolNames = util.getToolNames(sarifPayload);
102+
101103
const payload = JSON.stringify({
102104
"commit_oid": commitOid,
103105
"ref": ref,
@@ -106,7 +108,8 @@ async function uploadFiles(sarifFiles: string[]) {
106108
"workflow_run_id": workflowRunID,
107109
"checkout_uri": checkoutURI,
108110
"environment": matrix,
109-
"started_at": startedAt
111+
"started_at": startedAt,
112+
"tool_names": toolNames,
110113
});
111114

112115
core.info('Uploading results');

src/util.test.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import * as fs from 'fs';
2+
3+
import * as util from './util';
4+
5+
test('getToolNames', () => {
6+
const input = fs.readFileSync(__dirname + '/testdata/tool-names.sarif', 'utf8')
7+
const toolNames = util.getToolNames(input);
8+
expect(toolNames).toStrictEqual(["CodeQL command-line toolchain", "ESLint"])
9+
})

src/util.ts

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,3 +293,23 @@ export async function reportActionFailed(action: string, cause?: string, excepti
293293
export async function reportActionSucceeded(action: string) {
294294
await sendStatusReport(await createStatusReport(action, 'success'));
295295
}
296+
297+
/**
298+
* Get the array of all the tool names contained in the given sarif contents.
299+
*
300+
* Returns an array of unique string tool names.
301+
*/
302+
export function getToolNames(sarifContents: string): string[] {
303+
const sarif = JSON.parse(sarifContents);
304+
const toolNames = {};
305+
306+
for (const run of sarif.runs || []) {
307+
const tool = run.tool || {};
308+
const driver = tool.driver || {};
309+
if (typeof driver.name === "string" && driver.name.length > 0) {
310+
toolNames[driver.name] = true;
311+
}
312+
}
313+
314+
return Object.keys(toolNames);
315+
}

0 commit comments

Comments
 (0)