Skip to content

Commit

Permalink
fix(writer): don't print category if empty
Browse files Browse the repository at this point in the history
  • Loading branch information
tvardy committed Jun 5, 2017
1 parent 21a8003 commit a859a9b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/git.js
Expand Up @@ -47,7 +47,7 @@ exports.getCommits = function () {
}

commit.type = parsed[1].toLowerCase();
commit.category = parsed[3];
commit.category = parsed[3] || '';
commit.subject = parsed[4];

return commit;
Expand Down
4 changes: 2 additions & 2 deletions lib/writer.js
Expand Up @@ -67,9 +67,9 @@ exports.markdown = function (version, commits, options) {
Object.keys(this.types[type]).forEach(function (category) {
var prefix = '*';
var nested = types[type][category].length > 1;
var categoryHeading = '* **' + category + ':**';
var categoryHeading = prefix + (category ? ' **' + category + ':**' : '');

if (nested) {
if (nested && category) {
content.push(categoryHeading);
prefix = ' *';
} else {
Expand Down
22 changes: 21 additions & 1 deletion test/writer.test.js
Expand Up @@ -122,7 +122,7 @@ describe('writer', function () {
});
});

it('breaks a commit category onto its own line if there are more than one commit in it', function () {
it('breaks a commit category onto its own line if there is more than one commit in it', function () {
var category = 'testing';
var commits = [
{ type: 'feat', category: category, subject: 'did some testing', hash: '1234567890' },
Expand All @@ -144,6 +144,26 @@ describe('writer', function () {
});
});

it('omits commit category if there was no category defined', function () {
var hash = '1234567890';
var commits = [
{ type: 'feat', category: 'testing', subject: 'did some testing', hash: hash },
{ type: 'test', category: '', subject: 'other changes', hash: hash }
];

return Writer.markdown(VERSION, commits, {})
.then(function (changelog) {
return changelog.split('\n');
})
.filter(function (line) {
return line.indexOf(hash.slice(0, 8)) > -1;
})
.then(function (lines) {
Expect(lines[0]).to.equal('* **testing:** did some testing (12345678)');
Expect(lines[1]).to.equal('* other changes (12345678)');
});
});

it('trims the commit hash to only 8 chars', function () {
var category = 'testing';
var hash = '1234567890';
Expand Down

0 comments on commit a859a9b

Please sign in to comment.