forked from dciccale/slack-dockerhub-integration
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
54 lines (43 loc) · 1.24 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
'use strict';
process.env.NODE_ENV = process.env.NODE_ENV || 'development';
var fs = require('fs');
var qs = require('querystring');
var Hapi = require('hapi');
var inert = require('inert');
var marked = require('marked');
var SlackService = require('./slack.service.js');
var server = new Hapi.Server();
var port = process.env.PORT || 8080;
server.connection({port: port});
server.register(inert, function () {});
var readme = fs.readFileSync(__dirname + '/README.md', 'utf8');
var docs = marked(readme);
server.route({
method: 'GET',
path:'/{param*}',
handler: function (req, res) {
res(docs);
}
});
server.route({
method: 'GET',
path: '/docker-logo.png',
handler: function (req, res) {
res.file(__dirname + '/docker-logo.png');
}
});
server.route({
method: 'POST',
path:'/services/{id*}',
handler: function (req, res) {
var slackService = new SlackService(req.params);
slackService.send({
text: '[<' + req.payload.repository.repo_url + '|' + req.payload.repository.repo_name + '>] new image build complete',
username: 'DockerHub',
icon_url: 'https://hooks-slack-dockerhub.herokuapp.com/docker-logo.png'
}, res);
}
});
server.start(function () {
console.log('Server listening on %d', port);
});