Visitar URL original
Add ignore-commits-with option to filter commits with ignored words by alexcanessa · Pull Request #103 · github-tools/github-release-notes · GitHub
Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions lib/_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ module.exports = {
action: /^(merge|commits|all)$/i,
defaultValue: 'commits'
},
{
short: '-C',
name: 'ignore-commits-with',
valueType: '<string1>,<string2>',
description: 'Ignore commits that contains one of the specified strings.',
action: value => value.split(',')
},
{
short: '-p',
name: 'prefix',
Expand Down
33 changes: 21 additions & 12 deletions lib/src/Gren.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const defaults = {
override: false,
ignoreLabels: false,
ignoreIssuesWith: false,
ignoreCommitsWith: false,
groupBy: false,
milestoneMatch: 'Release {{tag_name}}'
};
Expand All @@ -29,11 +30,21 @@ class Gren {
this.options = ObjectAssign({}, defaults, props);
this.tasks = [];

const { username, repo, token, apiUrl, tags, ignoreLabels, ignoreIssuesWith } = this.options;
const {
username,
repo,
token,
apiUrl,
tags,
ignoreLabels,
ignoreIssuesWith,
ignoreCommitsWith
} = this.options;

this.options.tags = utils.convertStringToArray(tags);
this.options.ignoreLabels = utils.convertStringToArray(ignoreLabels);
this.options.ignoreIssuesWith = utils.convertStringToArray(ignoreIssuesWith);
this.options.ignoreCommitsWith = utils.convertStringToArray(ignoreCommitsWith);
this.options.limit = this.options.tags.indexOf('all') >= 0 ? MAX_TAGS_LIMIT : TAGS_LIMIT;

if (!token) {
Expand Down Expand Up @@ -540,22 +551,20 @@ class Gren {
_filterCommit({ commit: { message } }) {
const messageType = this.options.includeMessages;
const filterMap = {
merges: function(message) {
return message.match(/^merge/i);
},
commits: function(message) {
return !message.match(/^merge/i);
},
all: function() {
return true;
}
merges: message => message.match(/^merge/i),
commits: message => !message.match(/^merge/i),
all: () => true
};
const shouldIgnoreMessage = this.options.ignoreCommitsWith.every(commitMessage => {
const regex = new RegExp(commitMessage, 'i');
return !message.split('\n')[0].match(regex);
});

if (filterMap[messageType]) {
return filterMap[messageType](message);
return filterMap[messageType](message) && shouldIgnoreMessage;
}

return filterMap.commits(message);
return filterMap.commits(message) && shouldIgnoreMessage;
}

/**
Expand Down
8 changes: 8 additions & 0 deletions test/Gren.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,14 @@ describe('Gren', () => {
gren.options.includeMessages = 'merges';
assert.deepEqual(gren._generateCommitsBody(commitMessages), messages(2), 'Using commits as includeMessages');
});

it('Should not return commits with ignored words', () => {
gren.options.ignoreCommitsWith = ['another'];

const messages = msg => `${commitMessages[msg].commit.message} - ${commitMessages[msg].commit.author.name}`;

assert.notInclude(commitMessages.filter(message => gren._filterCommit(message)), messages(1), 'Ignore another');
});
});

describe('_checkChangelogFile', () => {
Expand Down