-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
67 lines (53 loc) · 1.87 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
var express = require('express');
var bodyParser = require('body-parser');
var Slack = require('node-slack');
var slack = new Slack(process.env.SLACK_HOOK_URL,'');
var app = express();
var port = process.env.PORT || 3000;
var getChannel = process.env.SLACK_CHANNEL;
app.use(bodyParser.json());
function sendNotif(msg, name, author, project) {
slack.send({
text: 'Nouveauté:',
channel: getChannel,
username: name,
attachments: [{"pretext": "", "text": "" + msg + "", "color":"#01B0F0", "fields": [{"title": "Fait par:", "value": "" + author + "", "short": "true"}, {"title": "Projet:", "value": "" + project + "", "short": "true"}]}],
icon_url: 'http://img15.hostingpics.net/pics/834337TechnicalSupport64.png'
});
}
function isCorect(messageToSend){
if(messageToSend.indexOf('merge') > -1 || messageToSend.indexOf('git.') > -1 || messageToSend.indexOf('pom.xml') > -1 || messageToSend.indexOf('.yml') > -1 || messageToSend.indexOf('!hide') > -1){
return false;
}
return true;
}
app.post('/gateway', function(req, res) {
var msg;
var author;
var project;
switch (req.body.object_kind) {
case 'push':
project = req.body.repository.name;
req.body.commits.forEach(function(item) {
author = item.author.name,
msg = item.message
})
break;
default:
break;
}
if(isCorect(msg)){
sendNotif(msg, 'UHBot', author, project);
}
res.sendStatus(200);
});
app.get('/', function (req, res) {
res.status(200).send('GitLab to Slack !')
});
app.use(function (err, req, res, next) {
console.error(err.stack);
res.status(400).send('Error: ' + err.message);
});
app.listen(port, function () {
console.log('Demarrage de gitlab2slack sur le port : ' + port);
});