Skip to content

Commit

Permalink
fix: fix regex rules evaluation
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdlg committed Jan 21, 2018
1 parent 67f9f88 commit 53faf3b
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/analyze-commit.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ module.exports = (releaseRules, commit) => {
commit,
omit(rule, ['release', 'breaking']),
(obj, src) =>
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/.*\/$/.exec(src)[1]).test(obj) : undefined
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/(.*)\/$/.exec(src)[1]).test(obj) : undefined
)
)
.every(match => {
Expand Down
14 changes: 10 additions & 4 deletions test/analyze-commit.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,15 +46,21 @@ test('Return undefined if there is no match', t => {
});

test('Match with regex', t => {
const commit = {type: 'docs', scope: 'README'};
const rules = [{type: 'docs', scope: /test\(.*\)/, release: 'minor'}];
const match = {type: 'docs', scope: 'test(readme): message'};
const notMatch = {type: 'docs', scope: 'test2(readme): message'};

t.is(analyzeCommit([{type: 'docs', scope: /RE..ME/, release: 'minor'}], commit), 'minor');
t.is(analyzeCommit(rules, match), 'minor');
t.is(analyzeCommit(rules, notMatch), undefined);
});

test('Match with regex as string', t => {
const commit = {type: 'docs', scope: 'README'};
const rules = [{type: 'docs', scope: '/test\\(.*\\)/', release: 'minor'}];
const match = {type: 'docs', scope: 'test(readme): message'};
const notMatch = {type: 'docs', scope: 'test2(readme): message'};

t.is(analyzeCommit([{type: 'docs', scope: '/RE..ME/', release: 'minor'}], commit), 'minor');
t.is(analyzeCommit(rules, match), 'minor');
t.is(analyzeCommit(rules, notMatch), undefined);
});

test('Return highest release type if multiple rules match', t => {
Expand Down

0 comments on commit 53faf3b

Please sign in to comment.