mirror of
https://github.com/github/codeql-action.git
synced 2026-01-06 14:40:10 +08:00
Split upload method into two mode-specific ones
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user