From 735bb0a51923b7acc3cdb15c068f197402cdf788 Mon Sep 17 00:00:00 2001 From: Tim Krins Date: Fri, 20 Sep 2024 15:45:21 +0100 Subject: [PATCH] add buildSendNotificationsExec function --- src/buildExec.ts | 54 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/src/buildExec.ts b/src/buildExec.ts index 9e80dd1..129103a 100644 --- a/src/buildExec.ts +++ b/src/buildExec.ts @@ -220,6 +220,60 @@ const buildReportExec = async (): Promise<{ return {reportExecArgs, reportOptions, reportCommand}; }; +const buildSendNotificationsExec = async (): Promise<{}> => { + const gitService = getGitService(); + const overrideCommit = core.getInput('override_commit'); + const overridePr = core.getInput('override_pr'); + const slug = core.getInput('slug'); + const token = await getToken(); + const failCi = isTrue(core.getInput('fail_ci_if_error')); + const workingDir = core.getInput('working-directory'); + + const sendNotificationsCommand = 'send-notifications'; + const sendNotificationsExecArgs: string[] = []; + + const sendNotificationsOptions: any = {}; + sendNotificationsOptions.env = Object.assign(process.env, { + GITHUB_ACTION: process.env.GITHUB_ACTION, + GITHUB_RUN_ID: process.env.GITHUB_RUN_ID, + GITHUB_REF: process.env.GITHUB_REF, + GITHUB_REPOSITORY: process.env.GITHUB_REPOSITORY, + GITHUB_SHA: process.env.GITHUB_SHA, + GITHUB_HEAD_REF: process.env.GITHUB_HEAD_REF || '', + }); + + if (token) { + sendNotificationsOptions.env.CODECOV_TOKEN = token; + } + sendNotificationsExecArgs.push('--git-service', gitService); + + if (overrideCommit) { + sendNotificationsExecArgs.push('-C', overrideCommit); + } else if ( + ['pull_request', 'pull_request_target'].includes(context.eventName) + ) { + const payload = context.payload as PullRequestEvent; + sendNotificationsExecArgs.push('-C', payload.pull_request.head.sha); + } + if (overridePr) { + sendNotificationsExecArgs.push('-P', overridePr); + } else if (context.eventName == 'pull_request_target') { + const payload = context.payload as PullRequestEvent; + sendNotificationsExecArgs.push('-P', payload.number.toString()); + } + if (slug) { + sendNotificationsExecArgs.push('--slug', slug); + } + if (failCi) { + sendNotificationsExecArgs.push('-Z'); + } + if (workingDir) { + sendNotificationsOptions.cwd = workingDir; + } + + return {sendNotificationsExecArgs, sendNotificationsOptions, sendNotificationsCommand}; +}; + const buildUploadExec = async (): Promise<{ uploadExecArgs: any[]; uploadOptions: any;