From 5fc9e66105b444f1ef097d1a09900e4d0d0b5270 Mon Sep 17 00:00:00 2001 From: "Michael B. Gale" Date: Mon, 29 Sep 2025 08:44:44 +0100 Subject: [PATCH] Move `findAndUpload` to a new module --- lib/upload-sarif-action.js | 4 ++- src/upload-sarif-action.ts | 55 +--------------------------------- src/upload-sarif.ts | 60 ++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 55 deletions(-) create mode 100644 src/upload-sarif.ts diff --git a/lib/upload-sarif-action.js b/lib/upload-sarif-action.js index a79e1b068..92bb88084 100644 --- a/lib/upload-sarif-action.js +++ b/lib/upload-sarif-action.js @@ -93416,7 +93416,7 @@ function filterAlertsByDiffRange(logger, sarif) { return sarif; } -// src/upload-sarif-action.ts +// src/upload-sarif.ts async function findAndUpload(logger, features, sarifPath, pathStats, checkoutPath, analysis, category) { let sarifFiles; if (pathStats.isDirectory()) { @@ -93441,6 +93441,8 @@ async function findAndUpload(logger, features, sarifPath, pathStats, checkoutPat } return void 0; } + +// src/upload-sarif-action.ts async function sendSuccessStatusReport(startedAt, uploadStats, logger) { const statusReportBase = await createStatusReportBase( "upload-sarif" /* UploadSarif */, diff --git a/src/upload-sarif-action.ts b/src/upload-sarif-action.ts index 4da042749..940faf720 100644 --- a/src/upload-sarif-action.ts +++ b/src/upload-sarif-action.ts @@ -18,6 +18,7 @@ import { isThirdPartyAnalysis, } from "./status-report"; import * as upload_lib from "./upload-lib"; +import { findAndUpload } from "./upload-sarif"; import { ConfigurationError, checkActionVersion, @@ -32,60 +33,6 @@ interface UploadSarifStatusReport extends StatusReportBase, upload_lib.UploadStatusReport {} -/** - * Searches for SARIF files for the given `analysis` in the given `sarifPath`. - * If any are found, then they are uploaded to the appropriate endpoint for the given `analysis`. - * - * @param logger The logger to use. - * @param features Information about FFs. - * @param sarifPath The path to a SARIF file or directory containing SARIF files. - * @param pathStats Information about `sarifPath`. - * @param checkoutPath The checkout path. - * @param analysis The configuration of the analysis we should upload SARIF files for. - * @param category The SARIF category to use for the upload. - * @returns The result of uploading the SARIF file(s) or `undefined` if there are none. - */ -async function findAndUpload( - logger: Logger, - features: Features, - sarifPath: string, - pathStats: fs.Stats, - checkoutPath: string, - analysis: analyses.AnalysisConfig, - category?: string, -): Promise { - let sarifFiles: string[] | undefined; - - if (pathStats.isDirectory()) { - sarifFiles = upload_lib.findSarifFilesInDir( - sarifPath, - analysis.sarifPredicate, - ); - } else if ( - pathStats.isFile() && - (analysis.sarifPredicate(sarifPath) || - (analysis.kind === analyses.AnalysisKind.CodeScanning && - !analyses.CodeQuality.sarifPredicate(sarifPath))) - ) { - sarifFiles = [sarifPath]; - } else { - return undefined; - } - - if (sarifFiles.length !== 0) { - return await upload_lib.uploadSpecifiedFiles( - sarifFiles, - checkoutPath, - category, - features, - logger, - analysis, - ); - } - - return undefined; -} - async function sendSuccessStatusReport( startedAt: Date, uploadStats: upload_lib.UploadStatusReport, diff --git a/src/upload-sarif.ts b/src/upload-sarif.ts new file mode 100644 index 000000000..ad43f3263 --- /dev/null +++ b/src/upload-sarif.ts @@ -0,0 +1,60 @@ +import * as fs from "fs"; + +import * as analyses from "./analyses"; +import { Features } from "./feature-flags"; +import { Logger } from "./logging"; +import * as upload_lib from "./upload-lib"; + +/** + * Searches for SARIF files for the given `analysis` in the given `sarifPath`. + * If any are found, then they are uploaded to the appropriate endpoint for the given `analysis`. + * + * @param logger The logger to use. + * @param features Information about FFs. + * @param sarifPath The path to a SARIF file or directory containing SARIF files. + * @param pathStats Information about `sarifPath`. + * @param checkoutPath The checkout path. + * @param analysis The configuration of the analysis we should upload SARIF files for. + * @param category The SARIF category to use for the upload. + * @returns The result of uploading the SARIF file(s) or `undefined` if there are none. + */ +export async function findAndUpload( + logger: Logger, + features: Features, + sarifPath: string, + pathStats: fs.Stats, + checkoutPath: string, + analysis: analyses.AnalysisConfig, + category?: string, +): Promise { + let sarifFiles: string[] | undefined; + + if (pathStats.isDirectory()) { + sarifFiles = upload_lib.findSarifFilesInDir( + sarifPath, + analysis.sarifPredicate, + ); + } else if ( + pathStats.isFile() && + (analysis.sarifPredicate(sarifPath) || + (analysis.kind === analyses.AnalysisKind.CodeScanning && + !analyses.CodeQuality.sarifPredicate(sarifPath))) + ) { + sarifFiles = [sarifPath]; + } else { + return undefined; + } + + if (sarifFiles.length !== 0) { + return await upload_lib.uploadSpecifiedFiles( + sarifFiles, + checkoutPath, + category, + features, + logger, + analysis, + ); + } + + return undefined; +}