Skip to content

Commit 5fc9e66

Browse files
committed
Move findAndUpload to a new module
1 parent 6a87ebe commit 5fc9e66

File tree

3 files changed

+64
-55
lines changed

3 files changed

+64
-55
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 & 54 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,60 +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 (
65-
pathStats.isFile() &&
66-
(analysis.sarifPredicate(sarifPath) ||
67-
(analysis.kind === analyses.AnalysisKind.CodeScanning &&
68-
!analyses.CodeQuality.sarifPredicate(sarifPath)))
69-
) {
70-
sarifFiles = [sarifPath];
71-
} else {
72-
return undefined;
73-
}
74-
75-
if (sarifFiles.length !== 0) {
76-
return await upload_lib.uploadSpecifiedFiles(
77-
sarifFiles,
78-
checkoutPath,
79-
category,
80-
features,
81-
logger,
82-
analysis,
83-
);
84-
}
85-
86-
return undefined;
87-
}
88-
8936
async function sendSuccessStatusReport(
9037
startedAt: Date,
9138
uploadStats: upload_lib.UploadStatusReport,

src/upload-sarif.ts

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
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 (
38+
pathStats.isFile() &&
39+
(analysis.sarifPredicate(sarifPath) ||
40+
(analysis.kind === analyses.AnalysisKind.CodeScanning &&
41+
!analyses.CodeQuality.sarifPredicate(sarifPath)))
42+
) {
43+
sarifFiles = [sarifPath];
44+
} else {
45+
return undefined;
46+
}
47+
48+
if (sarifFiles.length !== 0) {
49+
return await upload_lib.uploadSpecifiedFiles(
50+
sarifFiles,
51+
checkoutPath,
52+
category,
53+
features,
54+
logger,
55+
analysis,
56+
);
57+
}
58+
59+
return undefined;
60+
}

0 commit comments

Comments
 (0)