-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
39 lines (36 loc) · 1.05 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
const requestp = require('request-promise')
const addComment = (url, body, token) => requestp({
url,
json: true,
headers: {
'Authorization': 'token ' + token,
'User-Agent': process.env.APP_NAME,
'Accept': 'application/vnd.github.machine-man-preview+json'
},
method: 'POST',
body: {
body
}
})
const commentsURL = process.env.COMMENTS_URL
if (typeof commentsURL === 'undefined') {
console.error('No comments_url defined!')
} else {
if (typeof process.env.TOKEN === 'undefined') {
console.error('No token defined! Abort.')
} else {
const timeToWait = process.env.WAIT_MS || 120000 // 2 minutes
console.log(`waiting before doing a comment for ${timeToWait} ms.`)
setTimeout(() => {
console.log('now doing a comment')
addComment(commentsURL, process.env.COMMENT, process.env.TOKEN)
.then((response) => {
console.log('Response: ' + response)
return response
}).catch((error) => {
console.error(error)
})
}, timeToWait)
}
}
module.exports = { addComment }