Skip to content

Commit

Permalink
dangerjs update
Browse files Browse the repository at this point in the history
  • Loading branch information
jamieomaguire committed Nov 29, 2024
1 parent e70ff21 commit 34f1478
Showing 1 changed file with 34 additions and 17 deletions.
51 changes: 34 additions & 17 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down Expand Up @@ -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');
}

0 comments on commit 34f1478

Please sign in to comment.