Skip to content

Commit 40fb1f3

Browse files
committed
Add category input
1 parent 03f029c commit 40fb1f3

File tree

8 files changed

+111
-31
lines changed

8 files changed

+111
-31
lines changed

analyze/action.yml

+3
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,9 @@ inputs:
2727
description: "The path at which the analyzed repository was checked out. Used to relativize any absolute paths in the uploaded SARIF file."
2828
required: false
2929
default: ${{ github.workspace }}
30+
category:
31+
description: String used by Code Scanning for matching the analyses
32+
required: false
3033
token:
3134
default: ${{ github.token }}
3235
matrix:

lib/upload-lib.js

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

lib/upload-lib.js.map

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

lib/upload-lib.test.js

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

lib/upload-lib.test.js.map

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

src/upload-lib.test.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -137,10 +137,31 @@ test("populateRunAutomationDetails", (t) => {
137137
const analysisKey = ".github/workflows/codeql-analysis.yml:analyze";
138138

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

142+
// Category has priority over analysis_key/environment
142143
let modifiedSarif = uploadLib.populateRunAutomationDetails(
143144
sarif,
145+
"language:javascript/os:linux",
146+
analysisKey,
147+
'{"language": "other", "os": "other"}'
148+
);
149+
t.deepEqual(modifiedSarif, expectedSarif);
150+
151+
// It doesn't matter if the category has a slash at the end or not
152+
modifiedSarif = uploadLib.populateRunAutomationDetails(
153+
sarif,
154+
"language:javascript/os:linux/",
155+
analysisKey,
156+
""
157+
);
158+
t.deepEqual(modifiedSarif, expectedSarif);
159+
160+
expectedSarif =
161+
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/language:javascript/os:linux/"}}]}';
162+
modifiedSarif = uploadLib.populateRunAutomationDetails(
163+
sarif,
164+
undefined,
144165
analysisKey,
145166
'{"language": "javascript", "os": "linux"}'
146167
);
@@ -149,6 +170,7 @@ test("populateRunAutomationDetails", (t) => {
149170
// check the environment sorting
150171
modifiedSarif = uploadLib.populateRunAutomationDetails(
151172
sarif,
173+
undefined,
152174
analysisKey,
153175
'{"os": "linux", "language": "javascript"}'
154176
);
@@ -159,6 +181,7 @@ test("populateRunAutomationDetails", (t) => {
159181
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/"}}]}';
160182
modifiedSarif = uploadLib.populateRunAutomationDetails(
161183
sarif,
184+
undefined,
162185
analysisKey,
163186
"{}"
164187
);
@@ -169,6 +192,7 @@ test("populateRunAutomationDetails", (t) => {
169192
'{"runs":[{"automationDetails":{"id":".github/workflows/codeql-analysis.yml:analyze/number:/object:/"}}]}';
170193
modifiedSarif = uploadLib.populateRunAutomationDetails(
171194
sarif,
195+
undefined,
172196
analysisKey,
173197
'{"number": 1, "object": {"language": "javascript"}}'
174198
);
@@ -179,6 +203,7 @@ test("populateRunAutomationDetails", (t) => {
179203
expectedSarif = '{"runs":[{"automationDetails":{"id":"my_id"}}]}';
180204
modifiedSarif = uploadLib.populateRunAutomationDetails(
181205
sarif,
206+
undefined,
182207
analysisKey,
183208
'{"os": "linux", "language": "javascript"}'
184209
);

0 commit comments

Comments
 (0)