MCPcopy Create free account
hub / github.com/adobe/react-spectrum / main

Function main

scripts/sendWeeklyExcelSheet.mjs:83–140  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

81}
82
83async 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, aiPRs, otherPRs, offPRs, counts} = await generateData(
116 startDate,
117 endDate
118 );
119 console.log(
120 `Found: V3=${counts.v3}, S2=${counts.s2}, RAC=${counts.rac}, AI=${counts.ai}, Other=${counts.other}, Off PRs=${counts.offPRs}`
121 );
122
123 let buffer = await createTestingSheet({v3PRs, s2PRs, racPRs, aiPRs, otherPRs, offPRs});
124
125 let startLabel = formatDateLabel(startDate);
126 let endLabel = formatDateLabel(endDate);
127 let total = counts.v3 + counts.s2 + counts.rac + counts.ai + counts.other;
128 let filename = `${endLabel}.xlsx`;
129 let message = `*Testing sheet for ${startLabel} – ${endLabel}*\nV3: ${counts.v3} | S2: ${counts.s2} | RAC: ${counts.rac} | AI: ${counts.ai} | Other: ${counts.other} | Off PR: ${counts.offPRs} | Total: ${total}`;
130
131 if (isLocal) {
132 let outPath = path.resolve(process.cwd(), filename);
133 await writeFile(outPath, buffer);
134 console.log(`Saved testing sheet to ${outPath}`);
135 return;
136 }
137
138 await uploadToSlack(buffer, filename, message);
139 console.log('Posted to Slack successfully.');
140}

Callers 1

Calls 6

generateDataFunction · 0.90
createTestingSheetFunction · 0.90
getPreviousWeekRangeFunction · 0.85
formatDateLabelFunction · 0.85
uploadToSlackFunction · 0.85
parseArgsFunction · 0.70

Tested by

no test coverage detected