mirror of
https://github.com/LukeHagar/vercel.git
synced 2025-12-06 12:57:46 +00:00
* 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
56 lines
1.4 KiB
JavaScript
56 lines
1.4 KiB
JavaScript
const { execSync } = require('child_process');
|
|
|
|
const REVERT_MESSAGE_COMMIT_PATTERN = /This reverts commit ([^.^ ]+)/;
|
|
const AREA_PATTERN = /\[([^\]]+)\]/g;
|
|
|
|
function getCommitMessage(hash) {
|
|
return execSync(`git log --format=%B -n 1 ${hash}`).toString().trim();
|
|
}
|
|
|
|
function parseRevertCommit(message) {
|
|
// EX: This reverts commit 6dff0875f5f361decdb95ad70a400195006c6bba.
|
|
// EX: This reverts commit 6dff0875f5f361decdb95ad70a400195006c6bba (#123123).
|
|
const fullMessageLines = message
|
|
.trim()
|
|
.split('\n')
|
|
.filter(line => line.startsWith('This reverts commit'));
|
|
return fullMessageLines.map(
|
|
line => line.match(REVERT_MESSAGE_COMMIT_PATTERN)[1]
|
|
);
|
|
}
|
|
|
|
function parseAreas(subject) {
|
|
const areaChunk = subject.split(' ')[0] || '';
|
|
const areas = areaChunk.match(AREA_PATTERN);
|
|
if (!areas) {
|
|
return ['UNCATEGORIZED'];
|
|
}
|
|
|
|
return areas.map(area => area.substring(1, area.length - 1));
|
|
}
|
|
|
|
function parseCommits(logLines) {
|
|
const commits = [];
|
|
|
|
logLines.forEach(line => {
|
|
let [subject, hash] = line.split(' &&& ');
|
|
subject = subject.trim();
|
|
|
|
const message = getCommitMessage(hash);
|
|
const revertsHashes = parseRevertCommit(message);
|
|
const areas = parseAreas(subject);
|
|
|
|
commits.push({
|
|
hash,
|
|
areas,
|
|
subject,
|
|
message,
|
|
revertsHashes,
|
|
});
|
|
});
|
|
|
|
return commits;
|
|
}
|
|
|
|
module.exports = parseCommits;
|