Skip to content

Commit

Permalink
feat: Link to issues and tickets in changelog
Browse files Browse the repository at this point in the history
Closes #8
  • Loading branch information
Jan Krems committed Dec 24, 2015
1 parent 2a834ba commit 73da2d3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 7 deletions.
14 changes: 13 additions & 1 deletion lib/steps/changelog.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,20 @@ function generateChangeLog(cwd, pkg, options) {
].join('\n');
}

function formatReference(ref) {
return '[' + ref.prefix + ref.issue + '](' + ref.href + ')';
}

function formatReferences(refs) {
if (!refs || refs.length === 0) return '';
return ' - see: ' + refs.map(formatReference).join(', ');
}

function formatCommit(commit) {
return getCommitLink(commit) + ' **' + commit.type + ':** ' + commit.subject;
return getCommitLink(commit) +
' **' + commit.type + ':** ' +
commit.subject +
formatReferences(commit.references);
}

function formatPR(pr) {
Expand Down
35 changes: 29 additions & 6 deletions test/steps/changelog.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,39 @@ describe('generateChangeLog', function () {
});
});

xit('links to github issues and jira tickets', function () {
it('links to github issues and jira tickets', function () {
var pkg = { repository: 'usr/proj' };
var commits = [
{
sha: '1234567890123456789012345678901234567890',
type: 'fix',
subject: 'Stop doing the wrong thing',
references: [
{},
{
action: 'Closes',
issue: '7',
prefix: 'fo/ba#',
href: 'https://gitub.com/fo/ba/issues/7',
},
],
},
{
sha: '2234567890123456789012345678901234567890',
type: 'feat',
subject: 'Do more things',
references: [
{
action: 'Resolves',
issue: '2010',
prefix: 'THING-',
href: 'https://example.com/browse/THING-7',
},
{
action: 'Fixes',
issue: '44',
prefix: '#',
href: 'https://github.com/usr/proj/issues/44',
},
],
},
];
Expand All @@ -70,10 +87,16 @@ describe('generateChangeLog', function () {
var href1 = 'https://github.com/usr/proj/commit/' + commits[1].sha;
return generateChangeLog(null, pkg, options)
.then(function (changelog) {
assert.equal([
'* [`1234567`](' + href0 + ') **fix:** Stop doing the wrong thing',
'* [`2234567`](' + href1 + ') **feat:** Do more things',
].join('\n'), changelog);
var lines = changelog.split('\n');
assert.equal(
'* [`1234567`](' + href0 + ') **fix:** Stop doing the wrong thing - see: ' +
'[fo/ba#7](https://gitub.com/fo/ba/issues/7)',
lines[0]);
assert.equal(
'* [`2234567`](' + href1 + ') **feat:** Do more things - see: ' +
'[THING-2010](https://example.com/browse/THING-7), ' +
'[#44](https://github.com/usr/proj/issues/44)',
lines[1]);
});
});

Expand Down

0 comments on commit 73da2d3

Please sign in to comment.