Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to disable empty section #19

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
3 changes: 2 additions & 1 deletion app/env.js
Original file line number Diff line number Diff line change
Expand Up @@ -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"
exports.ISSUE_CLOSED_SECONDS = process.env.ISSUE_CLOSED_SECONDS || "0";
exports.RENDER_EMPTY_SECTIONS = process.env.RENDER_EMPTY_SECTIONS === "false" ? false : true;
4 changes: 3 additions & 1 deletion app/lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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) {
if (!_.isEmpty(changelogBucket[labelConfig.name]) || (labelConfig.default && renderEmptySections)) {
changelogContent += `#### ${labelConfig.title}\n`;
if (!_.isEmpty(changelogBucket[labelConfig.name])) changelogContent += changelogBucket[labelConfig.name].join("\n") + "\n";
}
Expand Down
2 changes: 1 addition & 1 deletion app/lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
18 changes: 18 additions & 0 deletions tests/unit/lib/testChangelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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();
};
Expand Down Expand Up @@ -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");
});
});
});
});