Skip to content

Commit

Permalink
Merge 42b96e6 into 21a8003
Browse files Browse the repository at this point in the history
  • Loading branch information
tvardy authored Jun 3, 2017
2 parents 21a8003 + 42b96e6 commit c575ca2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 12 deletions.
6 changes: 6 additions & 0 deletions lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,11 @@ module.exports = CLI
.option('-p, --patch', 'create a patch changelog')
.option('-m, --minor', 'create a minor changelog')
.option('-M, --major', 'create a major changelog')
.option('-x, --exclude', 'exclude selected commit types (comma separated)', list)
.option('-f, --file [file]', 'file to write to, defaults to ./CHANGELOG.md, use - for stdout', './CHANGELOG.md')
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json');


function list (val) {
return val.split(',');
}
10 changes: 6 additions & 4 deletions lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ var FORMAT = '%H%n%s%n%b%n' + SEPARATOR;
* Get all commits from the last tag (or the first commit if no tags).
* @returns {Promise<Array<Object>>} array of parsed commit objects
*/
exports.getCommits = function () {
exports.getCommits = function (options) {
options = options || {};
return CP.execAsync('git describe --tags --abbrev=0')
.catch(function () {
return '';
Expand Down Expand Up @@ -47,12 +48,13 @@ exports.getCommits = function () {
}

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

return commit;
})
.filter(function (commit) {
return commit !== null;
.filter(function (commit, i) {
if (!commit) return false;
return options.exclude ? (options.exclude.indexOf(commit.type) !== -1) : true;
});
};
3 changes: 2 additions & 1 deletion lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,14 @@ var Writer = require('./writer');
* @param {Boolean} options.minor - whether it should be a minor changelog
* @param {Boolean} options.major - whether it should be a major changelog
* @param {String} options.repoUrl - repo URL that will be used when linking commits
* @param {Array} options.exclude - exclude listed commit types (e.g. ['chore', 'style', 'refactor'])
* @returns {Promise<String>} the \n separated changelog string
*/
exports.generate = function (options) {
return Bluebird.all([
Package.extractRepoUrl(),
Package.calculateNewVersion(options),
Git.getCommits()
Git.getCommits(options)
])
.spread(function (repoUrl, version, commits) {
options.repoUrl = options.repoUrl || repoUrl;
Expand Down
12 changes: 12 additions & 0 deletions test/data/git/valid-commits.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,15 @@ a2c164a718e45d7d3c5e37eec2008a3ebf371e93
feat(testing): did some testing

===END===
9bbdcf32e1c46176c4cbdcef329ada45fed0bf5a
chore(release): 1.2.3
New release
===END===
e45d7d3c5e37eec2008a3ebf371e93a2c164a718
style(all): reviewed semicolons usage

===END===
e45d7d3c5e37eec2008a3ebf371e93a2c164a718
test: add test coverage

===END===
14 changes: 13 additions & 1 deletion test/git.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describe('git', function () {

return Git.getCommits()
.then(function (commits) {
Expect(commits).to.have.length(1);
Expect(commits).to.have.length(4);
Expect(commits[0]).to.have.property('type');
Expect(commits[0]).to.have.property('category');
Expect(commits[0]).to.have.property('subject');
Expand All @@ -83,6 +83,18 @@ describe('git', function () {
});
});

it('skips any excluded commit types', function () {
Sinon.stub(CP, 'execAsync')
.onFirstCall().returns(Bluebird.resolve('v1.2.3'))
.onSecondCall().returns(Bluebird.resolve(VALID_COMMITS));

return Git.getCommits({ exclude: ['chore', 'style']})
.then(function (commits) {
Expect(commits).to.have.length(2);
CP.execAsync.restore();
});
});

});

});
18 changes: 12 additions & 6 deletions test/package.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ describe('package', function () {
Package.getUserPackage.restore();
});

it('bumps the patch version if patch is true', function () {
var options = { patch: true };
it('bumps the major version if major is true', function () {
var options = { major: true };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('1.2.4');
Expect(version).to.eql('2.0.0');
});
});

Expand All @@ -132,15 +132,21 @@ describe('package', function () {
});
});

it('bumps the major version if major is true', function () {
var options = { major: true };
it('bumps the patch version if patch is true', function () {
var options = { patch: true };

return Package.calculateNewVersion(options)
.then(function (version) {
Expect(version).to.eql('2.0.0');
Expect(version).to.eql('1.2.4');
});
});

it('leaves the version untouched if none of three options is true', function () {
return Package.calculateNewVersion({})
.then(function (version) {
Expect(version).to.eql('1.2.3');
});
});
});

});

0 comments on commit c575ca2

Please sign in to comment.