From 20ead42df9a2bfe06bdf0672d938c4c68bbdb0bf Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Wed, 26 Oct 2022 15:33:03 -0700 Subject: [PATCH 1/6] update checkbox counting logic --- .../contributorChecklist/contributorChecklist.js | 15 +++++++++++---- .../javascript/contributorChecklist/index.js | 15 +++++++++++---- 2 files changed, 22 insertions(+), 8 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/contributorChecklist.js b/.github/actions/javascript/contributorChecklist/contributorChecklist.js index 7411fbf88bd71..f39b2d9877ec1 100644 --- a/.github/actions/javascript/contributorChecklist/contributorChecklist.js +++ b/.github/actions/javascript/contributorChecklist/contributorChecklist.js @@ -127,6 +127,10 @@ function getAllComments() { }, response => _.map(response.data, comment => comment.body)); } +function countCheckedBoxes(string) { + return [...string.toLowerCase().matchAll(/\[x\]/g)].length; +} + getPullRequestBody() .then(pullRequestBody => combinedData.push(pullRequestBody)) .then(() => getAllReviewComments()) @@ -137,16 +141,19 @@ getPullRequestBody() let authorChecklistComplete = false; let reviewerChecklistComplete = false; + 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 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, ''))) { + if (commentChecklistNumber >= authorChecklistNumber - 2 && commentChecklistNumber <= authorChecklistNumber + 2 && !comment.includes('[ ]')) { authorChecklistComplete = true; } - if (comment.includes(completedReviewerChecklist.replace(whitespace, ''))) { + if (commentChecklistNumber >= reviewerChecklistNumber - 2 && commentChecklistNumber <= reviewerChecklistNumber + 2 && !comment.includes('[ ]')) { reviewerChecklistComplete = true; } } diff --git a/.github/actions/javascript/contributorChecklist/index.js b/.github/actions/javascript/contributorChecklist/index.js index ecf8f6ecd625f..05232cf145693 100644 --- a/.github/actions/javascript/contributorChecklist/index.js +++ b/.github/actions/javascript/contributorChecklist/index.js @@ -137,6 +137,10 @@ function getAllComments() { }, response => _.map(response.data, comment => comment.body)); } +function countCheckedBoxes(string) { + return [...string.toLowerCase().matchAll(/\[x\]/g)].length; +} + getPullRequestBody() .then(pullRequestBody => combinedData.push(pullRequestBody)) .then(() => getAllReviewComments()) @@ -147,16 +151,19 @@ getPullRequestBody() let authorChecklistComplete = false; let reviewerChecklistComplete = false; + 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 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, ''))) { + if (commentChecklistNumber >= authorChecklistNumber - 2 && commentChecklistNumber <= authorChecklistNumber + 2 && !comment.includes('[ ]')) { authorChecklistComplete = true; } - if (comment.includes(completedReviewerChecklist.replace(whitespace, ''))) { + if (commentChecklistNumber >= reviewerChecklistNumber - 2 && commentChecklistNumber <= reviewerChecklistNumber + 2 && !comment.includes('[ ]')) { reviewerChecklistComplete = true; } } From dcf224ef0f28d1e7a8886975d48a88421fbe7df4 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Sat, 29 Oct 2022 12:46:08 -0700 Subject: [PATCH 2/6] only look at appropriate checklist section --- .../contributorChecklist/contributorChecklist.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/contributorChecklist.js b/.github/actions/javascript/contributorChecklist/contributorChecklist.js index f39b2d9877ec1..0f81a315d9eb4 100644 --- a/.github/actions/javascript/contributorChecklist/contributorChecklist.js +++ b/.github/actions/javascript/contributorChecklist/contributorChecklist.js @@ -128,11 +128,16 @@ function getAllComments() { } function countCheckedBoxes(string) { - return [...string.toLowerCase().matchAll(/\[x\]/g)].length; + return string.toLowerCase().match(/\[x\]/g).length; +} + +function getChecklistSectionOfPullRequestBody(pullRequestBody) { + const processed = pullRequestBody.match(/#### PR Author Checklist(.*)

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()) @@ -144,7 +149,7 @@ getPullRequestBody() 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 for (let i = 0; i < combinedData.length; i++) { const comment = combinedData[i]; const commentChecklistNumber = countCheckedBoxes(comment); From 328ce34b5b14689ef2fe125a6b9740f31b33518a Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Sat, 29 Oct 2022 12:51:55 -0700 Subject: [PATCH 3/6] update build --- .../actions/javascript/contributorChecklist/index.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/index.js b/.github/actions/javascript/contributorChecklist/index.js index 05232cf145693..34155a512206f 100644 --- a/.github/actions/javascript/contributorChecklist/index.js +++ b/.github/actions/javascript/contributorChecklist/index.js @@ -138,11 +138,16 @@ function getAllComments() { } function countCheckedBoxes(string) { - return [...string.toLowerCase().matchAll(/\[x\]/g)].length; + return string.toLowerCase().match(/\[x\]/g).length; +} + +function getChecklistSectionOfPullRequestBody(pullRequestBody) { + const processed = pullRequestBody.match(/#### PR Author Checklist(.*)

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()) @@ -154,7 +159,7 @@ getPullRequestBody() 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 for (let i = 0; i < combinedData.length; i++) { const comment = combinedData[i]; const commentChecklistNumber = countCheckedBoxes(comment); From c1c964323cc0a3dc4894f2ff589a743454fefc1d Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Tue, 1 Nov 2022 21:17:58 -0700 Subject: [PATCH 4/6] stop double counting checklists --- .../contributorChecklist.js | 28 +++++++++++++------ 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/contributorChecklist.js b/.github/actions/javascript/contributorChecklist/contributorChecklist.js index 0f81a315d9eb4..809cb1675603b 100644 --- a/.github/actions/javascript/contributorChecklist/contributorChecklist.js +++ b/.github/actions/javascript/contributorChecklist/contributorChecklist.js @@ -143,8 +143,8 @@ getPullRequestBody() .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); @@ -154,22 +154,34 @@ getPullRequestBody() const comment = combinedData[i]; const commentChecklistNumber = countCheckedBoxes(comment); - if (commentChecklistNumber >= authorChecklistNumber - 2 && commentChecklistNumber <= authorChecklistNumber + 2 && !comment.includes('[ ]')) { - authorChecklistComplete = true; + if ( + reviewerChecklistComment !== i + && authorChecklistComment !== i + && commentChecklistNumber >= authorChecklistNumber - 2 + && commentChecklistNumber <= authorChecklistNumber + 2 + && !comment.includes('[ ]') + ) { + authorChecklistComment = i; } - if (commentChecklistNumber >= reviewerChecklistNumber - 2 && commentChecklistNumber <= reviewerChecklistNumber + 2 && !comment.includes('[ ]')) { - reviewerChecklistComplete = true; + if ( + reviewerChecklistComment !== i + && 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; From d299057513e88a096159a261c60194c8faa96238 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Tue, 1 Nov 2022 21:20:06 -0700 Subject: [PATCH 5/6] simplify logic --- .../contributorChecklist/contributorChecklist.js | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/contributorChecklist.js b/.github/actions/javascript/contributorChecklist/contributorChecklist.js index 809cb1675603b..7cb201bdbbac3 100644 --- a/.github/actions/javascript/contributorChecklist/contributorChecklist.js +++ b/.github/actions/javascript/contributorChecklist/contributorChecklist.js @@ -155,9 +155,7 @@ getPullRequestBody() const commentChecklistNumber = countCheckedBoxes(comment); if ( - reviewerChecklistComment !== i - && authorChecklistComment !== i - && commentChecklistNumber >= authorChecklistNumber - 2 + commentChecklistNumber >= authorChecklistNumber - 2 && commentChecklistNumber <= authorChecklistNumber + 2 && !comment.includes('[ ]') ) { @@ -165,8 +163,7 @@ getPullRequestBody() } if ( - reviewerChecklistComment !== i - && authorChecklistComment !== i + authorChecklistComment !== i && commentChecklistNumber >= reviewerChecklistNumber - 2 && commentChecklistNumber <= reviewerChecklistNumber + 2 && !comment.includes('[ ]') From b12492f73bbdb445547d64f3313ef566e1093b50 Mon Sep 17 00:00:00 2001 From: Daniel Gale-Rosen Date: Tue, 1 Nov 2022 21:27:08 -0700 Subject: [PATCH 6/6] build actions --- .../javascript/contributorChecklist/index.js | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/.github/actions/javascript/contributorChecklist/index.js b/.github/actions/javascript/contributorChecklist/index.js index 34155a512206f..23879c3b08989 100644 --- a/.github/actions/javascript/contributorChecklist/index.js +++ b/.github/actions/javascript/contributorChecklist/index.js @@ -153,8 +153,8 @@ getPullRequestBody() .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); @@ -164,22 +164,31 @@ getPullRequestBody() const comment = combinedData[i]; const commentChecklistNumber = countCheckedBoxes(comment); - if (commentChecklistNumber >= authorChecklistNumber - 2 && commentChecklistNumber <= authorChecklistNumber + 2 && !comment.includes('[ ]')) { - authorChecklistComplete = true; + if ( + commentChecklistNumber >= authorChecklistNumber - 2 + && commentChecklistNumber <= authorChecklistNumber + 2 + && !comment.includes('[ ]') + ) { + authorChecklistComment = i; } - if (commentChecklistNumber >= reviewerChecklistNumber - 2 && commentChecklistNumber <= reviewerChecklistNumber + 2 && !comment.includes('[ ]')) { - 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;