Skip to content

Commit 2c06524

Browse files
committed
fix(create-changelog): merge commit footers
1 parent 72860fa commit 2c06524

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

create-changelog/dist/index.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create-changelog/dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

create-changelog/index.js

Lines changed: 44 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -597,38 +597,57 @@ async function getLocalCommits(projectPath, repoUrl, versionPattern, tags) {
597597
}
598598

599599
function removeCommitDuplicates(commits) {
600+
/** @type {Commit[]} */
600601
const uniqueCommits = []
601-
const seenValues = new Set()
602+
/** @type {Set<string>} */
603+
const visitedCommits = new Set()
602604

603605
for (const commit of commits) {
604-
const comparisonValues = JSON.stringify([commit.type, commit.scope, commit.description])
605-
if (!seenValues.has(comparisonValues)) {
606+
const commitStr = JSON.stringify([commit.type, commit.scope, commit.description])
607+
const isNewCommit = !visitedCommits.has(commitStr)
608+
if (isNewCommit) {
606609
uniqueCommits.push(commit)
607-
seenValues.add(comparisonValues)
608-
} else {
609-
let idx = -1
610-
for (let i = 0; i < uniqueCommits.length; i++) {
611-
const comparisonValues2 = JSON.stringify([uniqueCommits[i].type, uniqueCommits[i].scope, uniqueCommits[i].description])
612-
if (comparisonValues === comparisonValues2) {
613-
idx = i
614-
break
615-
}
610+
visitedCommits.add(commitStr)
611+
continue
612+
}
613+
614+
// The commit has already been included in the list
615+
// Find the commit we put on the list
616+
let idx = -1
617+
for (let i = 0; i < uniqueCommits.length; i++) {
618+
const otherCommitStr = JSON.stringify([uniqueCommits[i].type, uniqueCommits[i].scope, uniqueCommits[i].description])
619+
if (commitStr === otherCommitStr) {
620+
idx = i
621+
break
616622
}
617-
if (idx !== -1) {
618-
if (uniqueCommits[idx].body !== commit.body) {
619-
uniqueCommits[idx].body += commit.body
620-
}
621-
for (const [footerKey, footerValue] of Object.entries(commit.footers)) {
622-
if (!uniqueCommits[idx].footers.includes(footerKey)) {
623-
uniqueCommits[idx].footers.push(footerKey)
624-
}
625-
}
626-
if (commit.breaking) {
627-
uniqueCommits[idx].breaking = true
628-
}
629-
uniqueCommits[idx].extra_hashes.push(commit.hash)
623+
}
624+
const cannotFindCommit = idx === -1
625+
if (cannotFindCommit) {
626+
continue
627+
}
628+
629+
// Merge the commit with the one we put on the list
630+
if (uniqueCommits[idx].body !== commit.body) {
631+
uniqueCommits[idx].body += commit.body
632+
}
633+
// Merge footers
634+
for (const [footerKey, footerValue] of Object.entries(commit.footers)) {
635+
if (!uniqueCommits[idx].footers.hasOwnProperty(footerKey)) {
636+
uniqueCommits[idx].footers[footerKey] = footerValue;
630637
}
631638
}
639+
// Merge tags
640+
for (const tag of commit.tags) {
641+
if (!uniqueCommits[idx].tags.includes(tag)) {
642+
uniqueCommits[idx].tags.push(tag)
643+
}
644+
}
645+
// Merge breaking
646+
if (commit.breaking) {
647+
uniqueCommits[idx].breaking = true
648+
}
649+
// Merge extra hashes
650+
uniqueCommits[idx].extra_hashes.push(commit.hash)
632651
}
633652

634653
return uniqueCommits

0 commit comments

Comments
 (0)