2021-08-31 21:50:25 -05:00
|
|
|
// @ts-check
|
|
|
|
import { Octokit } from '@octokit/action';
|
|
|
|
import { execSync } from 'child_process';
|
2021-11-11 18:59:52 -05:00
|
|
|
import { readFileSync, writeFileSync } from 'fs';
|
2021-08-31 21:50:25 -05:00
|
|
|
|
|
|
|
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;
|
2021-12-14 11:52:04 -05:00
|
|
|
// const COLUMN_ID_RFCS_IN_PROGRESS = 14946333;
|
|
|
|
// const COLUMN_ID_RFCS_ACCEPTED = 14946335;
|
|
|
|
// const COLUMN_ID_RFCS_PRIORITIZED = 14946454;
|
2021-08-31 21:50:25 -05:00
|
|
|
|
|
|
|
// 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(),
|
2021-08-31 21:51:36 -05:00
|
|
|
});
|
2021-08-31 21:50:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
export async function run() {
|
|
|
|
const twentyFourHoursAgo = new Date();
|
|
|
|
twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1);
|
|
|
|
|
2021-09-01 19:12:41 -05:00
|
|
|
const allOpenIssues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
|
2021-08-31 21:50:25 -05:00
|
|
|
owner,
|
|
|
|
repo,
|
|
|
|
});
|
2021-09-01 19:12:41 -05:00
|
|
|
const openIssues = allOpenIssues.filter((iss) => !iss.pull_request);
|
|
|
|
const openPulls = allOpenIssues.filter((iss) => iss.pull_request);
|
2021-09-01 19:04:39 -05:00
|
|
|
|
|
|
|
const allIssuesLastTwentyFourHours = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
|
2021-08-31 21:50:25 -05:00
|
|
|
owner,
|
|
|
|
repo,
|
2021-09-01 19:04:39 -05:00
|
|
|
state: 'all',
|
|
|
|
per_page: 100,
|
|
|
|
since: twentyFourHoursAgo.toISOString(),
|
2021-08-31 21:50:25 -05:00
|
|
|
});
|
2021-09-01 19:04:39 -05:00
|
|
|
const issuesLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && !iss.pull_request);
|
|
|
|
const pullsLastTwentyFourHours = allIssuesLastTwentyFourHours.filter((iss) => new Date(iss.created_at) > twentyFourHoursAgo && iss.pull_request);
|
|
|
|
|
2021-08-31 21:50:25 -05:00
|
|
|
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,
|
2021-09-01 19:04:39 -05:00
|
|
|
// New Issues(All) in last 24 hours
|
|
|
|
issuesLastTwentyFourHours.length,
|
|
|
|
// New Issues(Bugs) in last 24 hours
|
|
|
|
issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('🐛 BUG:')).length,
|
|
|
|
// New Issues(RFC) in last 24 hours
|
|
|
|
issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('💡 RFC:')).length,
|
|
|
|
// New Issues(Docs) in last 24 hours
|
|
|
|
issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('📘 DOC:')).length,
|
|
|
|
// New Pull Requests in last 24 hours
|
|
|
|
pullsLastTwentyFourHours.length,
|
2021-08-31 21:50:25 -05:00
|
|
|
// Pull requests
|
2021-09-01 19:12:41 -05:00
|
|
|
openPulls.length,
|
2021-08-31 21:50:25 -05:00
|
|
|
// Open Issues
|
2021-09-01 19:12:41 -05:00
|
|
|
openIssues.length,
|
2021-08-31 21:50:25 -05:00
|
|
|
// 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,
|
2021-09-02 11:40:03 -05:00
|
|
|
// RFC: In Progress
|
2021-12-14 11:52:04 -05:00
|
|
|
0, // (await countCards(COLUMN_ID_RFCS_IN_PROGRESS)).length,
|
2021-08-31 21:50:25 -05:00
|
|
|
// RFC: Accepted
|
2021-12-14 11:52:04 -05:00
|
|
|
0, // (await countCards(COLUMN_ID_RFCS_ACCEPTED)).length + (await countCards(COLUMN_ID_RFCS_PRIORITIZED)).length,
|
2021-08-31 21:50:25 -05:00
|
|
|
// Date (ISO)
|
|
|
|
`"${new Date().toISOString()}"`,
|
2021-11-11 18:59:52 -05:00
|
|
|
].join(',');
|
2021-08-31 21:50:25 -05:00
|
|
|
|
2021-11-11 19:01:05 -05:00
|
|
|
const statCsv = readFileSync('scripts/stats/stats.csv', { encoding: 'utf-8' });
|
2021-11-11 18:59:52 -05:00
|
|
|
const [statHeader, ...statItems] = statCsv.split('\n');
|
|
|
|
const updatedStatCsv = [statHeader, entry, ...statItems].join('\n');
|
|
|
|
writeFileSync('scripts/stats/stats.csv', updatedStatCsv);
|
2021-08-31 21:50:25 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
run();
|