From bc31d42576cf7eb0d295d24ef454a9b4602caeb4 Mon Sep 17 00:00:00 2001 From: Romain DAZY Date: Fri, 27 Sep 2019 23:26:45 +0200 Subject: [PATCH] Use = and & in compare URLs ( #131) --- scripts/generate-test-data.js | 4 + src/template.js | 3 + test/data/commits-bitbucket-corporate.js | 310 ++++++++++++++++++ test/data/remotes.js | 3 + .../template-compact-bitbucket-corporate.md | 33 ++ test/releases.js | 5 + test/remote.js | 9 + test/run.js | 14 + 8 files changed, 381 insertions(+) create mode 100644 test/data/commits-bitbucket-corporate.js create mode 100644 test/data/template-compact-bitbucket-corporate.md diff --git a/scripts/generate-test-data.js b/scripts/generate-test-data.js index 7760e213..1701f216 100644 --- a/scripts/generate-test-data.js +++ b/scripts/generate-test-data.js @@ -30,13 +30,17 @@ async function run () { const releases = parseReleases(commits, remotes.github, null, options) const commitsNoRemote = parseCommits(gitLog, remotes.null, options) const releasesNoRemote = parseReleases(commitsNoRemote, remotes.null, null, options) + const commitsBitbucketCorporate = parseCommits(gitLog, remotes.bitbucketCorporate, options) + const releasesBitbucketCorporate = parseReleases(commitsBitbucketCorporate, remotes.bitbucketCorporate, null, options) await writeObject('commits.js', commits) await writeObject('commits-no-remote.js', commitsNoRemote) + await writeObject('commits-bitbucket-corporate.js', commitsBitbucketCorporate) await writeObject('releases.js', releases) await writeTemplate('template-compact.md', 'compact', releases) await writeTemplate('template-keepachangelog.md', 'keepachangelog', releases) await writeTemplate('template-json.json', 'json', releases) await writeTemplate('template-compact-no-remote.md', 'compact', releasesNoRemote) + await writeTemplate('template-compact-bitbucket-corporate.md', 'compact', releasesBitbucketCorporate) } run().catch(e => console.error(e)) diff --git a/src/template.js b/src/template.js index 238c0a55..3cfb3ee6 100644 --- a/src/template.js +++ b/src/template.js @@ -71,6 +71,9 @@ function cleanTemplate (template) { // Fix multiple blank lines .replace(/\n\n\n+/g, '\n\n') .replace(/\n\n$/, '\n') + // Fix release comparison URLs for corporate Bitbucket servers + .replace(/=/g, '=') + .replace(/&/g, '&') } export async function compileTemplate ({ template, handlebarsSetup }, data) { diff --git a/test/data/commits-bitbucket-corporate.js b/test/data/commits-bitbucket-corporate.js new file mode 100644 index 00000000..ac2371a4 --- /dev/null +++ b/test/data/commits-bitbucket-corporate.js @@ -0,0 +1,310 @@ +export default [ + { + "hash": "2401ee4706e94629f48830bab9ed5812c032734a", + "shorthash": "2401ee4", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T21:57:19.000Z", + "tag": null, + "subject": "Unreleased commit", + "message": "Unreleased commit\n\nFixes #6", + "fixes": [ + { + "id": "6", + "href": "https://example.com/git/users/issues/6", + "author": "Pete Cook" + } + ], + "href": "https://example.com/git/users/commit/2401ee4706e94629f48830bab9ed5812c032734a", + "breaking": false, + "files": 5, + "insertions": 10, + "deletions": 10, + "merge": null + }, + { + "hash": "77bb243170408cd18e70ca05bf8b3ca7646ea437", + "shorthash": "77bb243", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T12:03:09.000Z", + "tag": "v1.0.0", + "subject": "1.0.0", + "message": "1.0.0\n\nThis is my major release description.\n\n- And a bullet point", + "fixes": null, + "href": "https://example.com/git/users/commit/77bb243170408cd18e70ca05bf8b3ca7646ea437", + "breaking": false, + "files": 2, + "insertions": 8, + "deletions": 2, + "merge": null + }, + { + "hash": "b0b304049847d9568585bc11399fa6cfa4cab5dc", + "shorthash": "b0b3040", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T21:57:19.000Z", + "tag": null, + "subject": "Some breaking change", + "message": "Some breaking change", + "fixes": null, + "href": "https://example.com/git/users/commit/b0b304049847d9568585bc11399fa6cfa4cab5dc", + "breaking": false, + "files": 5, + "insertions": 10, + "deletions": 10, + "merge": null + }, + { + "hash": "db92947e6129cc20cd7777b7ed90b2bd547918c0", + "shorthash": "db92947", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T21:19:17.000Z", + "tag": "v0.1.0", + "subject": "0.1.0", + "message": "0.1.0", + "fixes": null, + "href": "https://example.com/git/users/commit/db92947e6129cc20cd7777b7ed90b2bd547918c0", + "breaking": false, + "files": 2, + "insertions": 8, + "deletions": 2, + "merge": null + }, + { + "hash": "e9a43b2bf50449fc0d84465308e6008cc1597bb3", + "shorthash": "e9a43b2", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T21:19:19.000Z", + "tag": null, + "subject": "Another commit that fixes nothing but with less changes", + "message": "Another commit that fixes nothing but with less changes", + "fixes": null, + "href": "https://example.com/git/users/commit/e9a43b2bf50449fc0d84465308e6008cc1597bb3", + "breaking": false, + "files": 1, + "insertions": 1, + "deletions": 1, + "merge": null + }, + { + "hash": "12c0624e7e419a70bd5f3b403d7e0bd8f23ec617", + "shorthash": "12c0624", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T21:18:19.000Z", + "tag": null, + "subject": "Commit that fixes nothing with `backticks` and <html>", + "message": "Commit that fixes nothing with `backticks` and <html>", + "fixes": null, + "href": "https://example.com/git/users/commit/12c0624e7e419a70bd5f3b403d7e0bd8f23ec617", + "breaking": false, + "files": 1, + "insertions": 2, + "deletions": 3, + "merge": null + }, + { + "hash": "ef17dcc732d282f027aa3bddf8f91cbb05998cc8", + "shorthash": "ef17dcc", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-28T21:17:17.000Z", + "tag": "v0.0.2", + "subject": "0.0.2", + "message": "0.0.2", + "fixes": null, + "href": "https://example.com/git/users/commit/ef17dcc732d282f027aa3bddf8f91cbb05998cc8", + "breaking": false, + "files": 2, + "insertions": 8, + "deletions": 2, + "merge": null + }, + { + "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", + "shorthash": "0e24bf4", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-24T20:29:22.000Z", + "tag": null, + "subject": "Merge pull request #5 from repo/branch", + "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", + "fixes": null, + "href": "https://example.com/git/users/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", + "breaking": false, + "merge": { + "id": "5", + "message": "Should not parse #4 in PR title", + "href": "https://example.com/git/users/pull/5", + "author": "Pete Cook", + "commit": { + "hash": "0e24bf427a51eac52133cc731b4b5d74a7e04672", + "shorthash": "0e24bf4", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-24T20:29:22.000Z", + "tag": null, + "subject": "Merge pull request #5 from repo/branch", + "message": "Merge pull request #5 from repo/branch\n\nShould not parse #4 in PR title", + "fixes": null, + "href": "https://example.com/git/users/commit/0e24bf427a51eac52133cc731b4b5d74a7e04672", + "breaking": false + } + } + }, + { + "hash": "92839699a6aaea148dcd72ea897321e66cae0c18", + "shorthash": "9283969", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-29T11:35:54.000Z", + "tag": null, + "subject": "Merge remote-tracking branch 'random-branch' into master", + "message": "Merge remote-tracking branch 'random-branch' into master", + "fixes": null, + "href": "https://example.com/git/users/commit/92839699a6aaea148dcd72ea897321e66cae0c18", + "breaking": false, + "files": 1, + "insertions": 1, + "deletions": 0, + "merge": null + }, + { + "hash": "17fbef87e82889f01d8257900f7edc55b05918a2", + "shorthash": "17fbef8", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-28T11:35:54.000Z", + "tag": null, + "subject": "Commit 4 fixes #4 in the subject", + "message": "Commit 4 fixes #4 in the subject\n\nWith some extra notes here", + "fixes": [ + { + "id": "4", + "href": "https://example.com/git/users/issues/4", + "author": "Pete Cook" + } + ], + "href": "https://example.com/git/users/commit/17fbef87e82889f01d8257900f7edc55b05918a2", + "breaking": false, + "files": 1, + "insertions": 1, + "deletions": 0, + "merge": null + }, + { + "hash": "796edd129a6aaea148dcd72ea897321e66cae0c1", + "shorthash": "796edd1", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T12:03:09.000Z", + "tag": "v0.0.1", + "subject": "0.0.1", + "message": "0.0.1", + "fixes": null, + "href": "https://example.com/git/users/commit/796edd129a6aaea148dcd72ea897321e66cae0c1", + "breaking": false, + "files": 2, + "insertions": 8, + "deletions": 2, + "merge": null + }, + { + "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", + "shorthash": "31b7d3d", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:37:05.000Z", + "tag": null, + "subject": "Merge pull request #3 from repo/branch", + "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", + "fixes": null, + "href": "https://example.com/git/users/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", + "breaking": false, + "merge": { + "id": "3", + "message": "Third commit with same name as PR", + "href": "https://example.com/git/users/pull/3", + "author": "Pete Cook", + "commit": { + "hash": "31b7d3da24d64e32a0a7e558f254d01c348613f3", + "shorthash": "31b7d3d", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:37:05.000Z", + "tag": null, + "subject": "Merge pull request #3 from repo/branch", + "message": "Merge pull request #3 from repo/branch\n\nThird commit with same name as PR", + "fixes": null, + "href": "https://example.com/git/users/commit/31b7d3da24d64e32a0a7e558f254d01c348613f3", + "breaking": false + } + } + }, + { + "hash": "1c2694e44a032d2ab6d6eaa381beaf23ba3d9573", + "shorthash": "1c2694e", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:31:06.000Z", + "tag": null, + "subject": "Third commit with same name as PR", + "message": "Third commit with same name as PR", + "fixes": null, + "href": "https://example.com/git/users/commit/1c2694e44a032d2ab6d6eaa381beaf23ba3d9573", + "breaking": false, + "files": 8, + "insertions": 57, + "deletions": 53, + "merge": null + }, + { + "hash": "90ef33485369fc7892d11b2e4da04ffb64df1e99", + "shorthash": "90ef334", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-15T11:31:06.000Z", + "tag": null, + "subject": "Second commit", + "message": "Second commit\n\nResolves #1 and fixes https://github.com/user/repo/issues/2", + "fixes": [ + { + "id": "1", + "href": "https://example.com/git/users/issues/1", + "author": "Pete Cook" + }, + { + "id": "2", + "href": "https://github.com/user/repo/issues/2", + "author": "Pete Cook" + } + ], + "href": "https://example.com/git/users/commit/90ef33485369fc7892d11b2e4da04ffb64df1e99", + "breaking": false, + "files": 8, + "insertions": 57, + "deletions": 53, + "merge": null + }, + { + "hash": "158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69", + "shorthash": "158fdde", + "author": "Pete Cook", + "email": "email@example.com", + "date": "2015-12-14T17:06:12.000Z", + "tag": null, + "subject": "First commit", + "message": "First commit", + "fixes": null, + "href": "https://example.com/git/users/commit/158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69", + "breaking": false, + "files": 7, + "insertions": 37, + "deletions": 22, + "merge": null + } +] diff --git a/test/data/remotes.js b/test/data/remotes.js index ba3e0ea0..6a2ea642 100644 --- a/test/data/remotes.js +++ b/test/data/remotes.js @@ -7,6 +7,9 @@ export default { gitlab: getRemote('https://gitlab.com/user/repo'), gitlabSubgroup: getRemote('https://gitlab.com/user/repo/subgroup.git'), bitbucket: getRemote('https://bitbucket.org/user/repo'), + bitbucketCorporate: getRemote('https://example.com/git/users/user/repos/repo',{ + compareUrl: 'https://example.com/git/users/user/repos/repo/compare/commits?targetBranch=refs/heads/{from}&sourceBranch=refs/heads/{to}' + }), azure: getRemote('https://dev.azure.com/user/project/_git/repo'), visualstudio: getRemote('https://user.visualstudio.com/project/_git/repo') } diff --git a/test/data/template-compact-bitbucket-corporate.md b/test/data/template-compact-bitbucket-corporate.md new file mode 100644 index 00000000..e2392c9c --- /dev/null +++ b/test/data/template-compact-bitbucket-corporate.md @@ -0,0 +1,33 @@ +### Changelog + +All notable changes to this project will be documented in this file. Dates are displayed in UTC. + +Generated by [`auto-changelog`](https://github.com/CookPete/auto-changelog). + +### [v1.0.0](https://example.com/git/users/user/repos/repo/compare/commits?targetBranch=refs/heads/v0.1.0&sourceBranch=refs/heads/v1.0.0) + +> 15 December 2015 + +- Some breaking change [`b0b3040`](https://example.com/git/users/commit/b0b304049847d9568585bc11399fa6cfa4cab5dc) + +#### [v0.1.0](https://example.com/git/users/user/repos/repo/compare/commits?targetBranch=refs/heads/v0.0.2&sourceBranch=refs/heads/v0.1.0) + +> 29 December 2015 + +- Commit that fixes nothing with `backticks` and <html> [`12c0624`](https://example.com/git/users/commit/12c0624e7e419a70bd5f3b403d7e0bd8f23ec617) +- Another commit that fixes nothing but with less changes [`e9a43b2`](https://example.com/git/users/commit/e9a43b2bf50449fc0d84465308e6008cc1597bb3) + +#### [v0.0.2](https://example.com/git/users/user/repos/repo/compare/commits?targetBranch=refs/heads/v0.0.1&sourceBranch=refs/heads/v0.0.2) + +> 28 December 2015 + +- Should not parse #4 in PR title [`#5`](https://example.com/git/users/pull/5) +- Commit 4 fixes #4 in the subject [`#4`](https://example.com/git/users/issues/4) + +#### v0.0.1 + +> 15 December 2015 + +- Third commit with same name as PR [`#3`](https://example.com/git/users/pull/3) +- Second commit [`#1`](https://example.com/git/users/issues/1) [`#2`](https://github.com/user/repo/issues/2) +- First commit [`158fdde`](https://example.com/git/users/commit/158fdde54b6188c9f9ca3034e9cb5bcc3fe3ff69) diff --git a/test/releases.js b/test/releases.js index 37b2062c..2563cfe1 100644 --- a/test/releases.js +++ b/test/releases.js @@ -46,6 +46,11 @@ describe('parseReleases', () => { expect(releases[0].href).to.equal('https://bitbucket.org/user/repo/compare/v1.0.0..v0.1.0') }) + it('parses bitbucket corporate releases', () => { + const releases = parseReleases(commits, remotes.bitbucketCorporate, null, options) + expect(releases[0].href).to.equal('https://example.com/git/users/user/repos/repo/compare/commits?targetBranch=refs/heads/v0.1.0&sourceBranch=refs/heads/v1.0.0') + }) + it('parses azure devops releases', () => { const releases = parseReleases(commits, remotes.azure, null, options) expect(releases[0].href).to.equal('https://dev.azure.com/user/project/_git/repo/branches?baseVersion=GTv1.0.0&targetVersion=GTv0.1.0&_a=commits') diff --git a/test/remote.js b/test/remote.js index f3938105..3bb10207 100644 --- a/test/remote.js +++ b/test/remote.js @@ -121,6 +121,15 @@ describe('fetchRemote', () => { unmock('cmd') }) + it('creates valid comparison URLs for corporate Bitbucket servers', async () => { + mock('cmd', () => '') + const result = await fetchRemote({ + compareUrl: 'https://example.com/compare/commits?targetBranch=refs/tags/{from}&sourceBranch=refs/tags/{to}' + }) + expect(result.getCompareLink('v1.2.3', 'v2.0.0')).to.equal('https://example.com/compare/commits?targetBranch=refs/tags/v1.2.3&sourceBranch=refs/tags/v2.0.0') + unmock('cmd') + }) + it('returns null functions', async () => { mock('cmd', () => '') const result = await fetchRemote({}) diff --git a/test/run.js b/test/run.js index 75229dd3..594daf95 100644 --- a/test/run.js +++ b/test/run.js @@ -5,6 +5,7 @@ import { readFile } from '../src/utils' import remotes from './data/remotes' import commits from './data/commits' import commitsNoRemote from './data/commits-no-remote' +import commitsBitbucketCorporate from './data/commits-bitbucket-corporate' import run, { __get__, __Rewire__ as mock, @@ -68,6 +69,19 @@ describe('run', () => { return run(['', '']) }) + it('generates a changelog with valid URLs for corporate BitBucket servers', async () => { + const expected = await readFile(join(__dirname, 'data', 'template-compact-bitbucket-corporate.md')) + + mock('fetchRemote', () => remotes.bitbucketCorporate) + mock('fetchCommits', () => commitsBitbucketCorporate) + mock('writeFile', (output, log) => { + expect(output).to.equal('CHANGELOG.md') + expect(log).to.equal(expected) + }) + + return run(['', '']) + }) + it('uses options from package.json', async () => { const expected = await readFile(join(__dirname, 'data', 'template-keepachangelog.md'))