Skip to content

Commit fc88436

Browse files
committed
Move findAndUpload to new upload-sarif module
1 parent 9753473 commit fc88436

File tree

3 files changed

+59
-50
lines changed

3 files changed

+59
-50
lines changed

lib/upload-sarif-action.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.

src/upload-sarif-action.ts

Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import {
1818
isThirdPartyAnalysis,
1919
} from "./status-report";
2020
import * as upload_lib from "./upload-lib";
21+
import { findAndUpload } from "./upload-sarif";
2122
import {
2223
ConfigurationError,
2324
checkActionVersion,
@@ -32,55 +33,6 @@ interface UploadSarifStatusReport
3233
extends StatusReportBase,
3334
upload_lib.UploadStatusReport {}
3435

35-
/**
36-
* Searches for SARIF files for the given `analysis` in the given `sarifPath`.
37-
* If any are found, then they are uploaded to the appropriate endpoint for the given `analysis`.
38-
*
39-
* @param logger The logger to use.
40-
* @param features Information about FFs.
41-
* @param sarifPath The path to a SARIF file or directory containing SARIF files.
42-
* @param pathStats Information about `sarifPath`.
43-
* @param checkoutPath The checkout path.
44-
* @param analysis The configuration of the analysis we should upload SARIF files for.
45-
* @param category The SARIF category to use for the upload.
46-
* @returns The result of uploading the SARIF file(s) or `undefined` if there are none.
47-
*/
48-
async function findAndUpload(
49-
logger: Logger,
50-
features: Features,
51-
sarifPath: string,
52-
pathStats: fs.Stats,
53-
checkoutPath: string,
54-
analysis: analyses.AnalysisConfig,
55-
category?: string,
56-
): Promise<upload_lib.UploadResult | undefined> {
57-
let sarifFiles: string[] | undefined;
58-
59-
if (pathStats.isDirectory()) {
60-
sarifFiles = upload_lib.findSarifFilesInDir(
61-
sarifPath,
62-
analysis.sarifPredicate,
63-
);
64-
} else if (pathStats.isFile() && analysis.sarifPredicate(sarifPath)) {
65-
sarifFiles = [sarifPath];
66-
} else {
67-
return undefined;
68-
}
69-
70-
if (sarifFiles.length !== 0) {
71-
return await upload_lib.uploadSpecifiedFiles(
72-
sarifFiles,
73-
checkoutPath,
74-
category,
75-
features,
76-
logger,
77-
analysis,
78-
);
79-
}
80-
81-
return undefined;
82-
}
83-
8436
async function sendSuccessStatusReport(
8537
startedAt: Date,
8638
uploadStats: upload_lib.UploadStatusReport,

src/upload-sarif.ts

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
import * as fs from "fs";
2+
3+
import * as analyses from "./analyses";
4+
import { Features } from "./feature-flags";
5+
import { Logger } from "./logging";
6+
import * as upload_lib from "./upload-lib";
7+
8+
/**
9+
* Searches for SARIF files for the given `analysis` in the given `sarifPath`.
10+
* If any are found, then they are uploaded to the appropriate endpoint for the given `analysis`.
11+
*
12+
* @param logger The logger to use.
13+
* @param features Information about FFs.
14+
* @param sarifPath The path to a SARIF file or directory containing SARIF files.
15+
* @param pathStats Information about `sarifPath`.
16+
* @param checkoutPath The checkout path.
17+
* @param analysis The configuration of the analysis we should upload SARIF files for.
18+
* @param category The SARIF category to use for the upload.
19+
* @returns The result of uploading the SARIF file(s) or `undefined` if there are none.
20+
*/
21+
export async function findAndUpload(
22+
logger: Logger,
23+
features: Features,
24+
sarifPath: string,
25+
pathStats: fs.Stats,
26+
checkoutPath: string,
27+
analysis: analyses.AnalysisConfig,
28+
category?: string,
29+
): Promise<upload_lib.UploadResult | undefined> {
30+
let sarifFiles: string[] | undefined;
31+
32+
if (pathStats.isDirectory()) {
33+
sarifFiles = upload_lib.findSarifFilesInDir(
34+
sarifPath,
35+
analysis.sarifPredicate,
36+
);
37+
} else if (pathStats.isFile() && analysis.sarifPredicate(sarifPath)) {
38+
sarifFiles = [sarifPath];
39+
} else {
40+
return undefined;
41+
}
42+
43+
if (sarifFiles.length !== 0) {
44+
return await upload_lib.uploadSpecifiedFiles(
45+
sarifFiles,
46+
checkoutPath,
47+
category,
48+
features,
49+
logger,
50+
analysis,
51+
);
52+
}
53+
54+
return undefined;
55+
}

0 commit comments

Comments
 (0)