-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
74 lines (64 loc) · 2.27 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
'use strict';
const Hapi = require('hapi');
const Boom = require('boom');
const Wreck = require('wreck');
const Config = require('./config');
const server= Hapi.server(
{
host: '0.0.0.0',
port: 8080
}
);
server.route({
method:'POST',
path:'/services/{variableT}/{variableB}/{variableX}',
handler: async (request,h) => {
try {
const options = {
json: true,
payload: {
username: Config.get('/slack/username'),
icon_emoji: Config.get('/slack/icon'),
attachments: [
{
fallback: `${request.payload.repository.repo_name}`,
color: Config.get('/slack/color'),
title: `${request.payload.repository.repo_name}`,
title_link: request.payload.repository.repo_url,
text: `<!channel>`,
fields: [
{
title: 'Tag',
value: request.payload.push_data.tag,
short: true
},
{
title: 'Pusher',
value: request.payload.push_data.pusher,
short: true
}
],
footer: 'Posted via Docker Hub Slack',
ts: new Date().getTime()/1000
}
]
}
}
const { res, payload } = await Wreck.post(`https://hooks.slack.com/services/${request.params.variableT}/${request.params.variableB}/${request.params.variableX}`, options);
return payload;
} catch (err) {
throw Boom.boomify(err, { statusCode: err.statusCode, message: err.message });
}
}
});
async function start() {
try {
await server.start();
}
catch (err) {
console.log(err);
process.exit(1);
}
console.log('Docker Hub Slacker Online:', server.info.uri);
};
start();