Skip to content

Commit

Permalink
feat(conventional-changelog-conventionalcommits): add option to remov…
Browse files Browse the repository at this point in the history
…e references with duplicate issues
  • Loading branch information
james-prado committed Aug 14, 2022
1 parent bfe3bf1 commit df4a69f
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
21 changes: 21 additions & 0 deletions packages/conventional-changelog-conventionalcommits/test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,9 @@ betterThanBefore.setups([
'chore: release at different version',
'Release-As: v3.0.2'
])
},
function () {
gitDummyCommit(['feat(awesome): remove duplicates', 'fixes A of #107', 'fixes B of #107', ' closes #107'])
}
])

Expand Down Expand Up @@ -614,4 +617,22 @@ describe('conventionalcommits.org preset', function () {
done()
}))
})
it('should remove all duplicate issues', function (done) {
preparing(12)

conventionalChangelogCore({
config: getPreset({
removeDuplicateIssues: true
})
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()
const matches = [...chunk.matchAll(/\[#107\]\(.*\)/g)]
expect(chunk).to.satisfy(() => matches.length === 1)
done()
}))
})
})
27 changes: 21 additions & 6 deletions packages/conventional-changelog-conventionalcommits/writer-opts.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,26 @@ function getWriterOpts (config) {
}

// remove references that already appear in the subject
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.prefix + reference.issue) === -1) {
return true
}
if (config.removeIssuesShownInSubject) {
commit.references = commit.references.filter(reference => {
if (issues.indexOf(reference.prefix + reference.issue) === -1) {
return true
}

return false
})
return false
})
}

// remove references with duplicate issues
if (config.removeDuplicateIssues) {
commit.references = commit.references.reduce(
(uniqueReferences, reference) =>
uniqueReferences.find(({ issue }) => issue === reference.issue)
? uniqueReferences
: [...uniqueReferences, reference],
[]
)
}

return commit
},
Expand Down Expand Up @@ -199,6 +212,8 @@ function defaultConfig (config) {
config.userUrlFormat = config.userUrlFormat ||
'{{host}}/{{user}}'
config.issuePrefixes = config.issuePrefixes || ['#']
config.removeIssuesShownInSubject = config.removeIssuesShownInSubject || true
config.removeDuplicateIssues = config.removeDuplicateIssues || false

return config
}
Expand Down

0 comments on commit df4a69f

Please sign in to comment.