Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

Commit

Permalink
Update dangerfile (#306)
Browse files Browse the repository at this point in the history
  • Loading branch information
sycombs authored Apr 6, 2023
1 parent 4251ae9 commit e1c673f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions dangerfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ if (lernaConfig.command) {
const CHANGELOG_PATTERN = /^packages\/([a-z-])*\/CHANGELOG\.md/i;

const changedFiles = danger.git.created_files.concat(danger.git.modified_files);
const allowedFilepaths = ['package.json', 'CHANGELOG.md', 'src', 'translations', 'terra-graphs-docs'];

const changedChangelogs = new Set();
const changedPackages = new Set();
Expand All @@ -32,16 +33,24 @@ changedFiles.forEach((file) => {
return;
}

if (!allowedFilepaths.some(filepath => file.includes(filepath))) {
// skip further processing if the changed file is not among the allowed filepaths
return;
}

if (CHANGELOG_PATTERN.test(file)) {
// changed file is the CHANGELOG itself
changedChangelogs.add(packageName);
} else { // file is in a package and was changed - we need a changelog
changedPackages.add(packageName);
return;
}

// for other allowed files
changedPackages.add(packageName);
});

const missingChangelogs = [...changedPackages].filter(packageName => !changedChangelogs.has(packageName));

// Fail if there are package changes without a CHANGELOG update
if (missingChangelogs.length > 0) {
fail(`Please include a CHANGELOG entry for each changed package this PR. Looks like a CHANGELOG is missing for: \n\n - ${missingChangelogs.join('\n - ')}`);
fail(`Please include a CHANGELOG entry for each changed package this PR. Looks like a CHANGELOG entry is missing for: \n\n - ${missingChangelogs.join('\n - ')}`);
}

0 comments on commit e1c673f

Please sign in to comment.