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

Feature/add changelog link #16

Open
wants to merge 5 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
9 changes: 9 additions & 0 deletions app/lib/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down Expand Up @@ -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}`;
jk1z marked this conversation as resolved.
Show resolved Hide resolved
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`;
Expand All @@ -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) {
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, {tags, fullChangelogLink: true, useSlack: false});
Logger.debug(`Changelog: ${changeLogContent}`);
return await TagLib.upsertTagDescriptionByProjectIdAndTag(Env.GITLAB_PROJECT_ID, latestTag, changeLogContent);
};
50 changes: 48 additions & 2 deletions tests/unit/lib/testChangelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand All @@ -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");
});
});
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have a test case with fullChangeLogLink please?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added, but as mentioned in the description, I'm unable to test (or could you explain how to test?)

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" +
Expand Down