Skip to content

Commit

Permalink
fix: support trailing slash (#120)
Browse files Browse the repository at this point in the history
* fix: add support to trailing slash in PR-URL

* fix: add support to trailing slash in Fixes

* Update lib/rules/fixes-url.js

Co-authored-by: Rich Trott <rtrott@gmail.com>

---------

Co-authored-by: Rich Trott <rtrott@gmail.com>
  • Loading branch information
RafaelGSS and Trott authored Jul 17, 2024
1 parent 006aedd commit 67c75e0
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/rules/fixes-url.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const id = 'fixes-url'
const github = new RegExp('^https://github\\.com/[\\w-]+/[\\w-]+/' +
'(issues|pull)/\\d+(#issuecomment-\\d+|#discussion_r\\d+)?$'
'(issues|pull)/\\d+(#issuecomment-\\d+|#discussion_r\\d+)?/?$'
)

export default {
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/pr-url.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
const id = 'pr-url'
const prUrl = /^https:\/\/github\.com\/[\w-]+\/[\w-]+\/pull\/\d+$/
const prUrl = /^https:\/\/github\.com\/[\w-]+\/[\w-]+\/pull\/\d+\/?$/

export default {
id,
Expand Down
2 changes: 2 additions & 0 deletions test/rules/fixes-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ test('rule: fixes-url', (t) => {
const valid = [
['GitHub issue URL',
'/~https://github.com/nodejs/node/issues/1234'],
['GitHub issue URL with trailing slash',
'/~https://github.com/nodejs/node/issues/1234/'],
['GitHub issue URL containing hyphen',
'/~https://github.com/nodejs/node-report/issues/1234'],
['GitHub issue URL containing hyphen with comment',
Expand Down
23 changes: 23 additions & 0 deletions test/rules/pr-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,5 +115,28 @@ test('rule: pr-url', (t) => {
Rule.validate(context)
})

t.test('valid URL with trailing slash', (tt) => {
tt.plan(7)
const url = '/~https://github.com/nodejs/node-report/pull/1234/'
const context = {
prUrl: url,
body: [
'',
`PR-URL: ${url}`
],
report: (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'pr-url', 'id')
tt.equal(opts.message, VALID_PR_URL, 'message')
tt.equal(opts.string, url, 'string')
tt.equal(opts.line, 1, 'line')
tt.equal(opts.column, 8, 'column')
tt.equal(opts.level, 'pass', 'level')
}
}

Rule.validate(context)
})

t.end()
})

0 comments on commit 67c75e0

Please sign in to comment.