Skip to content

Commit 1d490f6

Browse files
committed
Add ignore-commits-with option to filter commits with ignored words
1 parent 2af7e56 commit 1d490f6

File tree

3 files changed

+36
-12
lines changed

3 files changed

+36
-12
lines changed

lib/_options.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,13 @@ module.exports = {
7878
action: /^(merge|commits|all)$/i,
7979
defaultValue: 'commits'
8080
},
81+
{
82+
short: '-C',
83+
name: 'ignore-commits-with',
84+
valueType: '<string1>,<string2>',
85+
description: 'Ignore commits that contains one of the specified strings.',
86+
action: value => value.split(',')
87+
},
8188
{
8289
short: '-p',
8390
name: 'prefix',

lib/src/Gren.js

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const defaults = {
1616
override: false,
1717
ignoreLabels: false,
1818
ignoreIssuesWith: false,
19+
ignoreCommitsWith: false,
1920
groupBy: false,
2021
milestoneMatch: 'Release {{tag_name}}'
2122
};
@@ -29,11 +30,21 @@ class Gren {
2930
this.options = ObjectAssign({}, defaults, props);
3031
this.tasks = [];
3132

32-
const { username, repo, token, apiUrl, tags, ignoreLabels, ignoreIssuesWith } = this.options;
33+
const {
34+
username,
35+
repo,
36+
token,
37+
apiUrl,
38+
tags,
39+
ignoreLabels,
40+
ignoreIssuesWith,
41+
ignoreCommitsWith
42+
} = this.options;
3343

3444
this.options.tags = utils.convertStringToArray(tags);
3545
this.options.ignoreLabels = utils.convertStringToArray(ignoreLabels);
3646
this.options.ignoreIssuesWith = utils.convertStringToArray(ignoreIssuesWith);
47+
this.options.ignoreCommitsWith = utils.convertStringToArray(ignoreCommitsWith);
3748
this.options.limit = this.options.tags.indexOf('all') >= 0 ? MAX_TAGS_LIMIT : TAGS_LIMIT;
3849

3950
if (!token) {
@@ -540,22 +551,20 @@ class Gren {
540551
_filterCommit({ commit: { message } }) {
541552
const messageType = this.options.includeMessages;
542553
const filterMap = {
543-
merges: function(message) {
544-
return message.match(/^merge/i);
545-
},
546-
commits: function(message) {
547-
return !message.match(/^merge/i);
548-
},
549-
all: function() {
550-
return true;
551-
}
554+
merges: message => message.match(/^merge/i),
555+
commits: message => !message.match(/^merge/i),
556+
all: () => true
552557
};
558+
const shouldIgnoreMessage = this.options.ignoreCommitsWith.every(commitMessage => {
559+
const regex = new RegExp(commitMessage, 'i');
560+
return !message.split('\n')[0].match(regex);
561+
});
553562

554563
if (filterMap[messageType]) {
555-
return filterMap[messageType](message);
564+
return filterMap[messageType](message) && shouldIgnoreMessage;
556565
}
557566

558-
return filterMap.commits(message);
567+
return filterMap.commits(message) && shouldIgnoreMessage;
559568
}
560569

561570
/**

test/Gren.spec.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,14 @@ describe('Gren', () => {
438438
gren.options.includeMessages = 'merges';
439439
assert.deepEqual(gren._generateCommitsBody(commitMessages), messages(2), 'Using commits as includeMessages');
440440
});
441+
442+
it('Should not return commits with ignored words', () => {
443+
gren.options.ignoreCommitsWith = ['another'];
444+
445+
const messages = msg => `${commitMessages[msg].commit.message} - ${commitMessages[msg].commit.author.name}`;
446+
447+
assert.notInclude(commitMessages.filter(message => gren._filterCommit(message)), messages(1), 'Ignore another');
448+
});
441449
});
442450

443451
describe('_checkChangelogFile', () => {

0 commit comments

Comments
 (0)