-
Notifications
You must be signed in to change notification settings - Fork 62
Expand file tree
/
Copy pathreplyInvalidTitle.js
More file actions
61 lines (53 loc) · 1.63 KB
/
replyInvalidTitle.js
File metadata and controls
61 lines (53 loc) · 1.63 KB
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
/**
* @file PR 提示标题正确性
* @author xuexb <fe.xiaowu@gmail.com>
*/
const format = require('string-template')
const { getPkgCommitPrefix } = require('../../utils')
const {
commentPullRequest,
addLabelsToPullRequest,
removeLabelsToPullRequest,
pullRequestHasLabel
} = require('../../github')
const actions = getPkgCommitPrefix()
const match = title => {
return actions.some(action => title.indexOf(`${action}:`) === 0)
}
const commentSuccess = [
'hi @{user},非常感谢您及时修正标题格式,祝您玩的开心!'
].join('')
const commentError = [
'hi @{user},非常感谢您的 PR ,',
'但是您没有使用 [PR 标题规则](https://github.com/xuexb/github-bot#commit-log-和-pr-标题规则) 格式,',
'请及时修改, 谢谢!'
].join('')
module.exports = {
name: 'pullRequest/replyInvaidTitle',
register (on) {
if (actions.length) {
on('pull_request_opened', ({ payload, repo }) => {
if (!match(payload.pull_request.title)) {
commentPullRequest(
payload,
format(commentError, {
user: payload.pull_request.user.login
})
)
addLabelsToPullRequest(payload, 'invalid')
}
})
on('pull_request_edited', async ({ payload, repo }) => {
if (match(payload.pull_request.title) && await pullRequestHasLabel(payload, 'invalid')) {
commentPullRequest(
payload,
format(commentSuccess, {
user: payload.pull_request.user.login
})
)
removeLabelsToPullRequest(payload, 'invalid')
}
})
}
}
}