Skip to content

Commit

Permalink
fix: address discrepancies between cc preset and spec (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoe committed Mar 31, 2019
1 parent 2fef568 commit 18f71d2
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 13 deletions.
3 changes: 3 additions & 0 deletions packages/conventional-changelog-conventionalcommits/README.md
Expand Up @@ -6,6 +6,9 @@ A concrete implementation of the specification described at
[conventionalcommits.org](https://conventionalcommits.org/) for automated
CHANGELOG generation and version management.

TODO: once we flesh out the spec for configuring conventional-changelog tools,
fill in this section of the README [see](https://github.com/conventional-changelog/conventional-changelog-config-spec/issues/1).

[travis-image]: https://travis-ci.org/conventional-changelog/conventional-changelog.svg?branch=master
[travis-url]: https://travis-ci.org/conventional-changelog/conventional-changelog
[coveralls-image]: https://coveralls.io/repos/conventional-changelog/conventional-changelog/badge.svg
Expand Down
57 changes: 51 additions & 6 deletions packages/conventional-changelog-conventionalcommits/test/test.js
Expand Up @@ -24,8 +24,8 @@ betterThanBefore.setups([

gitDummyCommit(['build: first build setup', 'BREAKING CHANGE: New build system.'])
gitDummyCommit(['ci(travis): add TravisCI pipeline', 'BREAKING CHANGE: Continuously integrated.'])
gitDummyCommit(['feat: amazing new module', 'BREAKING CHANGE: Not backward compatible.'])
gitDummyCommit(['fix(compile): avoid a bug', 'BREAKING CHANGE: The Change is huge.'])
gitDummyCommit(['Feat: amazing new module', 'BREAKING CHANGE: Not backward compatible.'])
gitDummyCommit(['Fix(compile): avoid a bug', 'BREAKING CHANGE: The Change is huge.'])
gitDummyCommit(['perf(ngOptions): make it faster', ' closes #1, #2'])
gitDummyCommit('revert(ngOptions): bad commit')
gitDummyCommit('fix(*): oops')
Expand Down Expand Up @@ -57,6 +57,15 @@ betterThanBefore.setups([
function () {
gitDummyCommit(['fix: use npm@5 (@username)'])
gitDummyCommit(['build(deps): bump @dummy/package from 7.1.2 to 8.0.0', 'BREAKING CHANGE: The Change is huge.'])
gitDummyCommit([
'feat: complex new feature',
'this is a complex new feature with many reviewers',
'Reviewer: @hutson',
'Fixes: #99',
'Refs: #100',
'BREAKING CHANGE: this completely changes the API'
])
gitDummyCommit(['FEAT(foo): incredible new flag FIXES: #33'])
}
])

Expand Down Expand Up @@ -122,7 +131,7 @@ describe('conventionalcommits.org preset', function () {
expect(chunk).to.include('**travis:** Continuously integrated.')
expect(chunk).to.include('amazing new module')
expect(chunk).to.include('**compile:** avoid a bug')
expect(chunk).to.include('feat')
expect(chunk).to.include('Feat')

expect(chunk).to.not.include('make it faster')
expect(chunk).to.not.include('Reverts')
Expand Down Expand Up @@ -163,18 +172,20 @@ describe('conventionalcommits.org preset', function () {
}))
})

it('should replace @username with GitHub user URL', function (done) {
it('should replace @user with configured userUrlFormat', function (done) {
preparing(4)

conventionalChangelogCore({
config: preset
config: require('../')({
userUrlFormat: 'https://foo/{{user}}'
})
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()
expect(chunk).to.include('[@bcoe](https://github.com/bcoe)')
expect(chunk).to.include('[@bcoe](https://foo/bcoe)')
done()
}))
})
Expand Down Expand Up @@ -356,4 +367,38 @@ describe('conventionalcommits.org preset', function () {
done()
}))
})

it('supports multiple lines of footer information', function (done) {
preparing(8)

conventionalChangelogCore({
config: preset
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()
expect(chunk).to.include('closes [#99]')
expect(chunk).to.include('[#100]')
expect(chunk).to.include('this completely changes the API')
done()
}))
})

it('does not require that types are case sensitive', function (done) {
preparing(8)

conventionalChangelogCore({
config: preset
})
.on('error', function (err) {
done(err)
})
.pipe(through(function (chunk) {
chunk = chunk.toString()
expect(chunk).to.include('incredible new flag')
done()
}))
})
})
26 changes: 19 additions & 7 deletions packages/conventional-changelog-conventionalcommits/writer-opts.js
Expand Up @@ -56,17 +56,18 @@ function getWriterOpts (config) {
transform: (commit, context) => {
let discard = true
const issues = []
const typeKey = (commit.type || '').toLowerCase()

commit.notes.forEach(note => {
note.title = `BREAKING CHANGES`
discard = false
})

// breaking changes attached to any type are still displayed.
if (discard && (typesLookup[commit.type] === undefined ||
typesLookup[commit.type].hide)) return
if (discard && (typesLookup[typeKey] === undefined ||
typesLookup[typeKey].hide)) return

if (typesLookup[commit.type]) commit.type = typesLookup[commit.type].name
if (typesLookup[typeKey]) commit.type = typesLookup[typeKey].name

if (commit.scope === `*`) {
commit.scope = ``
Expand All @@ -92,12 +93,20 @@ function getWriterOpts (config) {
}
if (context.host) {
// User URLs.
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, username) => {
if (username.includes('/')) {
return `@${username}`
commit.subject = commit.subject.replace(/\B@([a-z0-9](?:-?[a-z0-9/]){0,38})/g, (_, user) => {
// TODO: investigate why this code exists.
if (user.includes('/')) {
return `@${user}`
}

return `[@${username}](${context.host}/${username})`
const usernameUrl = expandTemplate(config.userUrlFormat, {
host: context.host,
owner: context.owner,
repository: context.repository,
user: user
})

return `[@${user}](${usernameUrl})`
})
}
}
Expand Down Expand Up @@ -143,6 +152,9 @@ function defaultConfig (config) {
'{{host}}/{{owner}}/{{repository}}/commit/{{hash}}'
config.compareUrlFormat = config.compareUrlFormat ||
'{{host}}/{{owner}}/{{repository}}/compare/{{previousTag}}...{{currentTag}}'
config.userUrlFormat = config.userUrlFormat ||
'{{host}}/{{user}}'

return config
}

Expand Down

0 comments on commit 18f71d2

Please sign in to comment.