-
Notifications
You must be signed in to change notification settings - Fork 22
/
Copy pathserver.js
33 lines (25 loc) · 909 Bytes
/
server.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
'use strict';
var express = require('express');
var bodyParser = require('body-parser');
var logfmt = require('logfmt');
var config = require('./lib/config');
var slackService = require('./lib/slackService');
var bitbucketParser = require('./lib/bitbucketParser');
var app = express();
app.use(logfmt.requestLogger());
app.use(bodyParser.json());
app.get('/', function (req, res) {
res.send('Set your repository\'s Pull Request POST hook to this page\'s URL.');
});
app.post('*', function (req, res) {
var channel = req.path.substring(1);
var eventKey = req.headers['x-event-key'];
var message = bitbucketParser.generateMessage(req.body, eventKey);
if (message !== undefined) {
slackService.sendMessage(message, channel);
}
res.status(200).end();
});
app.listen(config.port, function () {
console.log('BitBucket PR Hook bridge listening on:', config.port);
});