Skip to content
Closed
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 @@ -13,33 +13,52 @@ const combinedComments = [];
*/
function getNumberOfItemsFromReviewerChecklist() {
return new Promise((resolve, reject) => {
console.log(`Fetching checklist from ${pathToReviewerChecklist}`);
https.get(pathToReviewerChecklist, (res) => {
let fileContents = '';
res.on('data', (chunk) => {
fileContents += chunk;
});
res.on('end', () => {
console.log('Finished fetching checklist');
const numberOfChecklistItems = (fileContents.match(/- \[ \]/g) || []).length;
resolve(numberOfChecklistItems);
});
})
.on('error', reject);
.on('error', (err) => {
console.log('Problem fetching checklist')
console.error(err);
reject(err);
});
});
}

/**
* @param {Number} numberOfChecklistItems
*/
function checkIssueForCompletedChecklist(numberOfChecklistItems) {
console.log('Starting to look for completed checklist');
console.log('Getting all comments from PR reviews');
GitHubUtils.getAllReviewComments(issue)
.then(reviewComments => combinedComments.push(...reviewComments))
.then(() => GitHubUtils.getAllComments(issue))
.then(comments => combinedComments.push(...comments))
.then(reviewComments => {
console.log(`Found ${reviewComments.length} comments from PR reviews on this PR`);
combinedComments.push(...reviewComments)
})
.then(() => {
console.log('Getting all PR comments');
GitHubUtils.getAllComments(issue)
})
.then(comments => {
console.log(`Found ${comments.length} PR comments on this PR`);
combinedComments.push(...comments)
})
.then(() => {
console.log(`Found ${combinedComments.length} total comments`);
let foundReviewerChecklist = false;
let numberOfFinishedChecklistItems = 0;
let numberOfUnfinishedChecklistItems = 0;

console.log('Looking for the reviewer checklist comment');
// Once we've gathered all the data, loop through each comment and look to see if it contains the reviewer checklist
for (let i = 0; i < combinedComments.length; i++) {
// Skip all other comments if we already found the reviewer checklist
Expand All @@ -50,14 +69,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 checklist comment');
foundReviewerChecklist = true;
numberOfFinishedChecklistItems = (comment.match(/- \[x\]/gi) || []).length;
numberOfUnfinishedChecklistItems = (comment.match(/- \[ \]/g) || []).length;
}
}

if (!foundReviewerChecklist) {
core.setFailed('PR Reviewer Checklist was not found in any comments');
return;
}

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

Expand All @@ -75,6 +102,7 @@ function checkIssueForCompletedChecklist(numberOfChecklistItems) {
});
}

console.log('Starting reviewer checklist');
getNumberOfItemsFromReviewerChecklist()
.then(checkIssueForCompletedChecklist, (err) => {
console.error(err);
Expand Down