Skip to content

Commit 1d25802

Browse files
committed
rules: allow GitHub URLs containing hyphens
GitHub user and organization names and repository names can contain hyphen characters which are not included in the `\w` regular expression character class.
1 parent 8e70c12 commit 1d25802

File tree

4 files changed

+35
-2
lines changed

4 files changed

+35
-2
lines changed

lib/rules/fixes-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const id = 'fixes-url'
4-
const github = new RegExp('^https://github\.com/\\w+\/\\w+/' +
4+
const github = new RegExp('^https://github\.com/[\\w-]+\/[\\w-]+/' +
55
'(issues|pull)/\\d+(#issuecomment-\\d+|#discussion_r\\d+)?$'
66
)
77

lib/rules/pr-url.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
'use strict'
22

33
const id = 'pr-url'
4-
const prUrl = /^https:\/\/github\.com\/\w+\/\w+\/pull\/\d+$/
4+
const prUrl = /^https:\/\/github\.com\/[\w-]+\/[\w-]+\/pull\/\d+$/
55

66
module.exports = {
77
id: id

test/rules/fixes-url.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,16 @@ test('rule: fixes-url', (t) => {
2626
const valid = [
2727
[ 'GitHub issue URL'
2828
, 'https://github.com/nodejs/node/issues/1234' ]
29+
, [ 'GitHub issue URL containing hyphen'
30+
, 'https://github.com/nodejs/node-report/issues/1234' ]
31+
, [ 'GitHub issue URL containing hyphen with comment'
32+
, 'https://github.com/nodejs/node-report/issues/1234#issuecomment-1234' ]
2933
, [ 'GitHub issue URL with comment'
3034
, 'https://github.com/nodejs/node/issues/1234#issuecomment-1234' ]
35+
, [ 'GitHub PR URL containing hyphen with comment'
36+
, 'https://github.com/nodejs/node-report/pull/1234#issuecomment-1234' ]
37+
, [ 'GitHub PR URL containing hyphen with discussion comment'
38+
, 'https://github.com/nodejs/node-report/pull/1234#discussion_r1234' ]
3139
, [ 'GitHub PR URL with comment'
3240
, 'https://github.com/nodejs/node/pull/1234#issuecomment-1234' ]
3341
, [ 'GitHub PR URL with discussion comment'
@@ -61,6 +69,8 @@ Fixes: ${url}`
6169
, '#1234' ]
6270
, [ 'GitHub PR URL', INVALID_PRURL
6371
, 'https://github.com/nodejs/node/pull/1234' ]
72+
, [ 'GitHub PR URL containing hyphen', INVALID_PRURL
73+
, 'https://github.com/nodejs/node-report/pull/1234' ]
6474
, [ 'non-GitHub URL', NOT_A_GITHUB_URL
6575
, 'https://nodejs.org' ]
6676
, [ 'not a URL or issue number', NOT_A_GITHUB_URL

test/rules/pr-url.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,5 +95,28 @@ test('rule: pr-url', (t) => {
9595
Rule.validate(context)
9696
})
9797

98+
t.test('valid URL containing hyphen', (tt) => {
99+
tt.plan(7)
100+
const url = 'https://github.com/nodejs/node-report/pull/1234'
101+
const context = {
102+
prUrl: url
103+
, body: [
104+
''
105+
, `PR-URL: ${url}`
106+
]
107+
, report: (opts) => {
108+
tt.pass('called report')
109+
tt.equal(opts.id, 'pr-url', 'id')
110+
tt.equal(opts.message, VALID_PR_URL, 'message')
111+
tt.equal(opts.string, url, 'string')
112+
tt.equal(opts.line, 1, 'line')
113+
tt.equal(opts.column, 8, 'column')
114+
tt.equal(opts.level, 'pass', 'level')
115+
}
116+
}
117+
118+
Rule.validate(context)
119+
})
120+
98121
t.end()
99122
})

0 commit comments

Comments
 (0)