Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -127,37 +127,58 @@ function getAllComments() {
}, response => _.map(response.data, comment => comment.body));
}

function countCheckedBoxes(string) {
return string.toLowerCase().match(/\[x\]/g).length;
}

function getChecklistSectionOfPullRequestBody(pullRequestBody) {
const processed = pullRequestBody.match(/#### PR Author Checklist(.*)<h4>PR Reviewer Checklist<\/h4>/);
return processed ? processed[1] : '';
}

getPullRequestBody()
.then(pullRequestBody => combinedData.push(pullRequestBody))
.then(pullRequestBody => combinedData.push(getChecklistSectionOfPullRequestBody(pullRequestBody)))
.then(() => getAllReviewComments())
.then(reviewComments => combinedData.push(...reviewComments))
.then(() => getAllComments())
.then(comments => combinedData.push(...comments))
.then(() => {
let authorChecklistComplete = false;
let reviewerChecklistComplete = false;
let authorChecklistComment = null;
let reviewerChecklistComment = null;

const authorChecklistNumber = countCheckedBoxes(completedAuthorChecklist);
const reviewerChecklistNumber = countCheckedBoxes(completedReviewerChecklist);

// Once we've gathered all the data, loop through each comment and look to see if it contains a completed checklist
// Once we've gathered all the data, loop through each comment and look to see if it contains enough completed checkboxes
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can also include a word about the empty checkboxes (there should not be any)

for (let i = 0; i < combinedData.length; i++) {
const whitespace = /([\n\r])/gm;
const comment = combinedData[i].replace(whitespace, '');
const comment = combinedData[i];
const commentChecklistNumber = countCheckedBoxes(comment);

if (comment.includes(completedAuthorChecklist.replace(whitespace, ''))) {
authorChecklistComplete = true;
if (
commentChecklistNumber >= authorChecklistNumber - 2
&& commentChecklistNumber <= authorChecklistNumber + 2
&& !comment.includes('[ ]')
) {
authorChecklistComment = i;
}

if (comment.includes(completedReviewerChecklist.replace(whitespace, ''))) {
reviewerChecklistComplete = true;
if (
authorChecklistComment !== i
&& commentChecklistNumber >= reviewerChecklistNumber - 2
&& commentChecklistNumber <= reviewerChecklistNumber + 2
&& !comment.includes('[ ]')
) {
reviewerChecklistComment = i;
}
}

if (verifyingAuthorChecklist && !authorChecklistComplete) {
if (verifyingAuthorChecklist && authorChecklistComment === null) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('PR Author Checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}

if (!verifyingAuthorChecklist && !reviewerChecklistComplete) {
if (!verifyingAuthorChecklist && reviewerChecklistComment === null) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('PR Reviewer Checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
Expand Down
47 changes: 34 additions & 13 deletions .github/actions/javascript/contributorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -137,37 +137,58 @@ function getAllComments() {
}, response => _.map(response.data, comment => comment.body));
}

function countCheckedBoxes(string) {
return string.toLowerCase().match(/\[x\]/g).length;
}

function getChecklistSectionOfPullRequestBody(pullRequestBody) {
const processed = pullRequestBody.match(/#### PR Author Checklist(.*)<h4>PR Reviewer Checklist<\/h4>/);
return processed ? processed[1] : '';
}

getPullRequestBody()
.then(pullRequestBody => combinedData.push(pullRequestBody))
.then(pullRequestBody => combinedData.push(getChecklistSectionOfPullRequestBody(pullRequestBody)))
.then(() => getAllReviewComments())
.then(reviewComments => combinedData.push(...reviewComments))
.then(() => getAllComments())
.then(comments => combinedData.push(...comments))
.then(() => {
let authorChecklistComplete = false;
let reviewerChecklistComplete = false;
let authorChecklistComment = null;
let reviewerChecklistComment = null;

// Once we've gathered all the data, loop through each comment and look to see if it contains a completed checklist
for (let i = 0; i < combinedData.length; i++) {
const whitespace = /([\n\r])/gm;
const comment = combinedData[i].replace(whitespace, '');
const authorChecklistNumber = countCheckedBoxes(completedAuthorChecklist);
const reviewerChecklistNumber = countCheckedBoxes(completedReviewerChecklist);

if (comment.includes(completedAuthorChecklist.replace(whitespace, ''))) {
authorChecklistComplete = true;
// Once we've gathered all the data, loop through each comment and look to see if it contains enough completed checkboxes
for (let i = 0; i < combinedData.length; i++) {
const comment = combinedData[i];
const commentChecklistNumber = countCheckedBoxes(comment);

if (
commentChecklistNumber >= authorChecklistNumber - 2
&& commentChecklistNumber <= authorChecklistNumber + 2
&& !comment.includes('[ ]')
) {
authorChecklistComment = i;
}

if (comment.includes(completedReviewerChecklist.replace(whitespace, ''))) {
reviewerChecklistComplete = true;
if (
authorChecklistComment !== i
&& commentChecklistNumber >= reviewerChecklistNumber - 2
&& commentChecklistNumber <= reviewerChecklistNumber + 2
&& !comment.includes('[ ]')
) {
reviewerChecklistComment = i;
}
}

if (verifyingAuthorChecklist && !authorChecklistComplete) {
if (verifyingAuthorChecklist && authorChecklistComment === null) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('PR Author Checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
}

if (!verifyingAuthorChecklist && !reviewerChecklistComplete) {
if (!verifyingAuthorChecklist && reviewerChecklistComment === null) {
console.log('Make sure you are using the most up to date checklist found here: https://raw.githubusercontent.com/Expensify/App/main/.github/PULL_REQUEST_TEMPLATE.md');
core.setFailed('PR Reviewer Checklist is not completely filled out. Please check every box to verify you\'ve thought about the item.');
return;
Expand Down