Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(conventional-changelog-conventionalcommits): add option to remove duplicate issues #939

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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