Skip to content

Commit 55c5661

Browse files
committed
fix: allow only supported delimiter characters between keyword and issue ref
1 parent 5959468 commit 55c5661

File tree

4 files changed

+42
-14
lines changed

4 files changed

+42
-14
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,15 @@ FIX #1
214214
{actions: {close: [{raw: 'FIX #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}
215215
```
216216

217+
### Support delimiters between action keyword and issue
218+
219+
```text
220+
Fix: #1
221+
```
222+
```js
223+
{actions: {close: [{raw: 'Fix: #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}]}}
224+
```
225+
217226
### Ignore references in back-tick quotes
218227

219228
```text
@@ -342,6 +351,13 @@ Object with type of action as key and array of keywords as value.
342351

343352
Each keyword match will be placed in the corresponding property of the [`result`](#result) `action` object. For example the with the configuration `{actions: fix: ['fixed', 'fixing']}` each action matching `fixed` or `fixing` will be under `result.actions.fix`.
344353

354+
##### delimiters
355+
356+
Type: `Array<String>` `String`<br>
357+
Default: `[':']`
358+
359+
List of delimiter characters allowed between an action keywords and the issue reference. The characters space (` `) and tab (` `) are always allowed.
360+
345361
##### mentionsPrefixes
346362

347363
Type: `Array<String>` `String`<br>

index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -45,14 +45,12 @@ function buildMentionsRegexp({mentionsPrefixes}) {
4545
return `((?:(?:[^\\w\\n\\v\\r]|^)+(?:${join(mentionsPrefixes)})[\\w-\\.]+[^\\W])+)`;
4646
}
4747

48-
function buildRefRegexp({actions, issuePrefixes, issueURLSegments, hosts}) {
49-
return `(?:(?:[^\\w\\n\\v\\r]|^)+(${join([].concat(...Object.keys(actions).map(key => actions[key])))}))?(?:${[
50-
'[^\\w\\n\\v\\r]|^',
51-
join([...issuePrefixes, ...issueURLSegments]),
52-
].join('|')})+${hosts.length > 0 ? `(?:${join(hosts)})?` : ''}((?:(?:[\\w-\\.]+)\\/)+(?:[\\w-\\.]+))?(${join([
53-
...issuePrefixes,
54-
...issueURLSegments,
55-
])})(\\d+)(?!\\w)`;
48+
function buildRefRegexp({actions, delimiters, issuePrefixes, issueURLSegments, hosts}) {
49+
return `(?:(?:[^\\w\\n\\v\\r]|^)+(${join(
50+
[].concat(...Object.keys(actions).map(key => actions[key]))
51+
)}))?(?:[^\\w\\n\\v\\r]|^|(?: |\\t)*(?:${join([' ', '\t', ...delimiters])})(?: |\\t)*)${
52+
hosts.length > 0 ? `(?:${join(hosts)})?` : ''
53+
}((?:(?:[\\w-\\.]+)\\/)+(?:[\\w-\\.]+))?(${join([...issuePrefixes, ...issueURLSegments])})(\\d+)(?!\\w)`;
5654
}
5755

5856
function buildRegexp(opts) {
@@ -65,7 +63,7 @@ function buildRegexp(opts) {
6563
}
6664

6765
function buildMentionRegexp({mentionsPrefixes}) {
68-
return new RegExp(`(${join(mentionsPrefixes)})([\\w-.]+)`, 'gim');
66+
return new RegExp(`(${join(mentionsPrefixes)})([\\w-\\.]+)`, 'gim');
6967
}
7068

7169
function parse(text, regexp, mentionRegexp, {actions, issuePrefixes, hosts}) {

lib/hosts-config.js

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ module.exports = {
1010
// https://help.github.com/articles/about-duplicate-issues-and-pull-requests
1111
duplicate: ['Duplicate of'],
1212
},
13+
delimiters: [':'],
1314
// https://guides.github.com/features/issues/#notifications
1415
mentionsPrefixes: ['@'],
1516
issuePrefixes: ['#', 'gh-'],
@@ -39,6 +40,7 @@ module.exports = {
3940
childOf: [],
4041
duplicate: [],
4142
},
43+
delimiters: [],
4244
// https://confluence.atlassian.com/bitbucket/mark-up-comments-issues-and-commit-messages-321859781.html
4345
mentionsPrefixes: ['@'],
4446
// https://confluence.atlassian.com/bitbucket/mark-up-comments-issues-and-commit-messages-321859781.html
@@ -74,6 +76,7 @@ module.exports = {
7476
// https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/12845
7577
duplicate: ['/duplicate'],
7678
},
79+
delimiters: [],
7780
// https://about.gitlab.com/2016/03/08/gitlab-tutorial-its-all-connected
7881
mentionsPrefixes: ['@'],
7982
// https://about.gitlab.com/2016/03/08/gitlab-tutorial-its-all-connected
@@ -95,6 +98,7 @@ module.exports = {
9598
// https://help.github.com/articles/about-duplicate-issues-and-pull-requests
9699
duplicate: ['Duplicate of'],
97100
},
101+
delimiters: [':'],
98102
// https://guides.github.com/features/issues/#notifications
99103
mentionsPrefixes: ['@'],
100104
issuePrefixes: ['#', 'gh-'],
@@ -127,6 +131,7 @@ module.exports = {
127131
childOf: ['child of', 'child to', 'child'],
128132
duplicate: ['Duplicate of', '/duplicate'],
129133
},
134+
delimiters: [':'],
130135
mentionsPrefixes: ['@'],
131136
issuePrefixes: ['#', 'gh-'],
132137
hosts: ['https://github.com', 'https://gitlab.com'],

test/index.test.js

+14-5
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import m from '..';
44
test('Parse GitHub issue', t => {
55
t.deepEqual(
66
m('GitHub')(
7-
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fix o/r#4 #5 o/r#6 fix https://github.com/o/r/issues/7 https://github.com/o/r/issues/8 fix https://github.com/o/r/pull/9 https://github.com/o/r/pull/10 fixing #11 Duplicate OF #12 @user'
7+
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fix o/r#4 #5 o/r#6 fix https://github.com/o/r/issues/7 https://github.com/o/r/issues/8 fix https://github.com/o/r/pull/9 https://github.com/o/r/pull/10 fixing #11 Duplicate OF #12 Fix:#13 Fix: #14 Fix::#15 @user'
88
),
99
{
1010
actions: {
@@ -15,6 +15,8 @@ test('Parse GitHub issue', t => {
1515
{raw: 'fix o/r#4', action: 'Fix', slug: 'o/r', prefix: '#', issue: '4'},
1616
{raw: 'fix https://github.com/o/r/issues/7', action: 'Fix', slug: 'o/r', prefix: undefined, issue: '7'},
1717
{raw: 'fix https://github.com/o/r/pull/9', action: 'Fix', slug: 'o/r', prefix: undefined, issue: '9'},
18+
{raw: 'Fix:#13', action: 'Fix', slug: undefined, prefix: '#', issue: '13'},
19+
{raw: 'Fix: #14', action: 'Fix', slug: undefined, prefix: '#', issue: '14'},
1820
],
1921
duplicate: [{raw: 'Duplicate OF #12', action: 'Duplicate of', slug: undefined, prefix: '#', issue: '12'}],
2022
},
@@ -24,6 +26,7 @@ test('Parse GitHub issue', t => {
2426
{raw: 'https://github.com/o/r/issues/8', slug: 'o/r', prefix: undefined, issue: '8'},
2527
{raw: 'https://github.com/o/r/pull/10', slug: 'o/r', prefix: undefined, issue: '10'},
2628
{raw: '#11', slug: undefined, prefix: '#', issue: '11'},
29+
{raw: '#15', slug: undefined, prefix: '#', issue: '15'},
2730
],
2831
mentions: [{raw: '@user', prefix: '@', user: 'user'}],
2932
}
@@ -130,7 +133,7 @@ test('Parse Waffle issue', t => {
130133
test('Parse with default options', t => {
131134
t.deepEqual(
132135
m()(
133-
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fix o/r#4 #5 o/r#6 implementing #7 https://github.com/o/r/issues/8 implementing https://github.com/o/r/issues/9 Duplicate OF #10 @user'
136+
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fix o/r#4 #5 o/r#6 implementing #7 https://github.com/o/r/issues/8 implementing https://github.com/o/r/issues/9 Duplicate OF #10 Fix: #11 @user'
134137
),
135138
{
136139
actions: {
@@ -147,6 +150,7 @@ test('Parse with default options', t => {
147150
prefix: undefined,
148151
issue: '9',
149152
},
153+
{raw: 'Fix: #11', action: 'Fix', slug: undefined, prefix: '#', issue: '11'},
150154
],
151155
block: [],
152156
require: [],
@@ -167,17 +171,22 @@ test('Parse with default options', t => {
167171
test('Parse with custom options', t => {
168172
t.deepEqual(
169173
m({
170-
actions: {close: ['fix'], fix: ['fix'], duplicate: undefined},
174+
actions: {close: ['fix', 'close'], fix: ['fix'], duplicate: undefined},
175+
delimiters: [':', '*'],
171176
mentionsPrefixes: '!',
172177
issuePrefixes: ['#'],
173178
hosts: ['http://host1.com/', 'http://host2.com'],
174179
issueURLSegments: ['bugs'],
175180
})(
176-
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fixed o/r#4 #5 o/r#6 fixing #7 http://host1.com/o/r/bugs/8 http://host2.com/o/r/bugs/9 Duplicate OF #10 !user @other'
181+
'Fix #1 reSOLved gh-2 CLOSES Gh-3 fixed o/r#4 #5 o/r#6 fixing #7 http://host1.com/o/r/bugs/8 http://host2.com/o/r/bugs/9 Duplicate OF #10 Close:#11 Close* #12 !user @other'
177182
),
178183
{
179184
actions: {
180-
close: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}],
185+
close: [
186+
{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'},
187+
{raw: 'Close:#11', action: 'Close', slug: undefined, prefix: '#', issue: '11'},
188+
{raw: 'Close* #12', action: 'Close', slug: undefined, prefix: '#', issue: '12'},
189+
],
181190
fix: [{raw: 'Fix #1', action: 'Fix', slug: undefined, prefix: '#', issue: '1'}],
182191
block: [],
183192
require: [],

0 commit comments

Comments
 (0)