forked from buronnie/slack-command-open-pr
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
45 lines (41 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
40
41
42
43
44
45
const express = require('express');
const path = require('path');
const PORT = process.env.PORT || 5000;
const fetch = require('node-fetch');
const teamUsers = ['devongovett', 'fathyb'];
const colors = ['#81d2e0', '#49c4a1'];
function fetchUrl(user) {
return `https://api.github.com/search/issues?q=+author:${user}+is:open+type:pr`;
}
function createResponse(data) {
const resp = {
response_type: 'in_channel',
text: 'Open PRs',
attachments: []
};
data.forEach((prs, i) => {
resp.attachments.push({
color: colors[i],
pretext: teamUsers[i],
fields: prs.items.map(item => {
return {
value: item.html_url,
short: false,
}
}),
});
});
return resp;
}
express()
.post('/', (req, res) => {
Promise.all(teamUsers.map(user => fetch(fetchUrl(user))))
.then((arr) => {
return Promise.all(arr.map(resp => resp.json()));
})
.then(data => {
res.setHeader('Content-Type', 'application/json');
res.send(JSON.stringify(createResponse(data)));
});
})
.listen(PORT, () => console.log(`Listening on ${ PORT }`))