Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@
"lerna": "^3.13.2",
"lucide-react": "^0.517.0",
"md5": "^2.2.1",
"mdast-util-to-string": "^4.0.0",
"motion": "^12.23.6",
"npm-cli-login": "^1.0.0",
"parcel": "^2.16.3",
Expand Down
125 changes: 85 additions & 40 deletions scripts/getCommitsForTesting.js → scripts/getCommitsForTesting.mjs
Original file line number Diff line number Diff line change
@@ -1,8 +1,20 @@
const Octokit = require('@octokit/rest');
const fs = require('fs');
let {parseArgs} = require('util');

const octokit = new Octokit();
import Octokit from "@octokit/rest";
import fs from 'fs';
import {parseArgs} from 'node:util';
import remarkParse from 'remark-parse';
import {toString} from 'mdast-util-to-string';
import {unified} from 'unified';

/**
* Instructions:
*
* 1. Run the following script: node scripts/getCommitsForTesting.mjs 2025-10-07 2025-10-18
* 2. Go to output.csv, copy it to Google sheets, highlight the rows, go to "Data" in the toolbar -> split text to columns -> separator: comma
*/

const octokit = new Octokit({
auth: `token ${process.env.GITHUB_TOKEN}`
});

let options = {
startDate: {
Expand Down Expand Up @@ -39,51 +51,54 @@ async function writeTestingCSV() {

// Get testing instructions if it exists
let content = info.data.body;
const match = content.match(/## 📝 Test Instructions:\s*([\s\S]*?)(?=##|$)/);
let testInstructions = '';
if (match) {
testInstructions = match[1];
testInstructions = testInstructions.replace(/<!--[\s\S]*?-->/g, '');
testInstructions = testInstructions.trim();
testInstructions = escapeCSV(testInstructions);
}
let testInstructions = escapeCSV(extractTestInstructions(content));

if (testInstructions.length > 350) {
if (testInstructions.length > 300) {
row.push('See PR for testing instructions');
} else {
row.push(testInstructions);
}

// Add PR url to the row
row.push(info.data.html_url);

if ((/\bs2\b/gi).test(title)) {
s2PRs.push(row);
} else if ((/\brac\b/gi).test(title)) {
racPRs.push(row);
} else if ((/\bv3\b/gi).test(title)) {
v3PRs.push(row);
} else {
// Categorize commit into V3, RAC, S2, or other (utilizes labels on PR's to categorize)
let labels = info.data.labels;
if (labels.length === 0) {
otherPRs.push(row);
} else {
for (let label of labels) {
// eslint-disable-next-line max-depth
if (label.name === 'S2') {
s2PRs.push(row);
} else if (label.name === 'RAC') {
racPRs.push(row);
} else if (label.name === 'V3') {
v3PRs.push(row);
}
}
}
}
}

// Prepare to write into CSV
let csvRows = '';
csvRows += 'V3 \n';
for (let v3 of v3PRs) {
csvRows += v3.join() + '\n';
}

csvRows += '\nRainbow \n'
csvRows += '\nRainbow \n';
for (let s2 of s2PRs) {
csvRows += s2.join() + '\n';
}

csvRows += '\nRAC \n'
csvRows += '\nRAC \n';
for (let rac of racPRs) {
csvRows += rac.join() + '\n';
}

csvRows += '\nOther \n'
csvRows += '\nOther \n';
for (let other of otherPRs) {
csvRows += other.join() + '\n';
}
Expand All @@ -102,8 +117,8 @@ async function listCommits() {
let end = new Date(args.positionals[1]);

if (isNaN(start.getTime()) || isNaN(end.getTime())) {
console.error('Please verify that your date is correctly formatted')
process.exit(1)
console.error('Please verify that your date is correctly formatted');
process.exit(1);
}

let startDate = new Date(start).toISOString();
Expand Down Expand Up @@ -132,6 +147,50 @@ async function getPR(num) {
return res;
}

function getHeadingText(node) {
return node.children
.map(child => child.value || '')
.join('')
.trim();
}

function extractTestInstructions(contents) {
if (!contents) {
return '';
}

let tree = unified().use(remarkParse).parse(contents);

let collecting = false;
let headingDepth = null;
let collected = [];

for (let node of tree.children) {
if (node.type === 'heading') {
let text = getHeadingText(node).toLowerCase();

if (text.includes('test instructions')) {
collecting = true;
headingDepth = node.depth;
continue;
}

// Stop when we reach another heading of same or higher level
if (collecting && node.depth <= headingDepth) {
break;
}
}

if (collecting) {
collected.push(node);
}

}

return collected.map(node => toString(node)).join(' ').replace(/\r\n/g, '\n').replace(/\s+/g, ' ').trim();
}


function escapeCSV(value) {
if (!value) {
return '';
Expand All @@ -146,17 +205,3 @@ function escapeCSV(value) {
// Wrap in quotes so commas/newlines don't break the cell
return `"${escaped}"`;
}

// We can bring this back if we start using the "needs testing" label
// function isReadyForTesting(labels){
// if (labels.length === 0) {
// return false;
// }
// for (let label of labels) {
// if (label.name === 'needs testing') {
// return true;
// }
// }

// return false;
// }
1 change: 1 addition & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -24878,6 +24878,7 @@ __metadata:
lerna: "npm:^3.13.2"
lucide-react: "npm:^0.517.0"
md5: "npm:^2.2.1"
mdast-util-to-string: "npm:^4.0.0"
motion: "npm:^12.23.6"
npm-cli-login: "npm:^1.0.0"
parcel: "npm:^2.16.3"
Expand Down