-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
68 lines (48 loc) · 1.69 KB
/
app.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
var application_root = __dirname,
express = require("express"),
path = require("path"),
rest = require('restler');
var express = require('express');
var bodyParser = require('body-parser');
var buildUrl = function (settings) {
var url = 'https://slack.com/api/chat.postMessage?' +
'token=' + settings.authToken +
'&channel=' + settings.channelId +
'&text=:scream:' + settings.text +
'&username=Git Master';
console.log(url);
return url;
};
fs = require('fs');
var token = fs.readFileSync('authToken.txt', 'utf8');
var app = express();
// parse application/json
app.use(bodyParser.json());
app.use(function (req, res, next) {
console.log(req.body); // populated!
var settings = {
text : req.body.changeset.author + ' pushed to ' + req.body.changeset.branches + ' with comment [' +
req.body.changeset.comment + '] http://gitlab.trad.tradestation.com/insight/sometaro/commit/' + req.body.changeset.csid,
// JSON.stringify(req.body),
//text : req.body.changeset.comment,
channelId : "G02EQ8WRX",
authToken: token
}
rest.get(buildUrl(settings)).on('complete', function (result) {
if (result instanceof Error) {
console.log('Error:', result.message);
this.retry(5000); // try again after 5 sec
} else {
console.log(result);
}
});
next();
});
app.post('/api', function (req, res) {
res.status(200).end();
});
//var port = process.env.PORT;
var port = 3000;
var server = app.listen(port, function () {
console.log('Listening on port %d', server.address().port);
});