Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 22 additions & 6 deletions scripts/sendWeeklyExcelSheet.mjs
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import {createTestingSheet} from './createExcelSheet.mjs';
import {generateData} from './getCommitsForTesting.mjs';
import {parseArgs} from 'node:util';
import {writeFile} from 'node:fs/promises';
import path from 'node:path';

const SLACK_TESTING_BOT_TOKEN = process.env.SLACK_TESTING_BOT_TOKEN;
const SLACK_CHANNEL_ID = process.env.SLACK_CHANNEL_ID;

if (!SLACK_TESTING_BOT_TOKEN || !SLACK_CHANNEL_ID) {
console.error('Missing required env vars: SLACK_BOT_TOKEN, SLACK_CHANNEL_ID');
process.exit(1);
}

function getPreviousWeekRange() {
let today = new Date();
let endDate = new Date(today);
Expand Down Expand Up @@ -84,7 +81,19 @@ async function uploadToSlack(buffer, filename, message) {
}

async function main() {
let args = parseArgs({allowPositionals: true});
let args = parseArgs({
allowPositionals: true,
options: {
local: {type: 'boolean', short: 'l', default: false}
}
});
let isLocal = args.values.local;

if (!isLocal && (!SLACK_TESTING_BOT_TOKEN || !SLACK_CHANNEL_ID)) {
console.error('Missing required env vars: SLACK_TESTING_BOT_TOKEN, SLACK_CHANNEL_ID');
process.exit(1);
}

let {startDate, endDate} = (() => {
if (args.positionals.length === 0) {
return getPreviousWeekRange();
Expand Down Expand Up @@ -116,6 +125,13 @@ async function main() {
let filename = `${endLabel}.xlsx`;
let message = `*Testing sheet for ${startLabel} – ${endLabel}*\nV3: ${counts.v3} | S2: ${counts.s2} | RAC: ${counts.rac} | Other: ${counts.other} | Off PR: ${counts.offPRs} | Total: ${total}`;

if (isLocal) {
let outPath = path.resolve(process.cwd(), filename);
await writeFile(outPath, buffer);
console.log(`Saved testing sheet to ${outPath}`);
return;
}

await uploadToSlack(buffer, filename, message);
console.log('Posted to Slack successfully.');
}
Expand Down