summaryrefslogtreecommitdiff
path: root/scripts/stats/index.js
diff options
context:
space:
mode:
authorGravatar Fred K. Schott <fkschott@gmail.com> 2021-08-31 19:50:25 -0700
committerGravatar GitHub <noreply@github.com> 2021-08-31 19:50:25 -0700
commitf14762bd12c6f9c6bc663514d58447c43a27a927 (patch)
treed49e577133c04d722d1221c57dcb60cf483c7cdf /scripts/stats/index.js
parente6766e2cd2099e2481c682a69d9234c413429a9f (diff)
downloadastro-f14762bd12c6f9c6bc663514d58447c43a27a927.tar.gz
astro-f14762bd12c6f9c6bc663514d58447c43a27a927.tar.zst
astro-f14762bd12c6f9c6bc663514d58447c43a27a927.zip
wip (#1284)
Diffstat (limited to 'scripts/stats/index.js')
-rw-r--r--scripts/stats/index.js102
1 files changed, 102 insertions, 0 deletions
diff --git a/scripts/stats/index.js b/scripts/stats/index.js
new file mode 100644
index 000000000..7cea7bf4f
--- /dev/null
+++ b/scripts/stats/index.js
@@ -0,0 +1,102 @@
+// @ts-check
+import { Octokit } from '@octokit/action';
+import { execSync } from 'child_process';
+import { appendFileSync, readFileSync, writeFileSync } from 'fs';
+
+const octokit = new Octokit();
+const owner = 'snowpackjs';
+const repo = 'astro';
+
+// Relevant IDs captured via: https://docs.github.com/en/graphql/overview/explorer
+// query {
+// repository(name:"astro", owner:"snowpackjs") {
+// project(number: 3) {
+// columns(first: 100) {
+// nodes {
+// id
+// databaseId
+// name
+// }
+// }
+// }
+// }
+// }
+
+const COLUMN_ID_BUGS_NEEDS_TRIAGE = 14724521;
+const COLUMN_ID_BUGS_ACCEPTED = 14724515;
+const COLUMN_ID_BUGS_PRIORITIZED = 14946516;
+const COLUMN_ID_RFCS_NEEDS_DISCUSSION = 14946333;
+const COLUMN_ID_RFCS_NEEDS_WORK = 14946353;
+const COLUMN_ID_RFCS_ACCEPTED = 14946335;
+const COLUMN_ID_RFCS_PRIORITIZED = 14946454;
+
+// CREATE LOCAL COPIES OF DATA (Useful for debugging locally)
+// Command:
+// GITHUB_ACTION=test GITHUB_TOKEN=XXXXXXXXX node scripts/stats/index.js
+// Code:
+// writeFileSync('pulls.json', JSON.stringify(await octokit.paginate("GET /repos/{owner}/{repo}/pulls", {
+// owner,
+// repo,
+// })));
+// writeFileSync('issues.json', JSON.stringify(await octokit.paginate("GET /repos/{owner}/{repo}/issues", {
+// owner,
+// repo,
+// })));
+// const issues = JSON.parse(readFileSync('issues.json').toString());
+// const pulls = JSON.parse(readFileSync('pulls.json').toString());
+
+async function countCards(column_id) {
+ return octokit.paginate('GET /projects/columns/{column_id}/cards', {
+ column_id,
+ mediaType: {
+ previews: ['inertia'],
+ },
+ });
+}
+async function countCommits(since) {
+ return octokit.paginate('GET /repos/{owner}/{repo}/commits', {
+ owner,
+ repo,
+ since: since.toISOString(),
+ })
+}
+
+export async function run() {
+ const twentyFourHoursAgo = new Date();
+ twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1);
+
+ const pulls = await octokit.paginate('GET /repos/{owner}/{repo}/pulls', {
+ owner,
+ repo,
+ });
+ const issues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
+ owner,
+ repo,
+ });
+ const entry = [
+ // Date (Human Readable)
+ `"${new Date().toLocaleDateString('en-US', { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' })}"`,
+ // Commits in last 24 hours
+ (await countCommits(twentyFourHoursAgo)).length,
+ // Pull requests
+ pulls.length,
+ // Open Issues
+ issues.length,
+ // Bugs: Needs Triage
+ (await countCards(COLUMN_ID_BUGS_NEEDS_TRIAGE)).length,
+ // Bugs: Accepted
+ (await countCards(COLUMN_ID_BUGS_ACCEPTED)).length + (await countCards(COLUMN_ID_BUGS_PRIORITIZED)).length,
+ // RFC: Needs Discussion
+ (await countCards(COLUMN_ID_RFCS_NEEDS_DISCUSSION)).length,
+ // RFC: Needs Work
+ (await countCards(COLUMN_ID_RFCS_NEEDS_WORK)).length,
+ // RFC: Accepted
+ (await countCards(COLUMN_ID_RFCS_ACCEPTED)).length + (await countCards(COLUMN_ID_RFCS_PRIORITIZED)).length,
+ // Date (ISO)
+ `"${new Date().toISOString()}"`,
+ ];
+
+ appendFileSync('scripts/stats/stats.csv', entry.join(',') + '\n');
+}
+
+run();