Files
vercel/utils/changelog/filter.js
Sean Massa 56960e506e [cli] enhance changelog accuracy and format (#7387)
* refactor and add test to changelog

* group changelog into areas

* remove revert and reverted commits from changelog

* make sure Revert commits that revert a commit in a previous changelog are not filtered

* run "yarn test" as part of "yarn test-unit"

* remove advanced syntax

* remove advanced syntax

* temp changelog

* remove temp changelog

* remove global jest config

* Delete symlink

* scope jest dir to just the test files we care about
2022-03-02 10:22:56 -08:00

32 lines
854 B
JavaScript

/**
* Filters out "Revert" commits as well as the commits they revert, if found.
*/
function filterReverts(commits) {
const revertCommits = commits.filter(commit => commit.revertsHashes.length);
const commitHashes = commits.map(commit => commit.hash);
let hashesToRemove = [];
revertCommits.forEach(revertCommit => {
const allFound = revertCommit.revertsHashes.every(hash => {
return commitHashes.includes(hash);
});
if (allFound) {
hashesToRemove = [
...hashesToRemove,
...revertCommit.revertsHashes,
revertCommit.hash,
];
}
});
return commits.filter(commit => !hashesToRemove.includes(commit.hash));
}
function normalizeLog(commits) {
commits = commits.filter(line => !line.subject.startsWith('Publish '));
return filterReverts(commits);
}
module.exports = normalizeLog;