forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfixes-url.js
102 lines (89 loc) · 3.13 KB
/
fixes-url.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
'use strict'
const test = require('tap').test
const Rule = require('../../lib/rules/fixes-url')
const Commit = require('gitlint-parser-node')
const Validator = require('../../')
const INVALID_PRURL = 'Pull request URL must reference a comment or discussion.'
const NOT_AN_ISSUE_NUMBER = 'Fixes must be a URL, not an issue number.'
const NOT_A_GITHUB_URL = 'Fixes must be a GitHub URL.'
const VALID_FIXES_URL = 'Valid fixes URL.'
const makeCommit = (msg) => {
return new Commit({
sha: 'e7c077c610afa371430180fbd447bfef60ebc5ea'
, author: {
name: 'Evan Lucas'
, email: 'evanlucas@me.com'
, date: '2016-04-12T19:42:23Z'
}
, message: msg
}, new Validator())
}
test('rule: fixes-url', (t) => {
const valid = [
[ 'GitHub issue URL'
, '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'
, 'https://github.com/nodejs/node-report/issues/1234#issuecomment-1234' ]
, [ 'GitHub issue URL with comment'
, 'https://github.com/nodejs/node/issues/1234#issuecomment-1234' ]
, [ 'GitHub PR URL containing hyphen with comment'
, 'https://github.com/nodejs/node-report/pull/1234#issuecomment-1234' ]
, [ 'GitHub PR URL containing hyphen with discussion comment'
, 'https://github.com/nodejs/node-report/pull/1234#discussion_r1234' ]
, [ 'GitHub PR URL with comment'
, 'https://github.com/nodejs/node/pull/1234#issuecomment-1234' ]
, [ 'GitHub PR URL with discussion comment'
, 'https://github.com/nodejs/node/pull/1234#discussion_r1234' ]
]
for (const [name, url] of valid) {
t.test(name, (tt) => {
tt.plan(7)
const context = makeCommit(`test: fix something
Fixes: ${url}`
)
context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'fixes-url', 'id')
tt.equal(opts.message, VALID_FIXES_URL, 'message')
tt.equal(opts.string, url, 'string')
tt.equal(opts.line, 1, 'line')
tt.equal(opts.column, 7, 'column')
tt.equal(opts.level, 'pass', 'level')
}
Rule.validate(context)
})
}
const invalid = [
[ 'issue number', NOT_AN_ISSUE_NUMBER
, '#1234' ]
, [ 'GitHub PR URL', INVALID_PRURL
, 'https://github.com/nodejs/node/pull/1234' ]
, [ 'GitHub PR URL containing hyphen', INVALID_PRURL
, 'https://github.com/nodejs/node-report/pull/1234' ]
, [ 'non-GitHub URL', NOT_A_GITHUB_URL
, 'https://nodejs.org' ]
, [ 'not a URL or issue number', NOT_A_GITHUB_URL
, 'fhqwhgads' ]
]
for (const [name, expected, url] of invalid) {
t.test(name, (tt) => {
tt.plan(7)
const context = makeCommit(`test: fix something
Fixes: ${url}`
)
context.report = (opts) => {
tt.pass('called report')
tt.equal(opts.id, 'fixes-url', 'id')
tt.equal(opts.message, expected, 'message')
tt.equal(opts.string, url, 'string')
tt.equal(opts.line, 1, 'line')
tt.equal(opts.column, 7, 'column')
tt.equal(opts.level, 'fail', 'level')
}
Rule.validate(context)
})
}
t.end()
})