Skip to content

Commit

Permalink
Add --breaking-pattern option
Browse files Browse the repository at this point in the history
Fixes #41
  • Loading branch information
cookpete committed May 17, 2018
1 parent 7f448ce commit 68b93e0
Show file tree
Hide file tree
Showing 13 changed files with 89 additions and 10 deletions.
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Options:
-l, --commit-limit [count] # number of commits to display per release, default: 3
-i, --issue-url [url] # override url for issues, use {id} for issue id
--issue-pattern [regex] # override regex pattern for issues in commit messages
--breaking-pattern [regex] # regex pattern for breaking change commits
--ignore-commit-pattern [regex] # pattern to ignore when parsing commits
--starting-commit [hash] # starting commit to use for changelog generation
--tag-prefix [prefix] # prefix used in version tags, default: v
Expand Down Expand Up @@ -134,6 +135,14 @@ Using `-p` or `--package` uses the `version` from `package.json` as the latest r

Now every time you run [`npm version`](https://docs.npmjs.com/cli/version), the changelog will automatically update and be part of the version commit.

#### Breaking changes

If you use a common pattern in your commit messages for breaking changes, use `--breaking-pattern` to highlight those commits as breaking changes in your changelog. Breaking change commits will always be listed as part of a release, regardless of any `--commit-limit` set.

```bash
auto-changelog --breaking-pattern "BREAKING CHANGE:"
```

#### Custom templates

If you aren’t happy with the default templates or want to tweak something, you can point to a [handlebars](http://handlebarsjs.com) template in your local repo. Check out the [existing templates](templates) to see what is possible.
Expand Down
1 change: 1 addition & 0 deletions src/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ function parseCommit (commit, remote, options = {}) {
fixes: getFixes(message, remote, options),
merge: getMerge(message, remote),
href: getCommitLink(hash, remote),
breaking: !!options.breakingPattern && new RegExp(options.breakingPattern).test(message),
...getStats(stats.trim())
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,9 @@ function newRelease (tag = null, date = new Date().toISOString()) {
}

function filterCommit (commit, release, limit) {
if (commit.breaking) {
return true
}
if (semver.valid(commit.subject)) {
// Filter out version commits
return false
Expand Down Expand Up @@ -86,5 +89,7 @@ function getCompareLink (from, to, remote) {
}

function sortCommits (a, b) {
if (!a.breaking && b.breaking) return -1
if (a.breaking && !b.breaking) return 1
return (b.insertions + b.deletions) - (a.insertions + a.deletions)
}
1 change: 1 addition & 0 deletions src/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function getOptions (argv, pkg) {
.option('-l, --commit-limit [count]', `number of commits to display per release, default: ${DEFAULT_OPTIONS.commitLimit}`, parseLimit)
.option('-i, --issue-url [url]', `override url for issues, use {id} for issue id`)
.option('--issue-pattern [regex]', `override regex pattern for issues in commit messages`)
.option('--breaking-pattern [regex]', `regex pattern for breaking change commits`)
.option('--ignore-commit-pattern [regex]', `pattern to ignore when parsing commits`)
.option('--starting-commit [hash]', `starting commit to use for changelog generation`)
.option('--tag-prefix [prefix]', `prefix used in version tags`)
Expand Down
2 changes: 1 addition & 1 deletion templates/compact.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).
- {{commit.subject}}{{#each fixes}}{{#if href}} [`#{{id}}`]({{href}}){{/if}}{{/each}}
{{/each}}
{{#each commits}}
- {{subject}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
- {{#if breaking}}**Breaking change:** {{/if}}{{subject}}{{#if href}} [`{{shorthash}}`]({{href}}){{/if}}
{{/each}}

{{/each}}
2 changes: 1 addition & 1 deletion templates/keepachangelog.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog).

{{/if}}
{{#commit-list commits heading='### Commits'}}
- {{subject}} {{#if href}}[`{{shorthash}}`]({{href}}){{/if}}
- {{#if breaking}}**Breaking change:** {{/if}}{{subject}} {{#if href}}[`{{shorthash}}`]({{href}}){{/if}}
{{/commit-list}}

{{/each}}
7 changes: 7 additions & 0 deletions test/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ describe('parseCommits', () => {
expect(JSON.stringify(result)).to.not.contain('Second commit')
})

it('supports breakingPattern option', async () => {
const gitLog = await readFile(join(__dirname, 'data', 'git-log.txt'), 'utf-8')
const options = { breakingPattern: 'Some breaking change' }
const result = parseCommits(gitLog, remotes.github, options)
expect(result.filter(c => c.breaking)).to.have.length(1)
})

it('invalid startingCommit throws an error', done => {
const options = { startingCommit: 'not-a-hash' }
readFile(join(__dirname, 'data', 'git-log.txt'), 'utf-8')
Expand Down
19 changes: 17 additions & 2 deletions test/data/commits-no-remote.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default [
],
"merge": null,
"href": null,
"breaking": false,
"files": 5,
"insertions": 10,
"deletions": 10
Expand All @@ -32,6 +33,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -48,6 +50,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 5,
"insertions": 10,
"deletions": 10
Expand All @@ -64,6 +67,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -80,6 +84,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 1
Expand All @@ -96,6 +101,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 1,
"insertions": 2,
"deletions": 3
Expand All @@ -112,6 +118,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -131,7 +138,8 @@ export default [
"message": "Should not parse #4 in PR title",
"href": null
},
"href": null
"href": null,
"breaking": false
},
{
"hash": "92839699a6aaea148dcd72ea897321e66cae0c18",
Expand All @@ -145,6 +153,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 0
Expand All @@ -166,6 +175,7 @@ export default [
],
"merge": null,
"href": null,
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 0
Expand All @@ -182,6 +192,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -201,7 +212,8 @@ export default [
"message": "Third commit with same name as PR",
"href": null
},
"href": null
"href": null,
"breaking": false
},
{
"hash": "1c2694e44a032d2ab6d6eaa381beaf23ba3d9573",
Expand All @@ -215,6 +227,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 8,
"insertions": 57,
"deletions": 53
Expand All @@ -240,6 +253,7 @@ export default [
],
"merge": null,
"href": null,
"breaking": false,
"files": 8,
"insertions": 57,
"deletions": 53
Expand All @@ -256,6 +270,7 @@ export default [
"fixes": null,
"merge": null,
"href": null,
"breaking": false,
"files": 7,
"insertions": 37,
"deletions": 22
Expand Down
19 changes: 17 additions & 2 deletions test/data/commits.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export default [
],
"merge": null,
"href": "https://github.com/user/repo/commit/2401ee4706e94629f48830bab9ed5812c032734a",
"breaking": false,
"files": 5,
"insertions": 10,
"deletions": 10
Expand All @@ -32,6 +33,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/77bb243170408cd18e70ca05bf8b3ca7646ea437",
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -48,6 +50,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/b0b304049847d9568585bc11399fa6cfa4cab5dc",
"breaking": false,
"files": 5,
"insertions": 10,
"deletions": 10
Expand All @@ -64,6 +67,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/db92947e6129cc20cd7777b7ed90b2bd547918c0",
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -80,6 +84,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/e9a43b2bf50449fc0d84465308e6008cc1597bb3",
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 1
Expand All @@ -96,6 +101,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/12c0624e7e419a70bd5f3b403d7e0bd8f23ec617",
"breaking": false,
"files": 1,
"insertions": 2,
"deletions": 3
Expand All @@ -112,6 +118,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/ef17dcc732d282f027aa3bddf8f91cbb05998cc8",
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -131,7 +138,8 @@ export default [
"message": "Should not parse #4 in PR title",
"href": "https://github.com/user/repo/pull/5"
},
"href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672"
"href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672",
"breaking": false
},
{
"hash": "92839699a6aaea148dcd72ea897321e66cae0c18",
Expand All @@ -145,6 +153,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/92839699a6aaea148dcd72ea897321e66cae0c18",
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 0
Expand All @@ -166,6 +175,7 @@ export default [
],
"merge": null,
"href": "https://github.com/user/repo/commit/17fbef87e82889f01d8257900f7edc55b05918a2",
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 0
Expand All @@ -182,6 +192,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/796edd129a6aaea148dcd72ea897321e66cae0c1",
"breaking": false,
"files": 2,
"insertions": 8,
"deletions": 2
Expand All @@ -201,7 +212,8 @@ export default [
"message": "Third commit with same name as PR",
"href": "https://github.com/user/repo/pull/3"
},
"href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3"
"href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3",
"breaking": false
},
{
"hash": "1c2694e44a032d2ab6d6eaa381beaf23ba3d9573",
Expand All @@ -215,6 +227,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/1c2694e44a032d2ab6d6eaa381beaf23ba3d9573",
"breaking": false,
"files": 8,
"insertions": 57,
"deletions": 53
Expand All @@ -240,6 +253,7 @@ export default [
],
"merge": null,
"href": "https://github.com/user/repo/commit/90ef33485369fc7892d11b2e4da04ffb64df1e99",
"breaking": false,
"files": 8,
"insertions": 57,
"deletions": 53
Expand All @@ -256,6 +270,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69",
"breaking": false,
"files": 7,
"insertions": 37,
"deletions": 22
Expand Down
6 changes: 6 additions & 0 deletions test/data/releases.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/b0b304049847d9568585bc11399fa6cfa4cab5dc",
"breaking": false,
"files": 5,
"insertions": 10,
"deletions": 10
Expand Down Expand Up @@ -42,6 +43,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/12c0624e7e419a70bd5f3b403d7e0bd8f23ec617",
"breaking": false,
"files": 1,
"insertions": 2,
"deletions": 3
Expand All @@ -58,6 +60,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/e9a43b2bf50449fc0d84465308e6008cc1597bb3",
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 1
Expand Down Expand Up @@ -100,6 +103,7 @@ export default [
],
"merge": null,
"href": "https://github.com/user/repo/commit/17fbef87e82889f01d8257900f7edc55b05918a2",
"breaking": false,
"files": 1,
"insertions": 1,
"deletions": 0
Expand Down Expand Up @@ -135,6 +139,7 @@ export default [
"fixes": null,
"merge": null,
"href": "https://github.com/user/repo/commit/158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69",
"breaking": false,
"files": 7,
"insertions": 37,
"deletions": 22
Expand Down Expand Up @@ -173,6 +178,7 @@ export default [
],
"merge": null,
"href": "https://github.com/user/repo/commit/90ef33485369fc7892d11b2e4da04ffb64df1e99",
"breaking": false,
"files": 8,
"insertions": 57,
"deletions": 53
Expand Down
Loading

0 comments on commit 68b93e0

Please sign in to comment.