Skip to content

Commit

Permalink
Undo all .github/ changes
Browse files Browse the repository at this point in the history
  • Loading branch information
AndrewGable committed May 8, 2023
1 parent 63bc287 commit 8755a82
Show file tree
Hide file tree
Showing 38 changed files with 22,036 additions and 21,897 deletions.
62 changes: 32 additions & 30 deletions .github/actions/javascript/authorChecklist/authorChecklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,21 @@ const issue = github.context.payload.issue ? github.context.payload.issue.number
*/
function getNumberOfItemsFromAuthorChecklist() {
return new Promise((resolve, reject) => {
https
.get(pathToAuthorChecklist, (res) => {
let fileContents = '';
res.on('data', (chunk) => {
fileContents += chunk;
});
res.on('end', () => {
// Currently, both the author and reviewer checklists are in the PR template file, so we need to do a little bit of parsing the PR description to get just the author
// checklist.
const contentAfterStartOfAuthorChecklist = fileContents.split(authorChecklistStartsWith).pop();
const contentBeforeStartOfReviewerChecklist = contentAfterStartOfAuthorChecklist.split(reviewerChecklistStartsWith).shift();
https.get(pathToAuthorChecklist, (res) => {
let fileContents = '';
res.on('data', (chunk) => {
fileContents += chunk;
});
res.on('end', () => {
// Currently, both the author and reviewer checklists are in the PR template file, so we need to do a little bit of parsing the PR description to get just the author
// checklist.
const contentAfterStartOfAuthorChecklist = fileContents.split(authorChecklistStartsWith).pop();
const contentBeforeStartOfReviewerChecklist = contentAfterStartOfAuthorChecklist.split(reviewerChecklistStartsWith).shift();

const numberOfChecklistItems = (contentBeforeStartOfReviewerChecklist.match(/\[ \]/g) || []).length;
resolve(numberOfChecklistItems);
});
})
const numberOfChecklistItems = (contentBeforeStartOfReviewerChecklist.match(/\[ \]/g) || []).length;
resolve(numberOfChecklistItems);
});
})
.on('error', reject);
});
}
Expand All @@ -37,26 +36,29 @@ function getNumberOfItemsFromAuthorChecklist() {
* @param {Number} numberOfChecklistItems
*/
function checkIssueForCompletedChecklist(numberOfChecklistItems) {
GitHubUtils.getPullRequestBody(issue).then((pullRequestBody) => {
const contentAfterStartOfAuthorChecklist = pullRequestBody.split(authorChecklistStartsWith).pop();
const contentOfAuthorChecklist = contentAfterStartOfAuthorChecklist.split(reviewerChecklistStartsWith).shift();
GitHubUtils.getPullRequestBody(issue)
.then((pullRequestBody) => {
const contentAfterStartOfAuthorChecklist = pullRequestBody.split(authorChecklistStartsWith).pop();
const contentOfAuthorChecklist = contentAfterStartOfAuthorChecklist.split(reviewerChecklistStartsWith).shift();

const numberOfFinishedChecklistItems = (contentOfAuthorChecklist.match(/- \[x\]/gi) || []).length;
const numberOfUnfinishedChecklistItems = (contentOfAuthorChecklist.match(/- \[ \]/g) || []).length;
const numberOfFinishedChecklistItems = (contentOfAuthorChecklist.match(/- \[x\]/gi) || []).length;
const numberOfUnfinishedChecklistItems = (contentOfAuthorChecklist.match(/- \[ \]/g) || []).length;

const maxCompletedItems = numberOfChecklistItems + 2;
const minCompletedItems = numberOfChecklistItems - 2;
const maxCompletedItems = numberOfChecklistItems + 2;
const minCompletedItems = numberOfChecklistItems - 2;

console.log(`You completed ${numberOfFinishedChecklistItems} out of ${numberOfChecklistItems} checklist items with ${numberOfUnfinishedChecklistItems} unfinished items`);
console.log(`You completed ${numberOfFinishedChecklistItems} out of ${numberOfChecklistItems} checklist items with ${numberOfUnfinishedChecklistItems} unfinished items`);

if (numberOfFinishedChecklistItems >= minCompletedItems && numberOfFinishedChecklistItems <= maxCompletedItems && numberOfUnfinishedChecklistItems === 0) {
console.log('PR Author checklist is complete 🎉');
return;
}
if (numberOfFinishedChecklistItems >= minCompletedItems
&& numberOfFinishedChecklistItems <= maxCompletedItems
&& numberOfUnfinishedChecklistItems === 0) {
console.log('PR Author checklist is complete 🎉');
return;
}

console.log(`Make sure you are using the most up to date checklist found here: ${pathToAuthorChecklist}`);
core.setFailed("PR Author Checklist is not completely filled out. Please check every box to verify you've thought about the item.");
});
console.log(`Make sure you are using the most up to date checklist found here: ${pathToAuthorChecklist}`);
core.setFailed('PR Author Checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
});
}

getNumberOfItemsFromAuthorChecklist()
Expand Down
Loading

0 comments on commit 8755a82

Please sign in to comment.