Skip to content

Commit f6cd153

Browse files
committed
Refactor finding SARIF files for the different upload endpoints
1 parent cca7e64 commit f6cd153

File tree

3 files changed

+53
-24
lines changed

3 files changed

+53
-24
lines changed

lib/upload-sarif-action.js

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

lib/upload-sarif-action.js.map

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

src/upload-sarif-action.ts

Lines changed: 35 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,28 @@ async function sendSuccessStatusReport(
5353
}
5454
}
5555

56+
async function findSecuritySarifFiles(sarifPath: string): Promise<string[]> {
57+
if (fs.lstatSync(sarifPath).isDirectory()) {
58+
return upload_lib.findSarifFilesInDir(
59+
sarifPath,
60+
upload_lib.CodeScanningTarget.sarifPredicate,
61+
);
62+
}
63+
64+
return [sarifPath];
65+
}
66+
67+
async function findQualitySarifFiles(sarifPath: string): Promise<string[]> {
68+
if (fs.lstatSync(sarifPath).isDirectory()) {
69+
return upload_lib.findSarifFilesInDir(
70+
sarifPath,
71+
upload_lib.CodeQualityTarget.sarifPredicate,
72+
);
73+
}
74+
75+
return [];
76+
}
77+
5678
async function run() {
5779
const startedAt = new Date();
5880
const logger = getActionsLogger();
@@ -89,8 +111,11 @@ async function run() {
89111
const checkoutPath = actionsUtil.getRequiredInput("checkout_path");
90112
const category = actionsUtil.getOptionalInput("category");
91113

92-
const uploadResult = await upload_lib.uploadFiles(
93-
sarifPath,
114+
const securitySarifFiles = await findSecuritySarifFiles(sarifPath);
115+
const qualitySarifFiles = await findQualitySarifFiles(sarifPath);
116+
117+
const uploadResult = await upload_lib.uploadSpecifiedFiles(
118+
securitySarifFiles,
94119
checkoutPath,
95120
category,
96121
features,
@@ -102,22 +127,15 @@ async function run() {
102127
// If there are `.quality.sarif` files in `sarifPath`, then upload those to the code quality service.
103128
// Code quality can currently only be enabled on top of security, so we'd currently always expect to
104129
// have a directory for the results here.
105-
if (fs.lstatSync(sarifPath).isDirectory()) {
106-
const qualitySarifFiles = upload_lib.findSarifFilesInDir(
107-
sarifPath,
108-
upload_lib.CodeQualityTarget.sarifPredicate,
130+
if (qualitySarifFiles.length !== 0) {
131+
await upload_lib.uploadSpecifiedFiles(
132+
qualitySarifFiles,
133+
checkoutPath,
134+
category,
135+
features,
136+
logger,
137+
upload_lib.CodeQualityTarget,
109138
);
110-
111-
if (qualitySarifFiles.length !== 0) {
112-
await upload_lib.uploadSpecifiedFiles(
113-
qualitySarifFiles,
114-
checkoutPath,
115-
category,
116-
features,
117-
logger,
118-
upload_lib.CodeQualityTarget,
119-
);
120-
}
121139
}
122140

123141
// We don't upload results in test mode, so don't wait for processing

0 commit comments

Comments
 (0)