()
| 81 | } |
| 82 | |
| 83 | async function main() { |
| 84 | let args = parseArgs({ |
| 85 | allowPositionals: true, |
| 86 | options: { |
| 87 | local: {type: 'boolean', short: 'l', default: false} |
| 88 | } |
| 89 | }); |
| 90 | let isLocal = args.values.local; |
| 91 | |
| 92 | if (!isLocal && (!SLACK_TESTING_BOT_TOKEN || !SLACK_CHANNEL_ID)) { |
| 93 | console.error('Missing required env vars: SLACK_TESTING_BOT_TOKEN, SLACK_CHANNEL_ID'); |
| 94 | process.exit(1); |
| 95 | } |
| 96 | |
| 97 | let {startDate, endDate} = (() => { |
| 98 | if (args.positionals.length === 0) { |
| 99 | return getPreviousWeekRange(); |
| 100 | } |
| 101 | if (args.positionals.length < 2) { |
| 102 | console.error('Expected two date arguments: <startDate> <endDate>'); |
| 103 | process.exit(1); |
| 104 | } |
| 105 | let start = new Date(args.positionals[0]); |
| 106 | let end = new Date(args.positionals[1]); |
| 107 | if (isNaN(start.getTime()) || isNaN(end.getTime())) { |
| 108 | console.error('Please verify that your dates are correctly formatted (YYYY-MM-DD)'); |
| 109 | process.exit(1); |
| 110 | } |
| 111 | return {startDate: args.positionals[0], endDate: args.positionals[1]}; |
| 112 | })(); |
| 113 | console.log(`Generating testing sheet for ${startDate} – ${endDate}...`); |
| 114 | |
| 115 | let {v3PRs, s2PRs, racPRs, otherPRs, offPRs, counts} = await generateData(startDate, endDate); |
| 116 | console.log( |
| 117 | `Found: V3=${counts.v3}, S2=${counts.s2}, RAC=${counts.rac}, Other=${counts.other}, Off PRs=${counts.offPRs}` |
| 118 | ); |
| 119 | |
| 120 | let buffer = await createTestingSheet({v3PRs, s2PRs, racPRs, otherPRs, offPRs}); |
| 121 | |
| 122 | let startLabel = formatDateLabel(startDate); |
| 123 | let endLabel = formatDateLabel(endDate); |
| 124 | let total = counts.v3 + counts.s2 + counts.rac + counts.other; |
| 125 | let filename = `${endLabel}.xlsx`; |
| 126 | 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}`; |
| 127 | |
| 128 | if (isLocal) { |
| 129 | let outPath = path.resolve(process.cwd(), filename); |
| 130 | await writeFile(outPath, buffer); |
| 131 | console.log(`Saved testing sheet to ${outPath}`); |
| 132 | return; |
| 133 | } |
| 134 | |
| 135 | await uploadToSlack(buffer, filename, message); |
| 136 | console.log('Posted to Slack successfully.'); |
| 137 | } |
| 138 | |
| 139 | main().catch(err => { |
| 140 | console.error(err); |
no test coverage detected