-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
48 lines (43 loc) · 1.26 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
var http = require("http");
var createHandler = require("/usr/local/node-v12/lib/node_modules/github-webhook-handler");
var handler = createHandler({ path: "/", secret: "123456" });
function RunCmd(cmd, args, cb) {
var spawn = require("child_process").spawn;
var child = spawn(cmd, args);
var result = "";
child.stdout.on("data", function(data) {
result += data.toString();
});
child.stdout.on("end", function() {
cb(result);
});
}
http.createServer(function(req, res) {
handler(req, res, function(err) {
res.statusCode = 404;
res.end("no such location");
});
}).listen(3000);
handler.on("error", function(err) {
console.error("Error:", err.message);
});
handler.on("push", function(event) {
console.log(
"Received a push event for %s to %s",
event.payload.repository.name,
event.payload.ref
);
var shpath = "./start.sh";
RunCmd("sh", [shpath], function(result) {
console.log(result);
});
});
handler.on("issues", function(event) {
console.log(
"Received an issue event for %s action=%s: #%d %s",
event.payload.repository.name,
event.payload.action,
event.payload.issue.number,
event.payload.issue.title
);
});