Skip to content

Commit e6d4db7

Browse files
authored
chore: get commits for testing (#9050)
* chore: automate building our testing sheet * write csv * update comments * filter PRs using label * get all commits, verify date arguments
1 parent 25b305b commit e6d4db7

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed

scripts/getCommitsForTesting.js

Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
const Octokit = require('@octokit/rest');
2+
const fs = require('fs');
3+
let {parseArgs} = require('util');
4+
5+
const octokit = new Octokit();
6+
7+
let options = {
8+
startDate: {
9+
type: 'string'
10+
},
11+
endDate: {
12+
type: 'string'
13+
}
14+
};
15+
16+
writeTestingCSV();
17+
18+
async function writeTestingCSV() {
19+
let data = await listCommits();
20+
21+
let s2PRs = [];
22+
let racPRs = [];
23+
let v3PRs = [];
24+
let otherPRs = [];
25+
26+
for (let d of data) {
27+
let row = [];
28+
29+
// Get the PR Title from the commit
30+
let regex = /\(#(\d+)\)/g;
31+
let messages = d.commit.message.split('\n');
32+
let title = messages[0];
33+
row.push(title);
34+
35+
// Get info about the PR using PR number
36+
if (regex.test(title)) {
37+
let num = title.match(regex)[0].replace(/[\(\)#]/g, '');
38+
let info = await getPR(num);
39+
40+
// Get testing instructions if it exists
41+
let content = info.data.body;
42+
const match = content.match(/## 📝 Test Instructions:\s*([\s\S]*?)(?=##|$)/);
43+
let testInstructions = '';
44+
if (match) {
45+
testInstructions = match[1];
46+
testInstructions = testInstructions.replace(/<!--[\s\S]*?-->/g, '');
47+
testInstructions = testInstructions.trim();
48+
testInstructions = escapeCSV(testInstructions);
49+
}
50+
51+
if (testInstructions.length > 350) {
52+
row.push('See PR for testing instructions');
53+
} else {
54+
row.push(testInstructions);
55+
}
56+
row.push(info.data.html_url);
57+
58+
if ((/\bs2\b/gi).test(title)) {
59+
s2PRs.push(row);
60+
} else if ((/\brac\b/gi).test(title)) {
61+
racPRs.push(row);
62+
} else if ((/\bv3\b/gi).test(title)) {
63+
v3PRs.push(row);
64+
} else {
65+
otherPRs.push(row);
66+
}
67+
}
68+
}
69+
70+
let csvRows = '';
71+
csvRows += 'V3 \n';
72+
for (let v3 of v3PRs) {
73+
csvRows += v3.join() + '\n';
74+
}
75+
76+
csvRows += '\nRainbow \n'
77+
for (let s2 of s2PRs) {
78+
csvRows += s2.join() + '\n';
79+
}
80+
81+
csvRows += '\nRAC \n'
82+
for (let rac of racPRs) {
83+
csvRows += rac.join() + '\n';
84+
}
85+
86+
csvRows += '\nOther \n'
87+
for (let other of otherPRs) {
88+
csvRows += other.join() + '\n';
89+
}
90+
91+
fs.writeFileSync('output.csv', csvRows, 'utf-8');
92+
}
93+
94+
async function listCommits() {
95+
let args = parseArgs({options, allowPositionals: true});
96+
if (args.positionals.length < 2) {
97+
console.error('Expected at least two arguments');
98+
process.exit(1);
99+
}
100+
101+
let start = new Date(args.positionals[0]);
102+
let end = new Date(args.positionals[1]);
103+
104+
if (isNaN(start.getTime()) || isNaN(end.getTime())) {
105+
console.error('Please verify that your date is correctly formatted')
106+
process.exit(1)
107+
}
108+
109+
let startDate = new Date(start).toISOString();
110+
let endDate = new Date(end).toISOString();
111+
112+
let res = await octokit.request(`GET /repos/adobe/react-spectrum/commits?sha=main&since=${startDate}&until=${endDate}`, {
113+
owner: 'adobe',
114+
repo: 'react-spectrum',
115+
headers: {
116+
'X-GitHub-Api-Version': '2022-11-28'
117+
}
118+
});
119+
120+
return res.data;
121+
}
122+
123+
async function getPR(num) {
124+
let res = await octokit.request(`GET /repos/adobe/react-spectrum/pulls/${num}`, {
125+
owner: 'adobe',
126+
repo: 'react-spectrum',
127+
pull_number: `${num}`,
128+
headers: {
129+
'X-GitHub-Api-Version': '2022-11-28'
130+
}
131+
});
132+
return res;
133+
}
134+
135+
function escapeCSV(value) {
136+
if (!value) {
137+
return '';
138+
}
139+
140+
// Normalize newlines for CSV compatibility
141+
let stringValue = String(value).replace(/\r\n/g, '\n').replace(/\r/g, '\n');
142+
143+
// Escape any internal double quotes
144+
let escaped = stringValue.replace(/"/g, '""');
145+
146+
// Wrap in quotes so commas/newlines don't break the cell
147+
return `"${escaped}"`;
148+
}
149+
150+
// We can bring this back if we start using the "needs testing" label
151+
// function isReadyForTesting(labels){
152+
// if (labels.length === 0) {
153+
// return false;
154+
// }
155+
// for (let label of labels) {
156+
// if (label.name === 'needs testing') {
157+
// return true;
158+
// }
159+
// }
160+
161+
// return false;
162+
// }

0 commit comments

Comments
 (0)