Skip to content

Commit

Permalink
Make references to pull requests a link
Browse files Browse the repository at this point in the history
  • Loading branch information
lo1tuma committed Mar 9, 2018
1 parent 0a61669 commit 1105b08
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ export default function createCliAgent(dependencies) {
}

const pullRequests = await getMergedPullRequests(githubRepo, validLabels);
const changelog = createChangelog(newVersionNumber, validLabels, pullRequests);
const changelog = createChangelog(newVersionNumber, validLabels, pullRequests, githubRepo);

return stripTrailingEmptyLine(changelog);
}
Expand Down
8 changes: 6 additions & 2 deletions lib/createChangelog.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import moment from 'moment';
import R from 'ramda';

function formatLinkToPullRequest(repo, pullRequestId) {
return `[#${pullRequestId}](https://github.com/${repo}/pull/${pullRequestId})`;
}

export default ({ getCurrentDate }) => {
return function createChangelog(newVersionNumber, validLabels, mergedPullRequests) {
return function createChangelog(newVersionNumber, validLabels, mergedPullRequests, repo) {
const groupedPullRequests = R.groupBy(R.prop('label'), mergedPullRequests);
const date = moment(getCurrentDate()).locale('en').format('MMMM D, YYYY');
const title = `## ${newVersionNumber} (${date})`;
Expand All @@ -15,7 +19,7 @@ export default ({ getCurrentDate }) => {
changelog += `### ${validLabels[label]}\n\n`;

pullRequests.forEach(function (pullRequest) {
changelog += `* ${pullRequest.title} (#${pullRequest.id})\n`;
changelog += `* ${pullRequest.title} (${formatLinkToPullRequest(repo, pullRequest.id)})\n`;
});

changelog += '\n';
Expand Down
2 changes: 1 addition & 1 deletion test/unit/lib/cliSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test('uses custom labels if they are provided in package.json', async (t) => {
t.deepEqual(getMergedPullRequests.firstCall.args, [ 'foo/bar', { foo: 'Foo', bar: 'Bar' } ]);

t.is(createChangelog.callCount, 1);
t.deepEqual(createChangelog.firstCall.args, [ '1.0.0', { foo: 'Foo', bar: 'Bar' }, undefined ]);
t.deepEqual(createChangelog.firstCall.args, [ '1.0.0', { foo: 'Foo', bar: 'Bar' }, undefined, 'foo/bar' ]);
});

test('reports the generated changelog', async (t) => {
Expand Down
16 changes: 8 additions & 8 deletions test/unit/lib/createChangelogSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,16 @@ test('creates a formatted changelog', (t) => {
const expectedChangelog = [
'### Bug Fixes',
'',
'* Fixed bug foo (#1)',
'* Fixed bug bar (#2)',
'* Fixed bug foo ([#1](https://github.com/any/repo/pull/1))',
'* Fixed bug bar ([#2](https://github.com/any/repo/pull/2))',
'',
'### Documentation',
'',
'* Fix spelling error (#3)',
'* Fix spelling error ([#3](https://github.com/any/repo/pull/3))',
''
].join('\n');

const changelog = createChangelog('1.0.0', defaultValidLabels, mergedPullRequests);
const changelog = createChangelog('1.0.0', defaultValidLabels, mergedPullRequests, 'any/repo');

t.true(changelog.includes(expectedChangelog));
});
Expand Down Expand Up @@ -74,16 +74,16 @@ test('uses custom labels when provided', (t) => {
const expectedChangelog = [
'### Core Features',
'',
'* Fixed bug foo (#1)',
'* Fix spelling error (#3)',
'* Fixed bug foo ([#1](https://github.com/any/repo/pull/1))',
'* Fix spelling error ([#3](https://github.com/any/repo/pull/3))',
'',
'### Addons',
'',
'* Fixed bug bar (#2)',
'* Fixed bug bar ([#2](https://github.com/any/repo/pull/2))',
''
].join('\n');

const changelog = createChangelog('1.0.0', customValidLabels, mergedPullRequests);
const changelog = createChangelog('1.0.0', customValidLabels, mergedPullRequests, 'any/repo');

t.true(changelog.includes(expectedChangelog));
});

0 comments on commit 1105b08

Please sign in to comment.