-
Notifications
You must be signed in to change notification settings - Fork 1.3k
chore: get commits for testing #9050
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| const Octokit = require('@octokit/rest'); | ||
| const fs = require('fs'); | ||
| let {parseArgs} = require('util'); | ||
|
|
||
| const octokit = new Octokit(); | ||
|
|
||
| let options = { | ||
| startDate: { | ||
| type: 'string' | ||
| }, | ||
| endDate: { | ||
| type: 'string' | ||
| } | ||
| }; | ||
|
|
||
| writeTestingCSV(); | ||
|
|
||
| async function writeTestingCSV() { | ||
| let data = await listCommits(); | ||
|
|
||
| let s2PRs = []; | ||
| let racPRs = []; | ||
| let v3PRs = []; | ||
| let otherPRs = []; | ||
|
|
||
| for (let d of data) { | ||
| let row = []; | ||
|
|
||
| // Get the PR Title from the commit | ||
| let regex = /\(#(\d+)\)/g; | ||
| let messages = d.commit.message.split('\n'); | ||
| let title = messages[0]; | ||
| row.push(title); | ||
|
|
||
| // Get info about the PR using PR number | ||
| if (regex.test(title)) { | ||
| let num = title.match(regex)[0].replace(/[\(\)#]/g, ''); | ||
| let info = await getPR(num); | ||
|
|
||
| // 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); | ||
| } | ||
|
|
||
| if (testInstructions.length > 350) { | ||
| row.push('See PR for testing instructions'); | ||
| } else { | ||
| row.push(testInstructions); | ||
| } | ||
| 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 { | ||
| otherPRs.push(row); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| let csvRows = ''; | ||
| csvRows += 'V3 \n'; | ||
| for (let v3 of v3PRs) { | ||
| csvRows += v3.join() + '\n'; | ||
| } | ||
|
|
||
| csvRows += '\nRainbow \n' | ||
| for (let s2 of s2PRs) { | ||
| csvRows += s2.join() + '\n'; | ||
| } | ||
|
|
||
| csvRows += '\nRAC \n' | ||
| for (let rac of racPRs) { | ||
| csvRows += rac.join() + '\n'; | ||
| } | ||
|
|
||
| csvRows += '\nOther \n' | ||
| for (let other of otherPRs) { | ||
| csvRows += other.join() + '\n'; | ||
| } | ||
|
|
||
| fs.writeFileSync('output.csv', csvRows, 'utf-8'); | ||
| } | ||
|
|
||
| async function listCommits() { | ||
| let args = parseArgs({options, allowPositionals: true}); | ||
| if (args.positionals.length < 2) { | ||
| console.error('Expected at least two arguments'); | ||
| process.exit(1); | ||
| } | ||
|
|
||
| let start = new Date(args.positionals[0]); | ||
| 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) | ||
| } | ||
|
|
||
| let startDate = new Date(start).toISOString(); | ||
| let endDate = new Date(end).toISOString(); | ||
|
|
||
| let res = await octokit.request(`GET /repos/adobe/react-spectrum/commits?sha=main&since=${startDate}&until=${endDate}`, { | ||
| owner: 'adobe', | ||
| repo: 'react-spectrum', | ||
| headers: { | ||
| 'X-GitHub-Api-Version': '2022-11-28' | ||
| } | ||
| }); | ||
|
|
||
| return res.data; | ||
| } | ||
|
|
||
| async function getPR(num) { | ||
| let res = await octokit.request(`GET /repos/adobe/react-spectrum/pulls/${num}`, { | ||
| owner: 'adobe', | ||
| repo: 'react-spectrum', | ||
| pull_number: `${num}`, | ||
| headers: { | ||
| 'X-GitHub-Api-Version': '2022-11-28' | ||
| } | ||
| }); | ||
| return res; | ||
| } | ||
|
|
||
| function escapeCSV(value) { | ||
| if (!value) { | ||
| return ''; | ||
| } | ||
|
|
||
| // Normalize newlines for CSV compatibility | ||
| let stringValue = String(value).replace(/\r\n/g, '\n').replace(/\r/g, '\n'); | ||
|
|
||
| // Escape any internal double quotes | ||
| let escaped = stringValue.replace(/"/g, '""'); | ||
|
|
||
| // 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; | ||
| // } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
would be nice if we had a bot account with limited perms so we could avoid having to have everyone auth via cmd line. Ideally stored in secrets somewhere but maybe more trouble than it is worth unless we make an automated job to do this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could do it in a Github Action with a button trigger to run it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thats a good idea