Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Allow unknown commit types #46

Merged
merged 1 commit into from
Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ $ changelog -h
-x, --exclude <types> exclude selected commit types (comma separated)
-f, --file [file] file to write to, defaults to ./CHANGELOG.md, use - for stdout
-u, --repo-url [url] specify the repo URL for commit links, defaults to checking the package.json
-a, --allow-unknown allow unkown commit types
```

It's possible to create a `./CHANGELOG.md` file for a specific commit range:
Expand Down
3 changes: 2 additions & 1 deletion lib/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ module.exports = CLI
.option('-t, --tag <range>', 'generate from specific tag or range (e.g. v1.2.3 or v1.2.3..v1.2.4)')
.option('-x, --exclude <types>', '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');
.option('-u, --repo-url [url]', 'specify the repo URL for commit links, defaults to checking the package.json')
.option('-a, --allow-unknown', 'allow unkown commit types');
2 changes: 1 addition & 1 deletion lib/git.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var Bluebird = require('bluebird');
var CP = Bluebird.promisifyAll(require('child_process'));

var SEPARATOR = '===END===';
var COMMIT_PATTERN = /^(\w*)(?:\(([^)]*?)\)|):(.*?(?:\[([^\]]+?)\]|))\s*$/;
var COMMIT_PATTERN = /^([^)]*)(?:\(([^)]*?)\)|):(.*?(?:\[([^\]]+?)\]|))\s*$/;
ffflorian marked this conversation as resolved.
Show resolved Hide resolved
var FORMAT = '%H%n%s%n%b%n' + SEPARATOR;

/**
Expand Down
9 changes: 7 additions & 2 deletions lib/writer.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ exports.markdown = function (version, commits, options) {
return Bluebird.resolve(commits)
.bind({ types: {} })
.each(function (commit) {
var type = TYPES[commit.type] ? commit.type : DEFAULT_TYPE;
var type = TYPES[commit.type] || options.allowUnknown ? commit.type : DEFAULT_TYPE;
var category = commit.category;

this.types[type] = this.types[type] || {};
Expand All @@ -89,8 +89,13 @@ exports.markdown = function (version, commits, options) {
})
.each(function (type) {
var types = this.types;
var typeDescription = TYPES[type];

content.push('##### ' + TYPES[type]);
if (!typeDescription && options.allowUnknown) {
typeDescription = TYPES.other + ' (' + type + ')';
}

content.push('##### ' + typeDescription);
content.push('');

Object.keys(this.types[type]).forEach(function (category) {
Expand Down
20 changes: 20 additions & 0 deletions test/writer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,26 @@ describe('writer', function () {
});
});

it('does not group uncommon types if unknown types are allowed', function () {
var commits = [
{ type: 'uncommon', category: 'testing', subject: 'did some testing', hash: '1234567890' },
{ type: 'unknown', category: 'testing', subject: 'did some more testing', hash: '1234567890' }
];

return Writer.markdown(VERSION, commits, { allowUnknown: true })
.then(function (changelog) {
return changelog.split('\n');
})
.filter(function (line) {
return line.indexOf('#####') > -1;
})
.tap(function (lines) {
Expect(lines).to.have.length(2);
Expect(lines[0]).to.eql('##### Other Changes (uncommon)');
Expect(lines[1]).to.eql('##### Other Changes (unknown)');
});
});

it('keeps a commit category on one line if there is only one commit in it', function () {
var category = 'testing';
var subject = 'did some testing';
Expand Down