-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
57 lines (42 loc) · 1.48 KB
/
index.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
const titleRegex = /(\w*)(?:\((\w*)\))?: (.*)/
const {getType, hasTitleChanged} = require('./utils')
module.exports = app => {
app.on(['pull_request.opened'], async context => {
const {owner, repo} = context.repo()
app.log(`------ receiving pull_request.opened webhook: ${owner}/${repo} ------`)
const {
payload: {
pull_request: {title, labels}
}
} = context
let label = getType(title)
if(!label) return
if (labels.some(l => l.name === label)) return
app.log('------ begin to process ------')
const newLabels = labels.map(l => l.name).concat(label)
context.github.issues.addLabels(context.issue({labels: newLabels}))
context.log(`Using label:`, newLabels)
})
app.on(['pull_request.edited'], async context => {
const {owner, repo} = context.repo()
app.log(`------ receiving pull_request.edited webhook: ${owner}/${repo} ------`)
const {
payload: {
pull_request: {title, labels},
changes
}
} = context
let label = getType(title)
if(!label) return
// if (!hasTitleChanged(title, changes)) return
if (labels.some(l => l.name === label)) return
app.log('------ begin to process ------')
let oldLabel = getType(changes.title.from)
const newLabels = labels
.filter(l => l.name != oldLabel)
.map(l => l.name)
.concat(label)
context.github.issues.replaceLabels(context.issue({labels: newLabels}))
context.log(`Using label:`, newLabels)
})
}