From 72f74046225c664b15b13e18e69008f1076990af Mon Sep 17 00:00:00 2001 From: Glenn Mulleners Date: Fri, 27 Dec 2019 09:23:07 +0100 Subject: [PATCH 1/5] Add link to full changelog --- app/lib/changelog.js | 5 +++++ app/lib/generator.js | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/app/lib/changelog.js b/app/lib/changelog.js index 0e2d970..33e145f 100644 --- a/app/lib/changelog.js +++ b/app/lib/changelog.js @@ -4,6 +4,7 @@ const MergeRequestLib = require("./mergeRequest"); const Moment = require("moment-timezone"); const Env = require("../env"); const Logger = require("../logger"); +const Gitlab = require("../adapters/gitlab"); // Changelog available format exports.CHANGELOG_FORMAT_SLACK = "slack-format"; @@ -33,8 +34,11 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } { name: "issues", title: "Closed issues", default: true }, { name: "mergeRequests", title: "Merged merge requests", default: true } ]; + const project = await Gitlab.getRepoByProjectId(Env.GITLAB_PROJECT_ID); + const changelogUrl = `${project.web_url}/compare/${options.tags[1].name}...${options.tags[0].name}`; if (options.useSlack) { let changelogContent = `*Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})*\n`; + changelogContent += `<${changelogUrl}|Full Changelog>\n`; for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { changelogContent += `*${labelConfig.title}*\n`; @@ -44,6 +48,7 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } return changelogContent; } else { let changelogContent = `### Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})\n`; + changelogContent += `[Full Changelog](${changelogUrl})\n`; for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { if (!_.isEmpty(changelogBucket[labelConfig.name]) || labelConfig.default) { diff --git a/app/lib/generator.js b/app/lib/generator.js index 8ecb3f5..dc1207e 100644 --- a/app/lib/generator.js +++ b/app/lib/generator.js @@ -26,7 +26,7 @@ exports.generate = async () => { } const changeLog = await ChangelogLib.getChangelogByStartAndEndDate(startDate, endDate); - const changeLogContent = await ChangelogLib.generateChangeLogContent(changeLog, {useSlack: false}); + const changeLogContent = await ChangelogLib.generateChangeLogContent(changeLog, {tags, useSlack: false}); Logger.debug(`Changelog: ${changeLogContent}`); return await TagLib.upsertTagDescriptionByProjectIdAndTag(Env.GITLAB_PROJECT_ID, latestTag, changeLogContent); }; From ea3a9d393f1009b7e56dfe8382614945a2991d19 Mon Sep 17 00:00:00 2001 From: Glenn Mulleners Date: Fri, 27 Dec 2019 10:07:36 +0100 Subject: [PATCH 2/5] Toggleable full changelog --- app/lib/changelog.js | 8 ++++++-- app/lib/generator.js | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/app/lib/changelog.js b/app/lib/changelog.js index 33e145f..c726a26 100644 --- a/app/lib/changelog.js +++ b/app/lib/changelog.js @@ -38,7 +38,9 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } const changelogUrl = `${project.web_url}/compare/${options.tags[1].name}...${options.tags[0].name}`; if (options.useSlack) { let changelogContent = `*Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})*\n`; - changelogContent += `<${changelogUrl}|Full Changelog>\n`; + if(options.fullChangelogLink) { + changelogContent += `<${changelogUrl}|Full Changelog>\n`; + } for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { changelogContent += `*${labelConfig.title}*\n`; @@ -48,7 +50,9 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } return changelogContent; } else { let changelogContent = `### Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})\n`; - changelogContent += `[Full Changelog](${changelogUrl})\n`; + if (options.fullChangelogLink) { + changelogContent += `[Full Changelog](${changelogUrl})\n`; + } for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { if (!_.isEmpty(changelogBucket[labelConfig.name]) || labelConfig.default) { diff --git a/app/lib/generator.js b/app/lib/generator.js index dc1207e..bcfefc0 100644 --- a/app/lib/generator.js +++ b/app/lib/generator.js @@ -26,7 +26,7 @@ exports.generate = async () => { } const changeLog = await ChangelogLib.getChangelogByStartAndEndDate(startDate, endDate); - const changeLogContent = await ChangelogLib.generateChangeLogContent(changeLog, {tags, useSlack: false}); + const changeLogContent = await ChangelogLib.generateChangeLogContent(changeLog, {tags, fullChangelogLink: true, useSlack: false}); Logger.debug(`Changelog: ${changeLogContent}`); return await TagLib.upsertTagDescriptionByProjectIdAndTag(Env.GITLAB_PROJECT_ID, latestTag, changeLogContent); }; From 9f08fc1220ab62008f7b83d9d97c96ebc1757e35 Mon Sep 17 00:00:00 2001 From: Glenn Mulleners Date: Fri, 27 Dec 2019 10:34:43 +0100 Subject: [PATCH 3/5] Add tests for full changelog link --- tests/unit/lib/testChangelog.test.js | 48 ++++++++++++++++++++++++++-- 1 file changed, 46 insertions(+), 2 deletions(-) diff --git a/tests/unit/lib/testChangelog.test.js b/tests/unit/lib/testChangelog.test.js index b699aac..f577331 100644 --- a/tests/unit/lib/testChangelog.test.js +++ b/tests/unit/lib/testChangelog.test.js @@ -176,7 +176,8 @@ describe("ChangelogLib lib", () => { setupCommon(); issues[0].labels = ["breaking change", "enhancement"]; mergeRequests[0].labels = ["bug", "feature"]; - changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}); + tags = ["0.1.1", "0.1.0"]; + changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}, {tags, fullChangelogLink: true}); }); afterAll(() => { cleanUpCommon(); @@ -198,7 +199,8 @@ describe("ChangelogLib lib", () => { describe("Without labels", () => { beforeAll(async () => { setupCommon(); - changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}); + tags = ["0.1.1", "0.1.0"]; + changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}, {tags, fullChangelogLink: true}); }); afterAll(() => { cleanUpCommon(); @@ -211,5 +213,47 @@ describe("ChangelogLib lib", () => { "- test1 [#1](http://gitlab.example.com/my-group/my-project/merge_requests/1) ([admin](https://gitlab.example.com/admin))\n"); }); }); + describe("With labels and without full changelog link", () => { + beforeAll(async () => { + setupCommon(); + issues[0].labels = ["breaking change", "enhancement"]; + mergeRequests[0].labels = ["bug", "feature"]; + tags = ["0.1.1", "0.1.0"]; + changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}, {tags); + }); + afterAll(() => { + cleanUpCommon(); + }); + test("should render changelog in markdown without full changelog link", () => { + expect(changelog).toEqual("### Release note (2019-06-02)\n" + + "#### Notable changes\n" + + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + + "#### Enhancements\n" + + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + + "#### New features\n" + + "- test1 [#1](http://gitlab.example.com/my-group/my-project/merge_requests/1) ([admin](https://gitlab.example.com/admin))\n" + + "#### Fixed bugs\n" + + "- test1 [#1](http://gitlab.example.com/my-group/my-project/merge_requests/1) ([admin](https://gitlab.example.com/admin))\n" + + "#### Closed issues\n" + + "#### Merged merge requests\n") + }); + }); + describe("Without labels and without full changelog link", () => { + beforeAll(async () => { + setupCommon(); + tags = ["0.1.1", "0.1.0"]; + changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}, {tags}); + }); + afterAll(() => { + cleanUpCommon(); + }); + test("should render changelog in markdown without full changelog link", () => { + expect(changelog).toEqual("### Release note (2019-06-02)\n" + + "#### Closed issues\n" + + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + + "#### Merged merge requests\n" + + "- test1 [#1](http://gitlab.example.com/my-group/my-project/merge_requests/1) ([admin](https://gitlab.example.com/admin))\n"); + }); + }); }); }); \ No newline at end of file From 023a586fcc4a428f708e7d0df8e591c37d37a5af Mon Sep 17 00:00:00 2001 From: Glenn Mulleners Date: Thu, 2 Jan 2020 14:29:53 +0100 Subject: [PATCH 4/5] Add Full Changelog link to tests --- tests/unit/lib/testChangelog.test.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/unit/lib/testChangelog.test.js b/tests/unit/lib/testChangelog.test.js index f577331..f0bd054 100644 --- a/tests/unit/lib/testChangelog.test.js +++ b/tests/unit/lib/testChangelog.test.js @@ -184,6 +184,7 @@ describe("ChangelogLib lib", () => { }); test("should render changelog in markdown", () => { expect(changelog).toEqual("### Release note (2019-06-02)\n" + + "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)" + "#### Notable changes\n" + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + "#### Enhancements\n" + @@ -207,6 +208,7 @@ describe("ChangelogLib lib", () => { }); test("should render changelog in markdown", () => { expect(changelog).toEqual("### Release note (2019-06-02)\n" + + "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)" + "#### Closed issues\n" + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + "#### Merged merge requests\n" + From 6c36de31f1ceba8ef6402b12c512db18c46f5e59 Mon Sep 17 00:00:00 2001 From: Glenn Mulleners Date: Thu, 2 Jan 2020 15:37:43 +0100 Subject: [PATCH 5/5] Add newline --- tests/unit/lib/testChangelog.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/lib/testChangelog.test.js b/tests/unit/lib/testChangelog.test.js index f0bd054..05945a6 100644 --- a/tests/unit/lib/testChangelog.test.js +++ b/tests/unit/lib/testChangelog.test.js @@ -184,7 +184,7 @@ describe("ChangelogLib lib", () => { }); test("should render changelog in markdown", () => { expect(changelog).toEqual("### Release note (2019-06-02)\n" + - "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)" + + "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)\n" + "#### Notable changes\n" + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + "#### Enhancements\n" + @@ -208,7 +208,7 @@ describe("ChangelogLib lib", () => { }); test("should render changelog in markdown", () => { expect(changelog).toEqual("### Release note (2019-06-02)\n" + - "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)" + + "[Full Changelog](http://gitlab.example.com/my-group/my-project/compare/0.1.0...0.1.1)\n" + "#### Closed issues\n" + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + "#### Merged merge requests\n" +