Skip to content
This repository has been archived by the owner on Feb 5, 2018. It is now read-only.

Commit

Permalink
fix(notes): do not include reverted notes
Browse files Browse the repository at this point in the history
BREAKING CHANGE: `includeDetails` will only include `log` and `keyCommit`.
  • Loading branch information
stevemao committed Jul 23, 2015
1 parent 33be78e commit e6ca2a2
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 31 deletions.
23 changes: 6 additions & 17 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ var _ = require('lodash');
function conventionalChangelogWriter(context, options) {
var savedKeyCommit;
var commits = [];
var notes = [];

context = _.extend({
commit: 'commits',
Expand Down Expand Up @@ -93,47 +92,39 @@ function conventionalChangelogWriter(context, options) {
if (options.reverse) {
if (commit) {
commits.push(commit);
notes = notes.concat(commit.notes);
}

if (generateOn(keyCommit)) {
result = util.generate(options, commits, notes, context, keyCommit);
result = util.generate(options, commits, context, keyCommit);
if (options.includeDetails) {
this.push({
log: result,
commits: commits,
keyCommit: keyCommit,
notes: notes
keyCommit: keyCommit
});
} else {
this.push(result);
}

commits = [];
notes = [];
}
} else {
if (generateOn(keyCommit)) {
result = util.generate(options, commits, notes, context, savedKeyCommit);
result = util.generate(options, commits, context, savedKeyCommit);
if (options.includeDetails) {
this.push({
log: result,
commits: commits,
keyCommit: savedKeyCommit,
notes: notes
keyCommit: savedKeyCommit
});
} else {
this.push(result);
}

commits = [];
notes = [];
savedKeyCommit = keyCommit;
}

if (commit) {
commits.push(commit);
notes = notes.concat(commit.notes);
}
}

Expand All @@ -147,14 +138,12 @@ function conventionalChangelogWriter(context, options) {
keyCommit = savedKeyCommit;
}

result = util.generate(options, commits, notes, context, savedKeyCommit);
result = util.generate(options, commits, context, savedKeyCommit);

if (options.includeDetails) {
this.push({
log: result,
commits: commits,
keyCommit: savedKeyCommit,
notes: notes
keyCommit: savedKeyCommit
});
} else {
this.push(result);
Expand Down
7 changes: 6 additions & 1 deletion lib/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,18 @@ function getExtraContext(commits, notes, options) {
return context;
}

function generate(options, commits, notes, context, keyCommit) {
function generate(options, commits, context, keyCommit) {
var notes = [];
var compiled = compileTemplates(options);

if (options.ignoreReverted) {
commits = conventionalCommitsFilter(commits);
}

_.forEach(commits, function(commit) {
notes = notes.concat(commit.notes);
});

var mergedContext = _.merge({}, context, keyCommit, getExtraContext(commits, notes, options));

if (keyCommit && keyCommit.committerDate) {
Expand Down
12 changes: 0 additions & 12 deletions test/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -441,21 +441,15 @@ describe('conventionalChangelogWriter', function() {
if (i === 0) {
expect(chunk.log).to.include('<a name=""></a>\n# (' + today + ')\n\n');
expect(chunk.log).to.include('feat(scope): broadcast $destroy event on scope destruction');
expect(chunk.commits[0].header).to.equal('feat(scope): broadcast $destroy event on scope destruction');
expect(chunk.keyCommit).to.eql();
expect(chunk.notes).to.eql([]);
} else {
expect(chunk.log).to.include('<a name="1.0.1"></a>\n## 1.0.1 (2015-04-07)\n\n');
expect(chunk.log).to.include('fix(ng-list): Allow custom separator');
expect(chunk.log).to.include('perf(template): tweak');
expect(chunk.log).to.include('refactor(name): rename this module to conventional-changelog-writer');
expect(chunk.commits[0].header).to.equal('fix(ng-list): Allow custom separator');
expect(chunk.commits[1].body).to.equal('My body.');
expect(chunk.commits[2].committerDate).to.equal('2015-04-07');
expect(chunk.keyCommit.body).to.equal('bla bla bla');
expect(chunk.keyCommit.committerDate).to.equal('2015-04-07');
expect(chunk.keyCommit.version).to.equal('1.0.1');
expect(chunk.notes).to.eql([]);
}

i++;
Expand Down Expand Up @@ -544,19 +538,13 @@ describe('conventionalChangelogWriter', function() {
expect(chunk.log).to.include('<a name="1.0.1"></a>\n## 1.0.1 (2015-04-07)\n\n');
expect(chunk.log).to.include('broadcast $destroy event on scope destruction');
expect(chunk.log).to.include('fix(ng-list):');
expect(chunk.commits[0].header).to.equal('feat(scope): broadcast $destroy event on scope destruction');
expect(chunk.commits[1].body).to.equal('bla bla bla');
expect(chunk.keyCommit.version).to.equal('1.0.1');
expect(chunk.keyCommit.committerDate).to.equal('2015-04-07');
expect(chunk.notes).to.eql([]);
} else {
expect(chunk.log).to.include('<a name=""></a>\n# (' + today + ')\n\n');
expect(chunk.log).to.include('perf(template): tweak');
expect(chunk.log).to.include('refactor(name): rename this module to conventional-changelog-writer');
expect(chunk.commits[0].header).to.equal('perf(template): tweak');
expect(chunk.commits[1].committerDate).to.equal('2015-04-07');
expect(chunk.keyCommit).to.eql();
expect(chunk.notes).to.eql([]);
}

i++;
Expand Down
2 changes: 1 addition & 1 deletion test/util.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ describe('util', function() {
it('should merge with the key commit', function() {
var log = util.generate({
mainTemplate: '{{whatever}}'
}, [], [], {
}, [], {
whatever: 'a'
}, {
whatever: 'b'
Expand Down

0 comments on commit e6ca2a2

Please sign in to comment.