Split upload method into two mode-specific ones

This commit is contained in:
Sam Partington
2020-11-26 11:37:50 +00:00
parent 7ae9b0db35
commit 57514f31db
12 changed files with 93 additions and 39 deletions

View File

@@ -258,20 +258,34 @@ export async function runAnalyze(
return { ...queriesStats };
}
const uploadStats = await upload_lib.upload(
outputDir,
repositoryNwo,
commitOid,
ref,
analysisKey,
analysisName,
workflowRunID,
checkoutPath,
environment,
apiDetails,
mode,
logger
);
let uploadStats: upload_lib.UploadStatusReport;
if (mode == "actions") {
uploadStats = await upload_lib.uploadFromActions(
outputDir,
repositoryNwo,
commitOid,
ref,
analysisKey!,
analysisName!,
workflowRunID!,
checkoutPath,
environment!,
apiDetails,
logger
);
} else if (mode == "runner") {
uploadStats = await upload_lib.uploadFromRunner(
outputDir,
repositoryNwo,
commitOid,
ref,
checkoutPath,
apiDetails,
logger
);
} else {
throw new Error(`Unknown mode "${mode}"`);
}
return { ...queriesStats, ...uploadStats };
}

View File

@@ -440,18 +440,13 @@ program
url: parseGithubUrl(cmd.githubUrl),
};
try {
await upload_lib.upload(
await upload_lib.uploadFromRunner(
cmd.sarifFile,
parseRepositoryNwo(cmd.repository),
cmd.commit,
parseRef(cmd.ref),
undefined,
undefined,
undefined,
cmd.checkoutPath || process.cwd(),
undefined,
apiDetails,
"runner",
logger
);
} catch (e) {

View File

@@ -83,18 +83,17 @@ export interface UploadStatusReport {
// Uploads a single sarif file or a directory of sarif files
// depending on what the path happens to refer to.
// Returns true iff the upload occurred and succeeded
export async function upload(
export async function uploadFromActions(
sarifPath: string,
repositoryNwo: RepositoryNwo,
commitOid: string,
ref: string,
analysisKey: string | undefined,
analysisName: string | undefined,
workflowRunID: number | undefined,
analysisKey: string,
analysisName: string,
workflowRunID: number,
checkoutPath: string,
environment: string | undefined,
environment: string,
apiDetails: api.GitHubApiDetails,
mode: util.Mode,
logger: Logger
): Promise<UploadStatusReport> {
return await uploadFiles(
@@ -108,7 +107,35 @@ export async function upload(
checkoutPath,
environment,
apiDetails,
mode,
"actions",
logger
);
}
// Uploads a single sarif file or a directory of sarif files
// depending on what the path happens to refer to.
// Returns true iff the upload occurred and succeeded
export async function uploadFromRunner(
sarifPath: string,
repositoryNwo: RepositoryNwo,
commitOid: string,
ref: string,
checkoutPath: string,
apiDetails: api.GitHubApiDetails,
logger: Logger
): Promise<UploadStatusReport> {
return await uploadFiles(
getSarifFilePaths(sarifPath),
repositoryNwo,
commitOid,
ref,
undefined,
undefined,
undefined,
checkoutPath,
undefined,
apiDetails,
"runner",
logger
);
}

View File

@@ -45,7 +45,7 @@ async function run() {
url: actionsUtil.getRequiredEnvParam("GITHUB_SERVER_URL"),
};
const uploadStats = await upload_lib.upload(
const uploadStats = await upload_lib.uploadFromActions(
actionsUtil.getRequiredInput("sarif_file"),
parseRepositoryNwo(actionsUtil.getRequiredEnvParam("GITHUB_REPOSITORY")),
await actionsUtil.getCommitOid(),
@@ -56,7 +56,6 @@ async function run() {
actionsUtil.getRequiredInput("checkout_path"),
actionsUtil.getRequiredInput("matrix"),
apiDetails,
"actions",
getActionsLogger()
);
await sendSuccessStatusReport(startedAt, uploadStats);