index.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. // @ts-check
  2. import { Octokit } from '@octokit/action';
  3. import { readFileSync, writeFileSync } from 'node:fs';
  4. const octokit = new Octokit();
  5. const owner = 'snowpackjs';
  6. const repo = 'astro';
  7. // Relevant IDs captured via: https://docs.github.com/en/graphql/overview/explorer
  8. // query {
  9. // repository(name:"astro", owner:"snowpackjs") {
  10. // project(number: 3) {
  11. // columns(first: 100) {
  12. // nodes {
  13. // id
  14. // databaseId
  15. // name
  16. // }
  17. // }
  18. // }
  19. // }
  20. // }
  21. const COLUMN_ID_BUGS_NEEDS_TRIAGE = 14724521;
  22. const COLUMN_ID_BUGS_ACCEPTED = 14724515;
  23. const COLUMN_ID_BUGS_PRIORITIZED = 14946516;
  24. // const COLUMN_ID_RFCS_IN_PROGRESS = 14946333;
  25. // const COLUMN_ID_RFCS_ACCEPTED = 14946335;
  26. // const COLUMN_ID_RFCS_PRIORITIZED = 14946454;
  27. // CREATE LOCAL COPIES OF DATA (Useful for debugging locally)
  28. // Command:
  29. // GITHUB_ACTION=test GITHUB_TOKEN=XXXXXXXXX node scripts/stats/index.js
  30. // Code:
  31. // writeFileSync('pulls.json', JSON.stringify(await octokit.paginate("GET /repos/{owner}/{repo}/pulls", {
  32. // owner,
  33. // repo,
  34. // })));
  35. // writeFileSync('issues.json', JSON.stringify(await octokit.paginate("GET /repos/{owner}/{repo}/issues", {
  36. // owner,
  37. // repo,
  38. // })));
  39. // const issues = JSON.parse(readFileSync('issues.json').toString());
  40. // const pulls = JSON.parse(readFileSync('pulls.json').toString());
  41. async function countCards(column_id) {
  42. return octokit.paginate('GET /projects/columns/{column_id}/cards', {
  43. column_id,
  44. mediaType: {
  45. previews: ['inertia'],
  46. },
  47. });
  48. }
  49. async function countCommits(since) {
  50. return octokit.paginate('GET /repos/{owner}/{repo}/commits', {
  51. owner,
  52. repo,
  53. since: since.toISOString(),
  54. });
  55. }
  56. export async function run() {
  57. const twentyFourHoursAgo = new Date();
  58. twentyFourHoursAgo.setDate(twentyFourHoursAgo.getDate() - 1);
  59. const allOpenIssues = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
  60. owner,
  61. repo,
  62. });
  63. const openIssues = allOpenIssues.filter((iss) => !iss.pull_request);
  64. const openPulls = allOpenIssues.filter((iss) => iss.pull_request);
  65. const allIssuesLastTwentyFourHours = await octokit.paginate('GET /repos/{owner}/{repo}/issues', {
  66. owner,
  67. repo,
  68. state: 'all',
  69. per_page: 100,
  70. since: twentyFourHoursAgo.toISOString(),
  71. });
  72. const issuesLastTwentyFourHours = allIssuesLastTwentyFourHours.filter(
  73. (iss) => new Date(iss.created_at) > twentyFourHoursAgo && !iss.pull_request
  74. );
  75. const pullsLastTwentyFourHours = allIssuesLastTwentyFourHours.filter(
  76. (iss) => new Date(iss.created_at) > twentyFourHoursAgo && iss.pull_request
  77. );
  78. const entry = [
  79. // Date (Human Readable)
  80. `"${new Date().toLocaleDateString('en-US', {
  81. weekday: 'long',
  82. year: 'numeric',
  83. month: 'long',
  84. day: 'numeric',
  85. })}"`,
  86. // Commits in last 24 hours
  87. (await countCommits(twentyFourHoursAgo)).length,
  88. // New Issues(All) in last 24 hours
  89. issuesLastTwentyFourHours.length,
  90. // New Issues(Bugs) in last 24 hours
  91. issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('🐛 BUG:')).length,
  92. // New Issues(RFC) in last 24 hours
  93. issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('💡 RFC:')).length,
  94. // New Issues(Docs) in last 24 hours
  95. issuesLastTwentyFourHours.filter((iss) => iss.title.startsWith('📘 DOC:')).length,
  96. // New Pull Requests in last 24 hours
  97. pullsLastTwentyFourHours.length,
  98. // Pull requests
  99. openPulls.length,
  100. // Open Issues
  101. openIssues.length,
  102. // Bugs: Needs Triage
  103. (await countCards(COLUMN_ID_BUGS_NEEDS_TRIAGE)).length,
  104. // Bugs: Accepted
  105. (await countCards(COLUMN_ID_BUGS_ACCEPTED)).length +
  106. (await countCards(COLUMN_ID_BUGS_PRIORITIZED)).length,
  107. // RFC: In Progress
  108. 0, // (await countCards(COLUMN_ID_RFCS_IN_PROGRESS)).length,
  109. // RFC: Accepted
  110. 0, // (await countCards(COLUMN_ID_RFCS_ACCEPTED)).length + (await countCards(COLUMN_ID_RFCS_PRIORITIZED)).length,
  111. // Date (ISO)
  112. `"${new Date().toISOString()}"`,
  113. ].join(',');
  114. const statCsv = readFileSync('scripts/stats/stats.csv', { encoding: 'utf-8' });
  115. const [statHeader, ...statItems] = statCsv.split('\n');
  116. const updatedStatCsv = [statHeader, entry, ...statItems].join('\n');
  117. writeFileSync('scripts/stats/stats.csv', updatedStatCsv);
  118. }
  119. run();