Skip to content

Commit 53faf3b

Browse files
committed
fix: fix regex rules evaluation
1 parent 67f9f88 commit 53faf3b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

lib/analyze-commit.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ module.exports = (releaseRules, commit) => {
2121
commit,
2222
omit(rule, ['release', 'breaking']),
2323
(obj, src) =>
24-
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/.*\/$/.exec(src)[1]).test(obj) : undefined
24+
/^\/.*\/$/.test(src) || isRegExp(src) ? new RegExp(/^\/(.*)\/$/.exec(src)[1]).test(obj) : undefined
2525
)
2626
)
2727
.every(match => {

test/analyze-commit.test.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,21 @@ test('Return undefined if there is no match', t => {
4646
});
4747

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

51-
t.is(analyzeCommit([{type: 'docs', scope: /RE..ME/, release: 'minor'}], commit), 'minor');
53+
t.is(analyzeCommit(rules, match), 'minor');
54+
t.is(analyzeCommit(rules, notMatch), undefined);
5255
});
5356

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

57-
t.is(analyzeCommit([{type: 'docs', scope: '/RE..ME/', release: 'minor'}], commit), 'minor');
62+
t.is(analyzeCommit(rules, match), 'minor');
63+
t.is(analyzeCommit(rules, notMatch), undefined);
5864
});
5965

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

0 commit comments

Comments
 (0)