From c56581a2bb8a4c22ae6781b011445c8e186e9af3 Mon Sep 17 00:00:00 2001 From: Rob Snow Date: Thu, 9 Jul 2026 12:09:37 +1000 Subject: [PATCH] chore: add testing sheet local run --- scripts/sendWeeklyExcelSheet.mjs | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/scripts/sendWeeklyExcelSheet.mjs b/scripts/sendWeeklyExcelSheet.mjs index 9aabee657ed..ee8b1098769 100644 --- a/scripts/sendWeeklyExcelSheet.mjs +++ b/scripts/sendWeeklyExcelSheet.mjs @@ -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); @@ -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(); @@ -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.'); }