Refactor prepareFailedSarif out of maybeUploadFailedSarif

This commit is contained in:
Michael B. Gale
2026-02-26 18:04:21 +00:00
parent 56d1ccc87a
commit 60ca40ecd4
2 changed files with 95 additions and 20 deletions
+47 -7
View File
@@ -163855,6 +163855,34 @@ async function asyncSome(array, predicate) {
const results = await Promise.all(array.map(predicate));
return results.some((result) => result);
}
var Success = class {
constructor(value) {
this.value = value;
}
isSuccess() {
return true;
}
isFailure() {
return false;
}
orElse(_defaultValue) {
return this.value;
}
};
var Failure = class {
constructor(value) {
this.value = value;
}
isSuccess() {
return false;
}
isFailure() {
return true;
}
orElse(defaultValue) {
return defaultValue;
}
};
// src/actions-util.ts
var pkg = require_package();
@@ -169755,9 +169783,11 @@ function createFailedUploadFailedSarifResult(error3) {
upload_failed_run_stack_trace: wrappedError.stack
};
}
async function maybeUploadFailedSarif(config, repositoryNwo, features, logger) {
async function prepareFailedSarif(logger, features, config) {
if (!config.codeQLCmd) {
return { upload_failed_run_skipped_because: "CodeQL command not found" };
return new Failure({
upload_failed_run_skipped_because: "CodeQL command not found"
});
}
const workflow = await getWorkflow(logger);
const jobName = getRequiredEnvParam("GITHUB_JOB");
@@ -169766,7 +169796,9 @@ async function maybeUploadFailedSarif(config, repositoryNwo, features, logger) {
if (!["always", "failure-only"].includes(
getUploadValue(shouldUpload)
) || shouldSkipSarifUpload()) {
return { upload_failed_run_skipped_because: "SARIF upload is disabled" };
return new Failure({
upload_failed_run_skipped_because: "SARIF upload is disabled"
});
}
const category = getCategoryInputOrThrow(workflow, jobName, matrix);
const checkoutPath = getCheckoutPathInputOrThrow(workflow, jobName, matrix);
@@ -169778,11 +169810,19 @@ async function maybeUploadFailedSarif(config, repositoryNwo, features, logger) {
} else {
await codeql.databaseExportDiagnostics(databasePath, sarifFile, category);
}
logger.info(`Uploading failed SARIF file ${sarifFile}`);
return new Success({ sarifFile, category, checkoutPath });
}
async function maybeUploadFailedSarif(config, repositoryNwo, features, logger) {
const failedSarifResult = await prepareFailedSarif(logger, features, config);
if (failedSarifResult.isFailure()) {
return failedSarifResult.value;
}
const failedSarif = failedSarifResult.value;
logger.info(`Uploading failed SARIF file ${failedSarif.sarifFile}`);
const uploadResult = await uploadFiles(
sarifFile,
checkoutPath,
category,
failedSarif.sarifFile,
failedSarif.checkoutPath,
failedSarif.category,
features,
logger,
CodeScanning