diff --git a/app/lib/changelog.js b/app/lib/changelog.js index 0e2d970..c726a26 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,13 @@ 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`; + if(options.fullChangelogLink) { + changelogContent += `<${changelogUrl}|Full Changelog>\n`; + } for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { changelogContent += `*${labelConfig.title}*\n`; @@ -44,6 +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`; + 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 8ecb3f5..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, {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); }; diff --git a/tests/unit/lib/testChangelog.test.js b/tests/unit/lib/testChangelog.test.js index b699aac..05945a6 100644 --- a/tests/unit/lib/testChangelog.test.js +++ b/tests/unit/lib/testChangelog.test.js @@ -176,13 +176,15 @@ 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(); }); 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)\n" + "#### Notable changes\n" + "- Consequatur vero maxime deserunt laboriosam est voluptas dolorem. [#6](http://example.com/example/example/issues/6)\n" + "#### Enhancements\n" + @@ -198,12 +200,56 @@ 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(); }); 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)\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"); + }); + }); + 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" +