Skip to content

Commit

Permalink
Merge pull request #12771 from Expensify/dangrous-reviewer-checklist-…
Browse files Browse the repository at this point in the history
…logs

[No QA] Add console logs to investigate where the Reviewer Checklist check is failing
  • Loading branch information
tgolen authored Nov 18, 2022
2 parents ff24549 + 9eff654 commit e1fceb3
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
}

getNumberOfItemsFromAuthorChecklist()
.then(checkIssueForCompletedChecklist, (err) => {
.then(checkIssueForCompletedChecklist)
.catch((err) => {
console.error(err);
core.setFailed(err);
});
4 changes: 3 additions & 1 deletion .github/actions/javascript/authorChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,10 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
}

getNumberOfItemsFromAuthorChecklist()
.then(checkIssueForCompletedChecklist, (err) => {
.then(checkIssueForCompletedChecklist)
.catch((err) => {
console.error(err);
core.setFailed(err);
});


Expand Down
30 changes: 26 additions & 4 deletions .github/actions/javascript/reviewerChecklist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const combinedComments = [];
* @returns {Promise}
*/
function getNumberOfItemsFromReviewerChecklist() {
console.log('Getting the number of items in the reviewer checklist...');
return new Promise((resolve, reject) => {
https.get(pathToReviewerChecklist, (res) => {
let fileContents = '';
Expand All @@ -30,10 +31,14 @@ function getNumberOfItemsFromReviewerChecklist() {
});
res.on('end', () => {
const numberOfChecklistItems = (fileContents.match(/- \[ \]/g) || []).length;
console.log(`There are ${numberOfChecklistItems} items in the reviewer checklist.`);
resolve(numberOfChecklistItems);
});
})
.on('error', reject);
.on('error', (err) => {
console.error(err);
reject(err);
});
});
}

Expand All @@ -42,10 +47,17 @@ function getNumberOfItemsFromReviewerChecklist() {
*/
function checkIssueForCompletedChecklist(numberOfChecklistItems) {
GitHubUtils.getAllReviewComments(issue)
.then(reviewComments => combinedComments.push(...reviewComments))
.then((reviewComments) => {
console.log(`Pulled ${reviewComments.length} review comments, now adding them to the list...`);
combinedComments.push(...reviewComments);
})
.then(() => GitHubUtils.getAllComments(issue))
.then(comments => combinedComments.push(...comments))
.then((comments) => {
console.log(`Pulled ${comments.length} comments, now adding them to the list...`);
combinedComments.push(...comments);
})
.then(() => {
console.log(`Looking through all ${combinedComments.length} comments for the reviewer checklist...`);
let foundReviewerChecklist = false;
let numberOfFinishedChecklistItems = 0;
let numberOfUnfinishedChecklistItems = 0;
Expand All @@ -60,14 +72,22 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
const whitespace = /([\n\r])/gm;
const comment = combinedComments[i].replace(whitespace, '');

console.log(`Comment ${i} starts with: ${comment.slice(0, 20)}...`);

// Found the reviewer checklist, so count how many completed checklist items there are
if (comment.startsWith(reviewerChecklistStartsWith)) {
console.log('Found the reviewer checklist!');
foundReviewerChecklist = true;
numberOfFinishedChecklistItems = (comment.match(/- \[x\]/gi) || []).length;
numberOfUnfinishedChecklistItems = (comment.match(/- \[ \]/g) || []).length;
}
}

if (!foundReviewerChecklist) {
core.setFailed('No PR Reviewer Checklist was found');
return;
}

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

Expand All @@ -86,8 +106,10 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
}

getNumberOfItemsFromReviewerChecklist()
.then(checkIssueForCompletedChecklist, (err) => {
.then(checkIssueForCompletedChecklist)
.catch((err) => {
console.error(err);
core.setFailed(err);
});


Expand Down
30 changes: 26 additions & 4 deletions .github/actions/javascript/reviewerChecklist/reviewerChecklist.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const combinedComments = [];
* @returns {Promise}
*/
function getNumberOfItemsFromReviewerChecklist() {
console.log('Getting the number of items in the reviewer checklist...');
return new Promise((resolve, reject) => {
https.get(pathToReviewerChecklist, (res) => {
let fileContents = '';
Expand All @@ -20,10 +21,14 @@ function getNumberOfItemsFromReviewerChecklist() {
});
res.on('end', () => {
const numberOfChecklistItems = (fileContents.match(/- \[ \]/g) || []).length;
console.log(`There are ${numberOfChecklistItems} items in the reviewer checklist.`);
resolve(numberOfChecklistItems);
});
})
.on('error', reject);
.on('error', (err) => {
console.error(err);
reject(err);
});
});
}

Expand All @@ -32,10 +37,17 @@ function getNumberOfItemsFromReviewerChecklist() {
*/
function checkIssueForCompletedChecklist(numberOfChecklistItems) {
GitHubUtils.getAllReviewComments(issue)
.then(reviewComments => combinedComments.push(...reviewComments))
.then((reviewComments) => {
console.log(`Pulled ${reviewComments.length} review comments, now adding them to the list...`);
combinedComments.push(...reviewComments);
})
.then(() => GitHubUtils.getAllComments(issue))
.then(comments => combinedComments.push(...comments))
.then((comments) => {
console.log(`Pulled ${comments.length} comments, now adding them to the list...`);
combinedComments.push(...comments);
})
.then(() => {
console.log(`Looking through all ${combinedComments.length} comments for the reviewer checklist...`);
let foundReviewerChecklist = false;
let numberOfFinishedChecklistItems = 0;
let numberOfUnfinishedChecklistItems = 0;
Expand All @@ -50,14 +62,22 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
const whitespace = /([\n\r])/gm;
const comment = combinedComments[i].replace(whitespace, '');

console.log(`Comment ${i} starts with: ${comment.slice(0, 20)}...`);

// Found the reviewer checklist, so count how many completed checklist items there are
if (comment.startsWith(reviewerChecklistStartsWith)) {
console.log('Found the reviewer checklist!');
foundReviewerChecklist = true;
numberOfFinishedChecklistItems = (comment.match(/- \[x\]/gi) || []).length;
numberOfUnfinishedChecklistItems = (comment.match(/- \[ \]/g) || []).length;
}
}

if (!foundReviewerChecklist) {
core.setFailed('No PR Reviewer Checklist was found');
return;
}

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

Expand All @@ -76,6 +96,8 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
}

getNumberOfItemsFromReviewerChecklist()
.then(checkIssueForCompletedChecklist, (err) => {
.then(checkIssueForCompletedChecklist)
.catch((err) => {
console.error(err);
core.setFailed(err);
});

0 comments on commit e1fceb3

Please sign in to comment.