Skip to content

Commit 89466a3

Browse files
committed
Move findAndUpload to new upload-sarif module
1 parent 88d231a commit 89466a3

File tree

3 files changed

+60
-51
lines changed

3 files changed

+60
-51
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 & 50 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,56 +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-
sarifPredicate: (name: string) => boolean,
56-
category?: string,
57-
): Promise<upload_lib.UploadResult | undefined> {
58-
let sarifFiles: string[] | undefined;
59-
60-
if (pathStats.isDirectory()) {
61-
sarifFiles = upload_lib.findSarifFilesInDir(
62-
sarifPath,
63-
analysis.sarifPredicate,
64-
);
65-
} else if (pathStats.isFile() && sarifPredicate(sarifPath)) {
66-
sarifFiles = [sarifPath];
67-
} else {
68-
return undefined;
69-
}
70-
71-
if (sarifFiles.length !== 0) {
72-
return await upload_lib.uploadSpecifiedFiles(
73-
sarifFiles,
74-
checkoutPath,
75-
category,
76-
features,
77-
logger,
78-
analysis,
79-
);
80-
}
81-
82-
return undefined;
83-
}
84-
8536
async function sendSuccessStatusReport(
8637
startedAt: Date,
8738
uploadStats: upload_lib.UploadStatusReport,

src/upload-sarif.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
sarifPredicate: (name: string) => boolean,
29+
category?: string,
30+
): Promise<upload_lib.UploadResult | undefined> {
31+
let sarifFiles: string[] | undefined;
32+
33+
if (pathStats.isDirectory()) {
34+
sarifFiles = upload_lib.findSarifFilesInDir(
35+
sarifPath,
36+
analysis.sarifPredicate,
37+
);
38+
} else if (pathStats.isFile() && sarifPredicate(sarifPath)) {
39+
sarifFiles = [sarifPath];
40+
} else {
41+
return undefined;
42+
}
43+
44+
if (sarifFiles.length !== 0) {
45+
return await upload_lib.uploadSpecifiedFiles(
46+
sarifFiles,
47+
checkoutPath,
48+
category,
49+
features,
50+
logger,
51+
analysis,
52+
);
53+
}
54+
55+
return undefined;
56+
}

0 commit comments

Comments
 (0)