From 8abd81cebba9923f77f14b6bee1ae92dde8fe611 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Voto=C4=8Dek?= Date: Tue, 21 Jan 2020 21:50:50 +0100 Subject: [PATCH 1/3] typo --- app/env.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/env.js b/app/env.js index 1842839..e0642a5 100644 --- a/app/env.js +++ b/app/env.js @@ -8,4 +8,4 @@ exports.NODE_ENV = process.env.NODE_ENV; // will looks for issues closed this many seconds after the tag, this may happen if the issue is merged via a MR and automatially closed // example -e GITLAB_ISSUE_SECOND_DELAY=60 will catch issues closed up to 60 seconds after the tag is created. -exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0" +exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0"; \ No newline at end of file From f9a0186af3ca9a75c5c1015a4ad2c7404fee0551 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Voto=C4=8Dek?= Date: Tue, 21 Jan 2020 21:51:14 +0100 Subject: [PATCH 2/3] option to disable empty sections --- README.md | 2 ++ app/env.js | 3 ++- app/lib/changelog.js | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index ab79c4a..9c997d8 100644 --- a/README.md +++ b/README.md @@ -68,6 +68,8 @@ These can be specified using environment variables * Default "Australia/Melbourne" * ISSUE_CLOSED_SECONDS: The amount of seconds to search after the last commit, useful for Merge Requests that close their tickets a second after the commit. * Default 0 +* RENDER_EMPTY_SECTIONS: Option to render empty default sections. _Closed Issues_ and _Merged merge requests_ are default and renders all the time, even when they are empty. With this option set to `"false"` this tool will not generate them if they are empty. + * Default `"true"` ## Building and Running locally diff --git a/app/env.js b/app/env.js index e0642a5..1bc4a69 100644 --- a/app/env.js +++ b/app/env.js @@ -8,4 +8,5 @@ exports.NODE_ENV = process.env.NODE_ENV; // will looks for issues closed this many seconds after the tag, this may happen if the issue is merged via a MR and automatially closed // example -e GITLAB_ISSUE_SECOND_DELAY=60 will catch issues closed up to 60 seconds after the tag is created. -exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0"; \ No newline at end of file +exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0"; +exports.RENDER_EMPTY_SECTIONS = process.env.RENDER_EMPTY_SECTIONS === "false" ? false : true; \ No newline at end of file diff --git a/app/lib/changelog.js b/app/lib/changelog.js index 0e2d970..bdeb983 100644 --- a/app/lib/changelog.js +++ b/app/lib/changelog.js @@ -46,7 +46,7 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } let changelogContent = `### Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})\n`; for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { - if (!_.isEmpty(changelogBucket[labelConfig.name]) || labelConfig.default) { + if (!_.isEmpty(changelogBucket[labelConfig.name]) || (labelConfig.default && Env.RENDER_EMPTY_SECTIONS)) { changelogContent += `#### ${labelConfig.title}\n`; if (!_.isEmpty(changelogBucket[labelConfig.name])) changelogContent += changelogBucket[labelConfig.name].join("\n") + "\n"; } From f5d0ffa5151054d21925ade065e50cd2b06e4ba7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrik=20Voto=C4=8Dek?= Date: Mon, 3 Feb 2020 12:52:39 +0100 Subject: [PATCH 3/3] add test for render empty section option --- app/lib/changelog.js | 4 +++- app/lib/generator.js | 2 +- tests/unit/lib/testChangelog.test.js | 18 ++++++++++++++++++ 3 files changed, 22 insertions(+), 2 deletions(-) diff --git a/app/lib/changelog.js b/app/lib/changelog.js index bdeb983..7a34c60 100644 --- a/app/lib/changelog.js +++ b/app/lib/changelog.js @@ -24,6 +24,8 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } // Separate by labels let changelogBucket = exports._createLabelBucket(); + const renderEmptySections = options.renderEmptySections != null ? options.renderEmptySections : true; + exports._populateIssuesWithBucketByIssue(changelogBucket, issues, options); exports._populateMergeRequestsWithBucketByMergeRequests(changelogBucket, mergeRequests, options); @@ -46,7 +48,7 @@ exports.generateChangeLogContent = async ({ releaseDate, issues, mergeRequests } let changelogContent = `### Release note (${Moment.tz(releaseDate, Env.TZ).format("YYYY-MM-DD")})\n`; for (const labelConfig of labelConfigs) { if (changelogBucket[labelConfig.name]) { - if (!_.isEmpty(changelogBucket[labelConfig.name]) || (labelConfig.default && Env.RENDER_EMPTY_SECTIONS)) { + if (!_.isEmpty(changelogBucket[labelConfig.name]) || (labelConfig.default && renderEmptySections)) { changelogContent += `#### ${labelConfig.title}\n`; if (!_.isEmpty(changelogBucket[labelConfig.name])) changelogContent += changelogBucket[labelConfig.name].join("\n") + "\n"; } diff --git a/app/lib/generator.js b/app/lib/generator.js index 8ecb3f5..5e83883 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, {useSlack: false, renderEmptySections: Env.RENDER_EMPTY_SECTIONS}); 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..017e65d 100644 --- a/tests/unit/lib/testChangelog.test.js +++ b/tests/unit/lib/testChangelog.test.js @@ -168,6 +168,12 @@ describe("ChangelogLib lib", () => { "subscribed": false }]; }; + const setupCommonEmpty = () => { + MockDate.set(new Date("2019-06-02T06:26:31.000Z")); + releaseDate = new Date().toISOString(); + mergeRequests = []; + issues = []; + }; const cleanUpCommon = () => { MockDate.reset(); }; @@ -211,5 +217,17 @@ describe("ChangelogLib lib", () => { "- test1 [#1](http://gitlab.example.com/my-group/my-project/merge_requests/1) ([admin](https://gitlab.example.com/admin))\n"); }); }); + describe("Without empty sections", () => { + beforeAll(async () => { + setupCommonEmpty(); + changelog = await ChangelogLib.generateChangeLogContent({releaseDate, issues, mergeRequests}, {renderEmptySections: false}); + }); + afterAll(() => { + cleanUpCommon(); + }); + test("should render changelog in markdown", () => { + expect(changelog).toEqual("### Release note (2019-06-02)\n"); + }); + }); }); }); \ No newline at end of file