Skip to content

Commit

Permalink
Add category input
Browse files Browse the repository at this point in the history
  • Loading branch information
David Verdeguer committed Apr 28, 2021
1 parent 03f029c commit 40fb1f3
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 31 deletions.
3 changes: 3 additions & 0 deletions analyze/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ inputs:
description: "The path at which the analyzed repository was checked out. Used to relativize any absolute paths in the uploaded SARIF file."
required: false
default: ${{ github.workspace }}
category:
description: String used by Code Scanning for matching the analyses
required: false
token:
default: ${{ github.token }}
matrix:
Expand Down
38 changes: 26 additions & 12 deletions lib/upload-lib.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/upload-lib.js.map

Large diffs are not rendered by default.

20 changes: 14 additions & 6 deletions lib/upload-lib.test.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/upload-lib.test.js.map

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

27 changes: 26 additions & 1 deletion src/upload-lib.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,31 @@ test("populateRunAutomationDetails", (t) => {
const analysisKey = ".github/workflows/codeql-analysis.yml:analyze";

let expectedSarif =
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/language:javascript/os:linux/"}}]}';
'{"runs":[{"automationDetails":{"id":"language:javascript/os:linux/"}}]}';

// Category has priority over analysis_key/environment
let modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
"language:javascript/os:linux",
analysisKey,
'{"language": "other", "os": "other"}'
);
t.deepEqual(modifiedSarif, expectedSarif);

// It doesn't matter if the category has a slash at the end or not
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
"language:javascript/os:linux/",
analysisKey,
""
);
t.deepEqual(modifiedSarif, expectedSarif);

expectedSarif =
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/language:javascript/os:linux/"}}]}';
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
undefined,
analysisKey,
'{"language": "javascript", "os": "linux"}'
);
Expand All @@ -149,6 +170,7 @@ test("populateRunAutomationDetails", (t) => {
// check the environment sorting
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
undefined,
analysisKey,
'{"os": "linux", "language": "javascript"}'
);
Expand All @@ -159,6 +181,7 @@ test("populateRunAutomationDetails", (t) => {
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/"}}]}';
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
undefined,
analysisKey,
"{}"
);
Expand All @@ -169,6 +192,7 @@ test("populateRunAutomationDetails", (t) => {
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/number:/object:/"}}]}';
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
undefined,
analysisKey,
'{"number": 1, "object": {"language": "javascript"}}'
);
Expand All @@ -179,6 +203,7 @@ test("populateRunAutomationDetails", (t) => {
expectedSarif = '{"runs":[{"automationDetails":{"id":"my_id"}}]}';
modifiedSarif = uploadLib.populateRunAutomationDetails(
sarif,
undefined,
analysisKey,
'{"os": "linux", "language": "javascript"}'
);
Expand Down
Loading

0 comments on commit 40fb1f3

Please sign in to comment.