This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hook.js
68 lines (51 loc) · 1.7 KB
/
hook.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
var mysecret = 'passphrase-to-run';
var port = 8181;
var http = require('http');
var script = './deploy.sh';
var createHandler = require('github-webhook-handler');
var handler = createHandler({ path: '/webhook', secret: mysecret });
var execFile = require('child_process').execFile;
var cathPhrase = '';
http.createServer(function (req, res) {
handler(req, res, function (err){
res.statusCode = 404;
res.end('no such location');
});
}).listen(port);
console.log('Hook server started at port %s', port);
console.log('Press CTRL+C to close sever');
handler.on('error', function (err) {
console.error('Error:', err.message);
});
var domagic = function (script){
execFile(script, function(error, stdout, stderr) {
if (stderr){
console.error( stderr );
}
else{
// Log success in some manner
console.log( stdout );
console.log( 'Deploy script exec complete' );
}
});
}
handler.on('release', function (event) {
console.log('Received release event for %s to %s',
event.payload.repository.name,
event.payload.ref);
if (event.payload.action == 'published'){
// Exec a shell script
domagic(script);
console.log ('Deploy sequence finished')
}
});
handler.on('pull_request', function (event) {
console.log('Received pull_request event for %s to %s',
event.payload.repository.name,
event.payload.ref);
if (event.payload.action == 'published'){
// Exec a shell script
domagic(script);
console.log ('Deploy sequence finished')
}
});