forked from JanDeDobbeleer/github-tools
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
50 lines (42 loc) · 1.4 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
/*jshint esversion: 6*/
var express = require('express');
var bodyParser = require('body-parser');
var xhub = require('express-x-hub');
var fixup = require('./modules/fixup');
var requirements = require('./modules/requirements');
var app = express();
// settings
app.use(xhub({ algorithm: 'sha1', secret: process.env.XHUB_SECRET }));
app.use(bodyParser.json()); // for parsing application/json
var port = process.env.PORT || 3000;
var authenticateAndRespond = function(req, res, handler) {
var isValid = req.isXHubValid();
if (!isValid) {
res.status(404).end();
return;
}
res.status(200).end();
handler();
};
app.get('/', function(req, res) {
res.send('hello world from GitHub tools!');
});
app.post('/github-fixup-hook', function(req, res) {
authenticateAndRespond(req, res, function() {
fixup.checkFixupCommits(
req.body.pull_request.number,
req.body.pull_request.head.repo.full_name,
req.body.pull_request.head.sha);
});
});
app.post('/github-requirements-hook', function(req, res) {
authenticateAndRespond(req, res, function() {
requirements.verifyForInvalidVersionUpgrades(
req.body.pull_request.number,
req.body.pull_request.head.repo.full_name,
req.body.pull_request.head.sha);
});
});
app.listen(port, function() {
console.log(`App listening on port ${port}!`);
});