refactor: revert getActionsStatus taking an extra argument
This commit is contained in:
parent
b53826d56d
commit
efd29bef22
24 changed files with 38 additions and 115 deletions
|
|
@ -34,7 +34,6 @@ import {
|
|||
createStatusReportBase,
|
||||
DatabaseCreationTimings,
|
||||
getActionsStatus,
|
||||
isFirstPartyAnalysis,
|
||||
StatusReportBase,
|
||||
} from "./status-report";
|
||||
import {
|
||||
|
|
@ -73,12 +72,7 @@ async function sendStatusReport(
|
|||
trapCacheCleanup: TrapCacheCleanupStatusReport | undefined,
|
||||
logger: Logger,
|
||||
) {
|
||||
const isThirdPartyAnalysis = !isFirstPartyAnalysis(ActionName.Analyze);
|
||||
const status = getActionsStatus(
|
||||
isThirdPartyAnalysis,
|
||||
error,
|
||||
stats?.analyze_failure_language,
|
||||
);
|
||||
const status = getActionsStatus(error, stats?.analyze_failure_language);
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
ActionName.Analyze,
|
||||
status,
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import {
|
|||
createStatusReportBase,
|
||||
sendStatusReport,
|
||||
ActionName,
|
||||
isFirstPartyAnalysis,
|
||||
} from "./status-report";
|
||||
import { endTracingForCluster } from "./tracer-config";
|
||||
import {
|
||||
|
|
@ -47,8 +46,7 @@ async function sendCompletedStatusReport(
|
|||
) {
|
||||
initializeEnvironment(getActionVersion());
|
||||
|
||||
const isThirdPartyAnalysis = !isFirstPartyAnalysis(ActionName.Autobuild);
|
||||
const status = getActionsStatus(isThirdPartyAnalysis, cause, failingLanguage);
|
||||
const status = getActionsStatus(cause, failingLanguage);
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
ActionName.Autobuild,
|
||||
status,
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ import {
|
|||
getActionsStatus,
|
||||
ActionName,
|
||||
getJobStatusDisplayName,
|
||||
isFirstPartyAnalysis,
|
||||
} from "./status-report";
|
||||
import { checkDiskUsage, checkGitHubVersionInRange, wrapError } from "./util";
|
||||
|
||||
|
|
@ -75,11 +74,9 @@ async function runWrapper() {
|
|||
const error = wrapError(unwrappedError);
|
||||
core.setFailed(error.message);
|
||||
|
||||
const isThirdPartyAnalysis = !isFirstPartyAnalysis(ActionName.InitPost);
|
||||
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
ActionName.InitPost,
|
||||
getActionsStatus(isThirdPartyAnalysis, error),
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
config,
|
||||
await checkDiskUsage(logger),
|
||||
|
|
|
|||
|
|
@ -51,7 +51,6 @@ import {
|
|||
StatusReportBase,
|
||||
createStatusReportBase,
|
||||
getActionsStatus,
|
||||
isFirstPartyAnalysis,
|
||||
sendStatusReport,
|
||||
} from "./status-report";
|
||||
import { ZstdAvailability } from "./tar";
|
||||
|
|
@ -137,10 +136,9 @@ async function sendCompletedStatusReport(
|
|||
logger: Logger,
|
||||
error?: Error,
|
||||
) {
|
||||
const isThirdPartyAnalysis = !isFirstPartyAnalysis(ActionName.Init);
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
ActionName.Init,
|
||||
getActionsStatus(isThirdPartyAnalysis, error),
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
config,
|
||||
await checkDiskUsage(logger),
|
||||
|
|
|
|||
|
|
@ -16,7 +16,6 @@ import {
|
|||
createStatusReportBase,
|
||||
getActionsStatus,
|
||||
ActionName,
|
||||
isFirstPartyAnalysis,
|
||||
} from "./status-report";
|
||||
import {
|
||||
checkActionVersion,
|
||||
|
|
@ -83,12 +82,9 @@ async function run() {
|
|||
`Failed to resolve a build environment suitable for automatically building your code. ${error.message}`,
|
||||
);
|
||||
|
||||
const isThirdPartyAnalysis = !isFirstPartyAnalysis(
|
||||
ActionName.ResolveEnvironment,
|
||||
);
|
||||
const statusReportBase = await createStatusReportBase(
|
||||
ActionName.ResolveEnvironment,
|
||||
getActionsStatus(isThirdPartyAnalysis, error),
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
config,
|
||||
await checkDiskUsage(logger),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,6 @@ import {
|
|||
setupActionsVars,
|
||||
createTestConfig,
|
||||
} from "./testing-utils";
|
||||
import { InvalidSarifUploadError } from "./upload-lib";
|
||||
import { BuildMode, ConfigurationError, withTmpDir, wrapError } from "./util";
|
||||
|
||||
setupTests(test);
|
||||
|
|
@ -193,37 +192,26 @@ test("createStatusReportBase_firstParty", async (t) => {
|
|||
});
|
||||
|
||||
test("getActionStatus handling correctly various types of errors", (t) => {
|
||||
const isThirdPartyAnalysis = true;
|
||||
const isFirstPartyAnalysis = !isThirdPartyAnalysis;
|
||||
|
||||
t.is(
|
||||
getActionsStatus(isFirstPartyAnalysis, new Error("arbitrary error")),
|
||||
getActionsStatus(new Error("arbitrary error")),
|
||||
"failure",
|
||||
"We categorise an arbitrary error as a failure",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isFirstPartyAnalysis,
|
||||
new ConfigurationError("arbitrary error"),
|
||||
),
|
||||
getActionsStatus(new ConfigurationError("arbitrary error")),
|
||||
"user-error",
|
||||
"We categorise a ConfigurationError as a user error",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isFirstPartyAnalysis,
|
||||
new Error("exit code 1"),
|
||||
"multiple things went wrong",
|
||||
),
|
||||
getActionsStatus(new Error("exit code 1"), "multiple things went wrong"),
|
||||
"failure",
|
||||
"getActionsStatus should return failure if passed an arbitrary error and an additional failure cause",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isFirstPartyAnalysis,
|
||||
new ConfigurationError("exit code 1"),
|
||||
"multiple things went wrong",
|
||||
),
|
||||
|
|
@ -232,47 +220,26 @@ test("getActionStatus handling correctly various types of errors", (t) => {
|
|||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(isFirstPartyAnalysis),
|
||||
getActionsStatus(),
|
||||
"success",
|
||||
"getActionsStatus should return success if no error is passed",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(isFirstPartyAnalysis, new Object()),
|
||||
getActionsStatus(new Object()),
|
||||
"failure",
|
||||
"getActionsStatus should return failure if passed an arbitrary object",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(isFirstPartyAnalysis, null, "an error occurred"),
|
||||
getActionsStatus(null, "an error occurred"),
|
||||
"failure",
|
||||
"getActionsStatus should return failure if passed null and an additional failure cause",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isFirstPartyAnalysis,
|
||||
wrapError(new ConfigurationError("arbitrary error")),
|
||||
),
|
||||
getActionsStatus(wrapError(new ConfigurationError("arbitrary error"))),
|
||||
"user-error",
|
||||
"We still recognise a wrapped ConfigurationError as a user error",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isThirdPartyAnalysis,
|
||||
new InvalidSarifUploadError("SyntaxError: Unexpected end of JSON input"),
|
||||
),
|
||||
"user-error",
|
||||
"We recognise an InvalidSarifUploadError as a user error if the tool that generated the SARIF file is not ours",
|
||||
);
|
||||
|
||||
t.is(
|
||||
getActionsStatus(
|
||||
isFirstPartyAnalysis,
|
||||
new InvalidSarifUploadError("arbitrary error"),
|
||||
),
|
||||
"failure",
|
||||
"We recognise an InvalidSarifUploadError as a failure if the tool that generated the SARIF file is ours",
|
||||
);
|
||||
});
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import { EnvVar } from "./environment";
|
|||
import { getRef } from "./git-utils";
|
||||
import { Logger } from "./logging";
|
||||
import { getRepositoryNwo } from "./repository";
|
||||
import { InvalidSarifUploadError } from "./upload-lib";
|
||||
import {
|
||||
ConfigurationError,
|
||||
isHTTPError,
|
||||
|
|
@ -170,20 +169,11 @@ export interface DatabaseCreationTimings {
|
|||
}
|
||||
|
||||
export function getActionsStatus(
|
||||
isThirdPartyAnalysis: boolean,
|
||||
error?: unknown,
|
||||
otherFailureCause?: string,
|
||||
): ActionStatus {
|
||||
if (error || otherFailureCause) {
|
||||
if (error instanceof ConfigurationError) {
|
||||
return "user-error";
|
||||
}
|
||||
|
||||
if (error instanceof InvalidSarifUploadError && isThirdPartyAnalysis) {
|
||||
return "user-error";
|
||||
}
|
||||
|
||||
return "failure";
|
||||
return error instanceof ConfigurationError ? "user-error" : "failure";
|
||||
} else {
|
||||
return "success";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ async function run() {
|
|||
|
||||
const errorStatusReportBase = await createStatusReportBase(
|
||||
ActionName.UploadSarif,
|
||||
getActionsStatus(isThirdPartyAnalysis, error),
|
||||
getActionsStatus(error),
|
||||
startedAt,
|
||||
undefined,
|
||||
await checkDiskUsage(logger),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue