-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
85 lines (79 loc) · 2.67 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
const readFileSync = require('fs').readFileSync
const rp = require('request-promise-native')
const tpl = (str, data) => {
return str.replace(/\{\{(.+?)\}\}/g, function (match) {
return data.shift() || match
})
}
module.exports = app => {
// Your code here
app.log('Yay, the app was loaded!')
app.on('issues.opened', async context => {
try {
const payload = context.payload
const options = {
method: 'POST',
uri: 'webhooks/github',
baseUrl: 'https://gitpay.me/',
body: payload,
simple: true,
resolveWithFullResponse: true,
followRedirect: false,
followAllRedirects: false,
json: true, // Automatically stringifies the body to JSON
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
}
const request = await rp(options)
const bodyJSON = request.body
const taskData = bodyJSON.task
const template = readFileSync('./first-comment.md', 'utf8')
const commentContent = template.toString()
const parsedCommentContent = tpl(commentContent, [taskData.url, taskData.url])
console.log(parsedCommentContent)
const issueComment = context.issue({ body: parsedCommentContent })
return context.github.issues.createComment(issueComment)
} catch (e) {
console.log(e)
throw new Error(e)
}
})
app.on('issues.labeled', async context => {
try {
const payload = context.payload
console.log(context.payload)
const options = {
method: 'POST',
uri: 'webhooks/github',
baseUrl: 'https://gitpay.me/',
body: payload,
simple: true,
resolveWithFullResponse: true,
followRedirect: false,
followAllRedirects: false,
json: true, // Automatically stringifies the body to JSON
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${process.env.TOKEN}`
}
}
const request = await rp(options)
const bodyJSON = request.body
const taskData = bodyJSON.task
const template = readFileSync('./notify-comment.md', 'utf8')
const commentContent = template.toString()
const parsedCommentContent = tpl(commentContent, [taskData.url])
const issueComment = context.issue({ body: parsedCommentContent })
return context.github.issues.createComment(issueComment)
} catch (e) {
console.log(e)
throw new Error(e)
}
})
// For more information on building apps:
// https://probot.github.io/docs/
// To get your app running against GitHub, see:
// https://probot.github.io/docs/development/
}