forked from jimyhuang/gitlab-pull-webhook
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pull.js
42 lines (34 loc) · 982 Bytes
/
pull.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
var spawn=require("child_process").spawn;
var sprintf=require("sprintf-js").sprintf;
var path=require("path");
var config=require("./config.js");
module.exports = function (repo) {
var repoCfg=config.repositories[repo],
dir=repoCfg.dir,
msg, cmd, proc;
if(!repoCfg) {
msg=sprintf(
"Configuration for '%s' doesn't exist",
repo);
console.log(msg);
return undefined;
}
// Spawn a new git process.
cmd=sprintf(
"/usr/bin/sudo -u %(user)s -g %(group)s -H git pull",
repoCfg);
console.log("Executing " + cmd);
proc=spawnCommand(cmd, dir);
proc.on('exit', function (code, signal) {
console.log(sprintf("git pull on %s exited with code %d", dir, code));
});
return proc;
}
function spawnCommand(cmd, dir) {
var args=cmd.split(" ");
cmd=args.splice(0, 1)[0];
return spawn(cmd, args, {
"cwd": dir,
"env" : process.env
});
}