From 5b0c44cc76147729b077df4eb4159df7eda0ebaa Mon Sep 17 00:00:00 2001 From: Pete Cook Date: Tue, 2 Oct 2018 15:39:15 +0100 Subject: [PATCH] Add author to fixes and merges Fixes https://github.com/CookPete/auto-changelog/issues/58 --- src/commits.js | 13 ++--- test/commits.js | 97 ++++++++++++++++++---------------- test/data/commits-no-remote.js | 18 ++++--- test/data/commits.js | 18 ++++--- test/data/releases.js | 24 ++++++--- test/data/template-json.json | 24 ++++++--- 6 files changed, 115 insertions(+), 79 deletions(-) diff --git a/src/commits.js b/src/commits.js index 463be56f..88eefc33 100644 --- a/src/commits.js +++ b/src/commits.js @@ -66,8 +66,8 @@ function parseCommit (commit, remote, options = {}) { tag: getTag(refs, options), subject: replaceText(getSubject(message), options), message: message.trim(), - fixes: getFixes(message, remote, options), - merge: getMerge(message, remote, options), + fixes: getFixes(message, author, remote, options), + merge: getMerge(message, author, remote, options), href: getCommitLink(hash, remote), breaking: !!options.breakingPattern && new RegExp(options.breakingPattern).test(message), ...getStats(stats.trim()) @@ -105,7 +105,7 @@ function getStats (stats) { } } -function getFixes (message, remote, options = {}) { +function getFixes (message, author, remote, options = {}) { const pattern = getFixPattern(options) let fixes = [] let match = pattern.exec(message) @@ -113,7 +113,7 @@ function getFixes (message, remote, options = {}) { while (match) { const id = getFixID(match) const href = getIssueLink(match, id, remote, options.issueUrl) - fixes.push({ id, href }) + fixes.push({ id, href, author }) match = pattern.exec(message) } return fixes @@ -135,7 +135,7 @@ function getFixPattern (options) { return DEFAULT_FIX_PATTERN } -function getMerge (message, remote, options = {}) { +function getMerge (message, author, remote, options = {}) { for (let pattern of MERGE_PATTERNS) { const match = message.match(pattern) if (match) { @@ -144,7 +144,8 @@ function getMerge (message, remote, options = {}) { return { id, message: replaceText(message, options), - href: getMergeLink(id, remote) + href: getMergeLink(id, remote), + author } } } diff --git a/test/commits.js b/test/commits.js index 56c3098f..6473e651 100644 --- a/test/commits.js +++ b/test/commits.js @@ -92,73 +92,73 @@ describe('parseCommits', () => { describe('getFixes', () => { it('returns null with no fixes', () => { const message = 'Commit message with no fixes' - expect(getFixes(message, remotes.github)).to.equal(null) + expect(getFixes(message, 'Commit Author', remotes.github)).to.equal(null) }) it('parses a single fix', () => { const message = 'Commit that fixes #12' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '12', href: 'https://github.com/user/repo/issues/12' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '12', href: 'https://github.com/user/repo/issues/12', author: 'Commit Author' } ]) }) it('parses fix in commit notes', () => { const message = 'Commit message\n\nCloses #8' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '8', href: 'https://github.com/user/repo/issues/8' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '8', href: 'https://github.com/user/repo/issues/8', author: 'Commit Author' } ]) }) it('parses a commit that closes a pull request', () => { const message = 'Commit message\n\nCloses https://github.com/user/repo/pull/14' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '14', href: 'https://github.com/user/repo/pull/14' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '14', href: 'https://github.com/user/repo/pull/14', author: 'Commit Author' } ]) }) it('parses a commit that closes a bitbucket pull request', () => { const message = 'Commit message\n\nCloses https://github.com/user/repo/pull-requests/14' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '14', href: 'https://github.com/user/repo/pull-requests/14' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '14', href: 'https://github.com/user/repo/pull-requests/14', author: 'Commit Author' } ]) }) it('parses a commit that closes a gitlab pull request', () => { const message = 'Commit message\n\nCloses https://github.com/user/repo/merge_requests/14' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '14', href: 'https://github.com/user/repo/merge_requests/14' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '14', href: 'https://github.com/user/repo/merge_requests/14', author: 'Commit Author' } ]) }) it('parses multiple fixes', () => { const message = 'Commit message\n\nFixes #1, fix #2, resolved #3, closes #4' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '1', href: 'https://github.com/user/repo/issues/1' }, - { id: '2', href: 'https://github.com/user/repo/issues/2' }, - { id: '3', href: 'https://github.com/user/repo/issues/3' }, - { id: '4', href: 'https://github.com/user/repo/issues/4' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '1', href: 'https://github.com/user/repo/issues/1', author: 'Commit Author' }, + { id: '2', href: 'https://github.com/user/repo/issues/2', author: 'Commit Author' }, + { id: '3', href: 'https://github.com/user/repo/issues/3', author: 'Commit Author' }, + { id: '4', href: 'https://github.com/user/repo/issues/4', author: 'Commit Author' } ]) }) it('parses fixes by issue URL', () => { const message = 'Commit message\n\nFixes https://github.com/user/repo/issues/1' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '1', href: 'https://github.com/user/repo/issues/1' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '1', href: 'https://github.com/user/repo/issues/1', author: 'Commit Author' } ]) }) it('parses multiple fixes by issue URL', () => { const message = 'Commit message\n\nFixes https://github.com/user/repo/issues/1 and fixes https://github.com/user/repo/issues/2' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '1', href: 'https://github.com/user/repo/issues/1' }, - { id: '2', href: 'https://github.com/user/repo/issues/2' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '1', href: 'https://github.com/user/repo/issues/1', author: 'Commit Author' }, + { id: '2', href: 'https://github.com/user/repo/issues/2', author: 'Commit Author' } ]) }) it('parses external repo issues', () => { const message = 'Commit message\n\nFixes https://github.com/other-user/external-repo/issues/1' - expect(getFixes(message, remotes.github)).to.deep.equal([ - { id: '1', href: 'https://github.com/other-user/external-repo/issues/1' } + expect(getFixes(message, 'Commit Author', remotes.github)).to.deep.equal([ + { id: '1', href: 'https://github.com/other-user/external-repo/issues/1', author: 'Commit Author' } ]) }) @@ -167,8 +167,8 @@ describe('getFixes', () => { issueUrl: 'http://example.com/issues/{id}' } const message = 'Commit message\n\nCloses #8' - expect(getFixes(message, remotes.github, options)).to.deep.equal([ - { id: '8', href: 'http://example.com/issues/8' } + expect(getFixes(message, 'Commit Author', remotes.github, options)).to.deep.equal([ + { id: '8', href: 'http://example.com/issues/8', author: 'Commit Author' } ]) }) @@ -178,8 +178,8 @@ describe('getFixes', () => { issueUrl: 'http://example.com/issues/{id}' } const message = 'Commit message\n\nCloses ABC-1234' - expect(getFixes(message, remotes.github, options)).to.deep.equal([ - { id: 'ABC-1234', href: 'http://example.com/issues/ABC-1234' } + expect(getFixes(message, 'Commit Author', remotes.github, options)).to.deep.equal([ + { id: 'ABC-1234', href: 'http://example.com/issues/ABC-1234', author: 'Commit Author' } ]) }) @@ -189,9 +189,9 @@ describe('getFixes', () => { issueUrl: 'http://example.com/issues/{id}' } const message = 'Commit message\n\nFixes ABC-1234 and fixes ABC-2345 but not BCD-2345' - expect(getFixes(message, remotes.github, options)).to.deep.equal([ - { id: 'ABC-1234', href: 'http://example.com/issues/ABC-1234' }, - { id: 'ABC-2345', href: 'http://example.com/issues/ABC-2345' } + expect(getFixes(message, 'Commit Author', remotes.github, options)).to.deep.equal([ + { id: 'ABC-1234', href: 'http://example.com/issues/ABC-1234', author: 'Commit Author' }, + { id: 'ABC-2345', href: 'http://example.com/issues/ABC-2345', author: 'Commit Author' } ]) }) }) @@ -199,34 +199,37 @@ describe('getFixes', () => { describe('getMerge', () => { it('returns null on fail', () => { const message = 'Not a merge commit' - expect(getMerge(message, remotes.github)).to.equal(null) + expect(getMerge(message, 'Commit Author', remotes.github)).to.equal(null) }) describe('GitHub', () => { it('parses a merge', () => { const message = 'Merge pull request #3 from repo/branch\n\nPull request title' - expect(getMerge(message, remotes.github)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.github)).to.deep.equal({ id: '3', message: 'Pull request title', - href: 'https://github.com/user/repo/pull/3' + href: 'https://github.com/user/repo/pull/3', + author: 'Commit Author' }) }) it('parses a squash merge', () => { const message = 'Update dependencies to enable Greenkeeper 🌴 (#10)\n\n* chore(package): update dependencies' - expect(getMerge(message, remotes.github)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.github)).to.deep.equal({ id: '10', message: 'Update dependencies to enable Greenkeeper 🌴', - href: 'https://github.com/user/repo/pull/10' + href: 'https://github.com/user/repo/pull/10', + author: 'Commit Author' }) }) it('parses a squash merge with no message', () => { const message = 'Generate changelogs that show the commits between tags (#411)' - expect(getMerge(message, remotes.github)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.github)).to.deep.equal({ id: '411', message: 'Generate changelogs that show the commits between tags', - href: 'https://github.com/user/repo/pull/411' + href: 'https://github.com/user/repo/pull/411', + author: 'Commit Author' }) }) }) @@ -234,10 +237,11 @@ describe('getMerge', () => { describe('GitLab', () => { it('parses a merge', () => { const message = 'Merge branch \'branch\' into \'master\'\n\nMemoize GitLab logger to reduce open file descriptors\n\nCloses gitlab-ee#3664\n\nSee merge request !15007' - expect(getMerge(message, remotes.gitlab)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.gitlab)).to.deep.equal({ id: '15007', message: 'Memoize GitLab logger to reduce open file descriptors', - href: 'https://gitlab.com/user/repo/merge_requests/15007' + href: 'https://gitlab.com/user/repo/merge_requests/15007', + author: 'Commit Author' }) }) @@ -247,10 +251,11 @@ describe('getMerge', () => { hostname: 'gitlab.com', url: 'https://gitlab.com/user/repo/subgroup' } - expect(getMerge(message, remote)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remote)).to.deep.equal({ id: '15007', message: 'Memoize GitLab logger to reduce open file descriptors', - href: 'https://gitlab.com/user/repo/subgroup/merge_requests/15007' + href: 'https://gitlab.com/user/repo/subgroup/merge_requests/15007', + author: 'Commit Author' }) }) }) @@ -258,10 +263,11 @@ describe('getMerge', () => { describe('BitBucket', () => { it('parses a merge', () => { const message = 'Merged in eshvedai/fix-schema-issue (pull request #4518)\n\nfix(component): re-export createSchema from editor-core\n\nApproved-by: Scott Sidwell ' - expect(getMerge(message, remotes.bitbucket)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.bitbucket)).to.deep.equal({ id: '4518', message: 'fix(component): re-export createSchema from editor-core', - href: 'https://bitbucket.org/user/repo/pull-requests/4518' + href: 'https://bitbucket.org/user/repo/pull-requests/4518', + author: 'Commit Author' }) }) }) @@ -273,10 +279,11 @@ describe('getMerge', () => { '(..l)': '_$1_' } } - expect(getMerge(message, remotes.github, options)).to.deep.equal({ + expect(getMerge(message, 'Commit Author', remotes.github, options)).to.deep.equal({ id: '3', message: '_Pul_l request t_itl_e', - href: 'https://github.com/user/repo/pull/3' + href: 'https://github.com/user/repo/pull/3', + author: 'Commit Author' }) }) }) diff --git a/test/data/commits-no-remote.js b/test/data/commits-no-remote.js index 380c78c3..3c0fb97f 100644 --- a/test/data/commits-no-remote.js +++ b/test/data/commits-no-remote.js @@ -11,7 +11,8 @@ export default [ "fixes": [ { "id": "6", - "href": null + "href": null, + "author": "Pete Cook" } ], "merge": null, @@ -136,7 +137,8 @@ export default [ "merge": { "id": "5", "message": "Should not parse #4 in PR title", - "href": null + "href": null, + "author": "Pete Cook" }, "href": null, "breaking": false @@ -170,7 +172,8 @@ export default [ "fixes": [ { "id": "4", - "href": null + "href": null, + "author": "Pete Cook" } ], "merge": null, @@ -210,7 +213,8 @@ export default [ "merge": { "id": "3", "message": "Third commit with same name as PR", - "href": null + "href": null, + "author": "Pete Cook" }, "href": null, "breaking": false @@ -244,11 +248,13 @@ export default [ "fixes": [ { "id": "1", - "href": null + "href": null, + "author": "Pete Cook" }, { "id": "2", - "href": null + "href": null, + "author": "Pete Cook" } ], "merge": null, diff --git a/test/data/commits.js b/test/data/commits.js index 99b459da..1d545798 100644 --- a/test/data/commits.js +++ b/test/data/commits.js @@ -11,7 +11,8 @@ export default [ "fixes": [ { "id": "6", - "href": "https://github.com/user/repo/issues/6" + "href": "https://github.com/user/repo/issues/6", + "author": "Pete Cook" } ], "merge": null, @@ -136,7 +137,8 @@ export default [ "merge": { "id": "5", "message": "Should not parse #4 in PR title", - "href": "https://github.com/user/repo/pull/5" + "href": "https://github.com/user/repo/pull/5", + "author": "Pete Cook" }, "href": "https://github.com/user/repo/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", "breaking": false @@ -170,7 +172,8 @@ export default [ "fixes": [ { "id": "4", - "href": "https://github.com/user/repo/issues/4" + "href": "https://github.com/user/repo/issues/4", + "author": "Pete Cook" } ], "merge": null, @@ -210,7 +213,8 @@ export default [ "merge": { "id": "3", "message": "Third commit with same name as PR", - "href": "https://github.com/user/repo/pull/3" + "href": "https://github.com/user/repo/pull/3", + "author": "Pete Cook" }, "href": "https://github.com/user/repo/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", "breaking": false @@ -244,11 +248,13 @@ export default [ "fixes": [ { "id": "1", - "href": "https://github.com/user/repo/issues/1" + "href": "https://github.com/user/repo/issues/1", + "author": "Pete Cook" }, { "id": "2", - "href": "https://github.com/user/repo/issues/2" + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" } ], "merge": null, diff --git a/test/data/releases.js b/test/data/releases.js index 12264d8a..42c62da3 100644 --- a/test/data/releases.js +++ b/test/data/releases.js @@ -83,7 +83,8 @@ export default [ "fixes": [ { "id": "4", - "href": "https://github.com/user/repo/issues/4" + "href": "https://github.com/user/repo/issues/4", + "author": "Pete Cook" } ], "commit": { @@ -98,7 +99,8 @@ export default [ "fixes": [ { "id": "4", - "href": "https://github.com/user/repo/issues/4" + "href": "https://github.com/user/repo/issues/4", + "author": "Pete Cook" } ], "merge": null, @@ -114,7 +116,8 @@ export default [ { "id": "5", "message": "Should not parse #4 in PR title", - "href": "https://github.com/user/repo/pull/5" + "href": "https://github.com/user/repo/pull/5", + "author": "Pete Cook" } ], "tag": "v0.0.2", @@ -150,11 +153,13 @@ export default [ "fixes": [ { "id": "1", - "href": "https://github.com/user/repo/issues/1" + "href": "https://github.com/user/repo/issues/1", + "author": "Pete Cook" }, { "id": "2", - "href": "https://github.com/user/repo/issues/2" + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" } ], "commit": { @@ -169,11 +174,13 @@ export default [ "fixes": [ { "id": "1", - "href": "https://github.com/user/repo/issues/1" + "href": "https://github.com/user/repo/issues/1", + "author": "Pete Cook" }, { "id": "2", - "href": "https://github.com/user/repo/issues/2" + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" } ], "merge": null, @@ -189,7 +196,8 @@ export default [ { "id": "3", "message": "Third commit with same name as PR", - "href": "https://github.com/user/repo/pull/3" + "href": "https://github.com/user/repo/pull/3", + "author": "Pete Cook" } ], "tag": "v0.0.1", diff --git a/test/data/template-json.json b/test/data/template-json.json index 228c2bd6..d596800c 100644 --- a/test/data/template-json.json +++ b/test/data/template-json.json @@ -83,7 +83,8 @@ "fixes": [ { "id": "4", - "href": "https://github.com/user/repo/issues/4" + "href": "https://github.com/user/repo/issues/4", + "author": "Pete Cook" } ], "commit": { @@ -98,7 +99,8 @@ "fixes": [ { "id": "4", - "href": "https://github.com/user/repo/issues/4" + "href": "https://github.com/user/repo/issues/4", + "author": "Pete Cook" } ], "merge": null, @@ -114,7 +116,8 @@ { "id": "5", "message": "Should not parse #4 in PR title", - "href": "https://github.com/user/repo/pull/5" + "href": "https://github.com/user/repo/pull/5", + "author": "Pete Cook" } ], "tag": "v0.0.2", @@ -150,11 +153,13 @@ "fixes": [ { "id": "1", - "href": "https://github.com/user/repo/issues/1" + "href": "https://github.com/user/repo/issues/1", + "author": "Pete Cook" }, { "id": "2", - "href": "https://github.com/user/repo/issues/2" + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" } ], "commit": { @@ -169,11 +174,13 @@ "fixes": [ { "id": "1", - "href": "https://github.com/user/repo/issues/1" + "href": "https://github.com/user/repo/issues/1", + "author": "Pete Cook" }, { "id": "2", - "href": "https://github.com/user/repo/issues/2" + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" } ], "merge": null, @@ -189,7 +196,8 @@ { "id": "3", "message": "Third commit with same name as PR", - "href": "https://github.com/user/repo/pull/3" + "href": "https://github.com/user/repo/pull/3", + "author": "Pete Cook" } ], "tag": "v0.0.1",