Skip to content
Source
Sign inSign up
TanStack/ai
Open History to see the last commit

scorecard.ts

71 lines2.1 KB

1/**
2 * Daily scorecard — computes the maintainer to-do digest and posts it to a
3 * Discord webhook (DISCORD_WEBHOOK_URL). With --dry-run (or when the webhook
4 * is not configured) it prints the payload instead of posting.
5 *
6 * Usage: node scripts/maintainer/scorecard.ts [--dry-run]
7 */
8​
9import { readdir } from 'node:fs/promises'
10import process from 'node:process'
11import { classifyAll } from './classify'
12import { collectSnapshot } from './collect'
13import { loadConfig } from './config'
14import { buildScorecardEmbeds, postToDiscord } from './discord'
15import { createGitHubClient } from './github'
16import { computeScorecard } from './metrics'
17import { isDryRun, resolveToken, writeStepSummary } from './env'
18​
19async function countPendingChangesets(): Promise<number> {
20 try {
21 const entries = await readdir('.changeset')
22 return entries.filter(
23 (f) => f.endsWith('.md') && f.toLowerCase() !== 'readme.md',
24 ).length
25 } catch {
26 return 0
27 }
29​
30async function main(): Promise<void> {
31 const dryRun = isDryRun()
32 const config = await loadConfig()
33 const client = createGitHubClient({ token: await resolveToken() })
34​
35 console.log(`Collecting snapshot of ${config.repo}…`)
36 const now = new Date()
37 const snapshot = await collectSnapshot(client, config, now)
38 const triage = classifyAll(snapshot, config, now)
39 const scorecard = computeScorecard(
40 snapshot,
41 triage,
42 config,
43 now,
44 await countPendingChangesets(),
45 )
46 const embeds = buildScorecardEmbeds(scorecard, config.repo)
47​
48 const summary = embeds
49 .map((e) => `### ${e.title}\n\n${e.description}`)
50 .join('\n\n')
51 await writeStepSummary(`## Daily scorecard\n\n${summary}`)
52​
53 const webhookUrl = process.env.DISCORD_WEBHOOK_URL
54 if (dryRun || !webhookUrl) {
55 if (!webhookUrl && !dryRun) {
56 console.warn(
57 'DISCORD_WEBHOOK_URL is not set — printing the digest instead of posting.',
58 )
59 }
60 console.log(JSON.stringify(embeds, null, 2))
61 return
62 }
63​
64 await postToDiscord(webhookUrl, embeds)
65 console.log(`Posted ${embeds.length} embed(s) to Discord.`)
67​
68main().catch((error) => {
69 console.error(error)
70 process.exitCode = 1
71})