-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpull.js
More file actions
54 lines (46 loc) · 1.39 KB
/
pull.js
File metadata and controls
54 lines (46 loc) · 1.39 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
42
43
44
45
46
47
48
49
50
51
52
53
54
var exec=require("child_process").exec;
var sprintf=require("sprintf-js").sprintf;
var configDir=require("./configDir");
var config=require(configDir);
module.exports = function (data) {
var repo=data.repository.name.replace(/\s/g, ''),
payloadBranch=data.ref.split('/').pop(),
repoCfg=config.repositories[repo],
name=repoCfg.name,
basepath=repoCfg.basepath,
command=repoCfg.command,
branch=repoCfg.branch,
msg, cmd, proc;
if(payloadBranch != branch){
msg=sprintf(
"Branch '%s' is not defined, skipping.",
payloadBranch);
console.log(msg);
return undefined;
}
if(!repoCfg) {
msg=sprintf(
"Configuration for '%s' doesn't exist",
repo);
console.log(msg);
return undefined;
}
cmd=sprintf(
"cd %(basepath)s && %(command)s",
repoCfg);
console.log("Executing " + cmd +" process "+name);
proc=execCommand(cmd);
proc.on('exit', function (code, signal) {
console.log(sprintf("command %s exited with code %d", command, code));
});
return proc;
}
function execCommand(cmd) {
return exec(cmd, function(error, stdout, stderr) {
console.log('stdout: ', stdout);
console.log('stderr: ', stderr);
if (error !== null) {
console.log('exec error: ', error);
}
});
}