forked from nextcloud/backportbot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 1.56 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
58
59
60
61
62
63
64
65
66
const pr = require('./lib/pr.js')
const comment = require('./lib/comment.js')
const backport = require('./lib/backport.js')
module.exports = app => {
app.on('issue_comment.created', async context => {
const payload = context.payload
if (!payload.issue.html_url.endsWith('pull/' + payload.issue.number)) {
// Ignore normal issues
app.log("NOT A PR!")
return
}
const target = comment.match(payload.comment.body);
if (target === false) {
app.log('Ignore')
return;
}
comment.plusOne(context, payload.comment.id)
pr.addLabel(context)
if (!(await pr.isMerged(context, payload.issue.number))) {
app.log("PR is not yet merged just carry on")
return
}
const success = await backport(context, context.issue.number, [target])
if (success) {
pr.removeLabel(context)
}
})
app.on('pull_request.closed', async context => {
const params = context.issue()
const comments = await context.github.issues.getComments(params)
// Obtain all targets
let targets = []
for (const {body, id} of comments.data) {
const target = comment.match(body)
if (target !== false) {
targets.push(target)
comment.plusOne(context, id)
pr.addLabel(context)
}
}
if (targets.length === 0) {
app.log('Nothing to backport')
return
}
//TODO filter same backport requests
app.log(targets)
const success = await backport(context, context.issue.number, targets)
if (success) {
pr.removeLabel(context)
}
})
}