forked from nodejs/core-validate-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpr-url.js
64 lines (63 loc) · 1.44 KB
/
pr-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
const id = 'pr-url'
const prUrl = /^https:\/\/github\.com\/[\w-]+\/[\w-]+\/pull\/\d+\/?$/
export default {
id,
meta: {
description: 'enforce PR-URL',
recommended: true
},
defaults: {},
options: {},
validate: (context, rule) => {
if (!context.prUrl) {
context.report({
id,
message: 'Commit must have a PR-URL.',
string: context.prUrl,
line: 0,
column: 0,
level: 'fail'
})
return
}
let line = -1
let column = -1
for (let i = 0; i < context.body.length; i++) {
const l = context.body[i]
if (~l.indexOf('PR-URL') && ~l.indexOf(context.prUrl)) {
line = i
column = l.indexOf(context.prUrl)
}
}
if (context.prUrl[0] === '#') {
// see nodejs/node#7d3a7ea0d7df9b6f11df723dec370f49f4f87e99
// for an example
context.report({
id,
message: 'PR-URL must be a URL, not a pull request number.',
string: context.prUrl,
line,
column,
level: 'fail'
})
} else if (!prUrl.test(context.prUrl)) {
context.report({
id,
message: 'PR-URL must be a GitHub pull request URL.',
string: context.prUrl,
line,
column,
level: 'fail'
})
} else {
context.report({
id,
message: 'PR-URL is valid.',
string: context.prUrl,
line,
column,
level: 'pass'
})
}
}
}