-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
41 lines (38 loc) · 1.02 KB
/
Copy pathindex.js
File metadata and controls
41 lines (38 loc) · 1.02 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
'use staric';
const http = require('http')
const createHandler = require('github-webhook-handler')
const handler = createHandler({ path: '/', secret: 'dhc-api' })
const child_process = require('child_process')
function execFunc(content) {
let spawn = child_process.spawn(content);
spawn.stdout.on('data', (data) => {
console.log('stdout: ' + data);
})
spawn.stderr.on('data', function (data) {
console.log('stderr: ' + data);
});
spawn.on('close', function (code) {
console.log('child process exited with code ' + code);
});
}
http.createServer((req, res) => {
handler(req, res, (err) => {
res.statusCode = 404;
res.end('no such location');
})
}).listen(7777, () => {
console.log('webhook is listen ...');
})
//
handler.on('error', (err) => {
console.error('Error:', err.message);
})
//
handler.on('push', (event) => {
console.log(
'Received a push event for %s to %s',
event.payload.repository.name,
event.payload.ref
);
execFunc('sh ./deploy.sh')
})