Repository navigation
Expand file tree
/
Copy pathserver.js
More file actions
executable file
·58 lines (43 loc) · 1.49 KB
/
Copy pathserver.js
File metadata and controls
executable file
·58 lines (43 loc) · 1.49 KB
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
#!/usr/bin/env node
var Hapi = require('hapi'),
config = require('config'),
spawn = require('child_process').spawn,
fs = require('fs'),
Hoek = require('hoek'),
http = require('request');
var configFile = './config/default.json';
Hoek.assert(fs.existsSync('./config/default.json'), 'No config file found. Looking for '+configFile);
Hoek.assert(config.events && config.events.push, 'Push script should be specified in config.events.push');
var server = new Hapi.Server();
server.connection({ port: process.env.PORT || 3000 });
server.route({
method: 'POST',
path: '/hub/push',
handler: function (request, reply) {
var script = spawn('sh', [ config.events.push, request.payload.repository.repo_name ], {});
script.stdout.on('data', function (data) {
console.log('stdout: ' + data);
});
script.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
script.on('close', function (code) {
console.log('child process exited with code ' + code);
var options = {
json: true,
body: {state: 'success'},
method: 'post',
uri: request.payload.callback_url
};
http(options, function(err, response, body) {
if (err) {
console.error(err);
}
reply();
})
});
}
});
server.start(function () {
console.log('Server running at:', server.info.uri);
});