diff --git a/dangerfile.js b/dangerfile.js index 1b1ea68dd5..9721db94bc 100644 --- a/dangerfile.js +++ b/dangerfile.js @@ -6,7 +6,8 @@ const validChangesetCategories = ['Added', 'Changed', 'Removed', 'Fixed']; const isDependabotPR = pr.user.login === 'dependabot[bot]'; // Check for correct Changeset formatting -danger.git.created_files.filter((filepath) => filepath.includes('.changeset/') && !filepath.includes('.changeset/pre.json')) +danger.git.created_files + .filter((filepath) => filepath.includes('.changeset/') && !filepath.includes('.changeset/pre.json')) .forEach((filepath) => { const changesetDiff = danger.git.diffForFile(filepath); changesetDiff.then((result) => { @@ -37,26 +38,42 @@ danger.git.created_files.filter((filepath) => filepath.includes('.changeset/') & // Allow unchecked checkboxes only in "Not-applicable Checklist items" if (!isDependabotPR) { const { body } = pr; + const uncheckedCheckboxRegex = /- \[ \]/g; - // Check for unchecked checkboxes - const uncheckedCheckboxMatches = body.match(uncheckedCheckboxRegex); + // Split the body into sections + const sections = body.split(/## /); + const notApplicableSection = sections.find((section) => section.startsWith('Not-applicable Checklist items')); - if (uncheckedCheckboxMatches) { - // Split the body into sections - const sections = body.split(/## /); - const notApplicableSection = sections.find((section) => section.startsWith('Not-applicable Checklist items')); + // Check for unchecked checkboxes outside the "Not-applicable Checklist items" section + const uncheckedOutsideNotApplicableSection = sections.some((section) => { + if (section !== notApplicableSection) { + return uncheckedCheckboxRegex.test(section); + } + return false; + }); - // Check for unchecked checkboxes outside the "Not-applicable Checklist items" section - const uncheckedOutsideNotApplicableSection = sections.some((section) => { - if (section !== notApplicableSection) { - return uncheckedCheckboxRegex.test(section); - } - return false; - }); + if (uncheckedOutsideNotApplicableSection) { + fail('You have unchecked checklist items outside the "Not-applicable Checklist items" section.\n\nPlease ensure all unchecked checkboxes are moved to the appropriate section.'); + } - if (uncheckedOutsideNotApplicableSection) { - fail('You have unchecked checklist items outside the "Not-applicable Checklist items" section.\n\nPlease ensure all unchecked checkboxes are moved to the appropriate section.'); + // Match sections for Reviewer 1 and Reviewer 2 + const reviewer1Section = body.match(/### Reviewer 1.*?(?=###|$)/s); + const reviewer2Section = body.match(/### Reviewer 2.*?(?=###|$)/s); + + // Helper function to check a reviewer's section + const checkReviewerSection = (section, reviewerName) => { + if (section) { + const uncheckedReviewerCheckboxes = section.match(uncheckedCheckboxRegex); + if (uncheckedReviewerCheckboxes) { + fail(`You have unchecked checklist items in ${reviewerName}'s section.\n\nPlease ensure all items are addressed before approval.`); + } } - } + }; + + // Check Reviewer 1 + checkReviewerSection(reviewer1Section ? reviewer1Section[0] : null, 'Reviewer 1'); + + // Check Reviewer 2 + checkReviewerSection(reviewer2Section ? reviewer2Section[0] : null, 'Reviewer 2'); }