@@ -3,10 +3,13 @@ process.env.PORT = process.env.PORT || 6666;
3
3
//Rewrite for logging to files
4
4
var dbg = true ;
5
5
function log ( msg , file ) {
6
- if ( dbg && file ) {
6
+ if ( file ) {
7
7
//Write to file
8
8
} else {
9
9
console . log ( msg ) ;
10
+ if ( dbg && typeof msg == 'object' ) {
11
+ console . dir ( msg ) ;
12
+ }
10
13
}
11
14
12
15
return false ;
@@ -37,7 +40,7 @@ var processFile = function(fileName){
37
40
throw new Error ( 'Bad config file "' + filePath + '". It need to be json object with path, user and commands keys.' ) ;
38
41
}
39
42
} catch ( e ) {
40
- return log ( e ) ;
43
+ return log ( 'Error while processing file "' + filePath + '": ' + e ) ;
41
44
}
42
45
//Populate good cfg object to objects map by filename without extension
43
46
return cfg_map [ path . basename ( fileName , fileExt ) ] = cfg ;
@@ -82,6 +85,9 @@ http.createServer(function(request, response) {
82
85
} ) ;
83
86
84
87
request . on ( 'end' , function ( ) {
88
+ var bodyObj = JSON . parse ( body . trim ( ) )
89
+ log ( body ) ;
90
+
85
91
var cfg = cfg_map [ request . url ] ;
86
92
var spawn_options = {
87
93
encoding : "utf-8" ,
@@ -92,14 +98,28 @@ http.createServer(function(request, response) {
92
98
if ( ! fs . readdirSync ( cfg . path ) ) {
93
99
return log ( 'Invalid path "' + cfg . path + '" in config "' + request . url + '"' ) ;
94
100
}
95
- spawn_options . path = cfg . path ;
101
+ spawn_options . cwd = cfg . path ;
102
+
103
+ var refsType = typeof cfg . refs ;
104
+ if ( [ 'string' , 'object' ] . indexOf ( refsType = typeof cfg . refs ) ) {
105
+ if ( refsType == 'string' ) cfg . refs = [ cfg . refs ] ;
106
+ var cont = false ;
107
+ for ( var key in cfg . refs ) {
108
+ if ( bodyObj . ref . match ( cfg . refs [ key ] ) ) {
109
+ cont = true ;
110
+ break ;
111
+ }
112
+ }
113
+ if ( ! cont ) return log ( 'No refs match. Aborting.' ) ;
114
+ }
96
115
97
116
if ( cfg . commands . length ) {
98
117
var handleExec = function ( err , stdout , stderr ) {
99
118
if ( err ) { log ( err ) ; }
100
119
101
120
102
121
} ;
122
+
103
123
for ( var i in cfg . commands ) {
104
124
var commandArray = cfg . commands [ i ] ;
105
125
var commandString = commandArray . join ( ' ' ) ;
@@ -115,7 +135,6 @@ http.createServer(function(request, response) {
115
135
}
116
136
}
117
137
//Do work according to hook data
118
- log ( body ) ;
119
138
} ) ;
120
139
}
121
140
// on every request, we'll output 'Hello world'
0 commit comments