-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupdater.js
39 lines (33 loc) · 1.15 KB
/
updater.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
var simpleGit = require('simple-git')('./');
var config = require('./config.js')();
if (!config.exists("updater", "port")) {
console.error("You need to specify a port for the updater to liston on for webhooks!");
process.exit(1);
}
if (!config.exists("updater", "secret")) {
console.warn("You didn't specifiy a secret! Not using a secret makes this updater runable by whoever can reach it.");
}
var http = require('http');
var createHandler = require('github-webhook-handler');
var handler = createHandler({
path: config.get("updater", "path") || "/",
secret: config.get("updater", "secret")
});
http.createServer(function (req, res) {
handler(req, res, function (err) {
res.statusCode = 404;
res.end('');
});
}).listen(config.get("updater", "port"));
handler.on('error', function (err) {
console.error('Error:', err.message);
});
handler.on('push', function (event) {
simpleGit.pull(function(err, update) {
if(update && update.summary.changes) {
// restart the app by installing dependencies and touching a restart file for nodemon
require('child_process').exec('npm install && touch updated.nodemon');
}
});
});
console.log("test");