add sendNotifications functionality to index

This commit is contained in:
Tim Krins 2024-09-20 15:58:40 +01:00
parent 4fc97fc913
commit 5a6c6a10d1
No known key found for this signature in database
2 changed files with 38 additions and 0 deletions

View file

@ -64,6 +64,12 @@ const getToken = async (): Promise<string> => {
return token;
};
const getSendNotifications = (): boolean => {
return isTrue(
core.getInput('send-notifications'),
);
};
const getOverrideBranch = (token: string): string => {
let overrideBranch = core.getInput('override_branch');
if (!overrideBranch && !token && isPullRequestFromFork()) {
@ -476,4 +482,5 @@ export {
buildUploadExec,
buildSendNotificationsExec,
getToken,
getSendNotifications,
};

View file

@ -8,7 +8,9 @@ import {
buildCommitExec,
buildGeneralExec,
buildReportExec,
buildSendNotificationsExec,
buildUploadExec,
getSendNotifications,
} from './buildExec';
import {
getBaseUrl,
@ -28,6 +30,11 @@ const run = async (): Promise<void> => {
try {
const {commitExecArgs, commitOptions, commitCommand} = await buildCommitExec();
const {reportExecArgs, reportOptions, reportCommand} = await buildReportExec();
const {
sendNotificationsExecArgs,
sendNotificationsOptions,
sendNotificationsCommand,
} = await buildSendNotificationsExec();
const {
uploadExecArgs,
uploadOptions,
@ -101,6 +108,30 @@ const run = async (): Promise<void> => {
);
});
};
const sendNotifications = async (): Promise<void> => {
await exec.exec(
getCommand(filename, args, sendNotificationsCommand).join(' '),
sendNotificationsExecArgs,
sendNotificationsOptions)
.then(async (exitCode) => {
if (exitCode == 0) {
// notifications sent
}
}).catch((err) => {
setFailure(
`Codecov:
Failed to send notifications: ${err.message}`,
failCi,
);
});
};
if (getSendNotifications()) {
await sendNotifications();
// don't perform an upload after sending notifications
return
}
await exec.exec(
getCommand(
filename,