-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
48 lines (40 loc) · 1.63 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
/**
* This is the main entrypoint to your Probot app
* @param {import('probot').Application} app
*/
module.exports = app => {
// Your code here
app.log('Yay, the app was loaded!')
app.on(['pull_request.opened', 'pull_request.closed', 'pull_request.reopened'], async (context) => {
context.log("Processing a pull request...")
context.log("Was merged?:", context.payload.pull_request.merged)
const query = 'bunny';
const url = `https://source.unsplash.com/random/?${query}`;
require('https').get(url, (res) => {
// this is slightly hacky as they are generating a redirection link
const bunny_link = res.headers.location;
context.log('Redirect target:', bunny_link);
if (context.payload.pull_request.merged & context.payload.action == 'closed') {
var praise = 'Good job on closing that one! Enjoy your reward:';
} else if (context.payload.action == 'opened') {
var praise = 'A new pull request, great! Look here...';
} else {
var praise = `Well, dunno what\'s goinng on. Grab a ${query} anyway:`;
}
const body = `${praise}\n![${query}](${bunny_link})`
const issueComment = context.issue({ body: body })
context.log("Commenting:", issueComment)
context.github.issues.createComment(issueComment)
});
function wait() {
return new Promise((resolve, reject) => {
setTimeout(() => resolve("hello"), 2000)
});
}
await wait();
})
// 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/
}