@@ -173,19 +173,58 @@ class Pipeline {
173
173
ev . sender . send ( 'data-pipeline-log-callback' , utils . serialize ( err ) , result ) ;
174
174
}
175
175
try {
176
- let index = 1 ;
177
-
176
+ let pipeline = this . storage . get ( arg . id ) ;
177
+ if ( pipeline . deployResult && pipeline . deployResult . done != true ) {
178
+ // Uncompleted deploy, clean cache and reload
179
+ this . storage . getAll ( { cache : false } ) ;
180
+ pipeline = this . storage . get ( arg . id ) ;
181
+ }
178
182
const metadata = new Metadata ( ) ;
179
183
const pPath = metadata . getPipelineFolder ( ) ;
180
- const logPath = path . join ( pPath , arg . id , 'pipeline.log' ) ;
184
+ const logPath = path . join ( pPath , pipeline . id , 'pipeline.log' ) ;
181
185
if ( ! fs . existsSync ( logPath ) ) {
182
186
return callback ( null ) ;
183
187
}
184
188
fs . readFile ( logPath , 'utf-8' , function ( err , data ) {
185
189
//console.log('>>> getPipelineLog' + index, (new Date()));
186
- index ++ ;
187
190
if ( err ) return callback ( err ) ;
188
- const result = data ;
191
+ // read deployResult
192
+ const drPath = path . join ( pPath , pipeline . id , 'deployResult.json' ) ;
193
+ let deployResult = { } ;
194
+ if ( fs . existsSync ( drPath ) ) {
195
+ deployResult = JSON . parse ( fs . readFileSync ( drPath ) ) ;
196
+ }
197
+ const result = { body : data , deployResult : deployResult } ;
198
+ return callback ( null , result ) ;
199
+ } ) ;
200
+ } catch ( err ) {
201
+ console . error ( '[ERROR]' , err ) ;
202
+ Raven . captureException ( err ) ;
203
+ return callback ( err ) ;
204
+ }
205
+ }
206
+
207
+ /**
208
+ * Export pipeline metadata zip file
209
+ * @param {Object } ev
210
+ * @param {Object } arg
211
+ */
212
+ exportMetadata ( ev , arg ) {
213
+ const callback = function ( err , result ) {
214
+ ev . sender . send ( 'data-pipeline-export-metadata-callback' , utils . serialize ( err ) , result ) ;
215
+ }
216
+ try {
217
+ const metadata = new Metadata ( ) ;
218
+ const pPath = metadata . getPipelineFolder ( ) ;
219
+ const packagePath = path . join ( pPath , arg . id , 'package.zip' ) ;
220
+ if ( ! fs . existsSync ( packagePath ) ) {
221
+ return callback ( null ) ;
222
+ }
223
+ fs . readFile ( packagePath , 'base64' , function ( err , data ) {
224
+ //new Buffer(data).toString('base64')
225
+ //console.log('>>> getPipelineLog' + index, (new Date()));
226
+ if ( err ) return callback ( err ) ;
227
+ const result = { data : data } ;
189
228
return callback ( null , result ) ;
190
229
} ) ;
191
230
} catch ( err ) {
@@ -229,6 +268,7 @@ class Pipeline {
229
268
const pPath = metadata . mkdirPipelineFolder ( pipeline . id ) ;
230
269
231
270
const logPath = path . join ( pPath , 'pipeline.log' ) ;
271
+ const deployResultPath = path . join ( pPath , 'deployResult.json' ) ;
232
272
const pipelineLog = function ( line ) {
233
273
line = moment ( ) . format ( 'HH:mm:ss' ) + ' ' + line + '\n' ;
234
274
fs . appendFileSync ( logPath , line ) ;
@@ -288,20 +328,22 @@ class Pipeline {
288
328
// Do Destruct
289
329
opts [ 'purgeOnDelete' ] = true ;
290
330
return metadata . deploy ( fromConn , zipPath , opts , function ( deployResult ) {
331
+ deployResult = self . saveDeployResult ( deployResultPath , fromConn , deployResult ) ;
291
332
self . outputDeployProcessLog ( pipelineLog , deployResult ) ;
292
333
} ) ;
293
334
} else {
294
335
// Do Deploy
295
336
opts [ 'runAllTests' ] = ( pipeline . runTests === true ) ;
296
337
return metadata . deploy ( toConn , zipPath , opts , function ( deployResult ) {
338
+ deployResult = self . saveDeployResult ( deployResultPath , toConn , deployResult ) ;
297
339
self . outputDeployProcessLog ( pipelineLog , deployResult ) ;
298
340
} ) ;
299
341
}
300
342
} )
301
343
. then ( function ( deployResult ) {
302
344
// Save deploy result
303
345
const targetConn = ( pipeline . action == 'destruct' ) ? fromConn : toConn ;
304
- deployResult [ 'url' ] = targetConn . instanceUrl + '/changemgmt/monitorDeploymentsDetails.apexp?asyncId=' + deployResult . id
346
+ deployResult = self . saveDeployResult ( deployResultPath , targetConn , deployResult ) ;
305
347
self . outputDeployLog ( pipelineLog , deployResult ) ;
306
348
const now = new Date ( ) ;
307
349
const endTime = now . toISOString ( ) ;
@@ -366,18 +408,53 @@ class Pipeline {
366
408
* @param {Object } deployResult
367
409
*/
368
410
outputDeployLog ( pipelineLog , deployResult ) {
369
- pipelineLog ( '[Metadata] Deploy Done : ' ) ;
370
- //pipelineLog(' Id: ' + deployResult.id);
371
- pipelineLog ( ' Success: ' + deployResult . success ) ;
372
- pipelineLog ( ' Components Total: ' + deployResult . numberComponentsTotal ) ;
373
- pipelineLog ( ' Components Error: ' + deployResult . numberComponentErrors ) ;
374
- pipelineLog ( ' Components Deployed: ' + deployResult . numberComponentsDeployed ) ;
375
- pipelineLog ( ' Tests Total: ' + deployResult . numberTestsTotal ) ;
376
- pipelineLog ( ' Tests Error: ' + deployResult . numberTestErrors ) ;
377
- pipelineLog ( ' Tests Completed: ' + deployResult . numberTestsCompleted ) ;
411
+ pipelineLog ( '[Metadata] Deploy done' ) ;
378
412
pipelineLog ( '[Metadata] Deploy result: @see ' + deployResult . url ) ;
379
413
}
380
414
415
+ /**
416
+ * Set component type label to deploy result and export to json file
417
+ */
418
+ saveDeployResult ( filePath , targetConn , deployResult ) {
419
+ // Set Entity Label to deployResult
420
+ const sfdcApi = new SfdcApi ( targetConn ) ;
421
+ const componentLables = sfdcApi . getComponentLabels ( targetConn . language ) ;
422
+ deployResult [ 'instanceUrl' ] = targetConn . instanceUrl ;
423
+ deployResult [ 'url' ] = targetConn . instanceUrl + '/changemgmt/monitorDeploymentsDetails.apexp?asyncId=' + deployResult . id
424
+
425
+ const getStatus = function ( cmp ) {
426
+ let status = 'No Change' ;
427
+ if ( cmp . changed == 'true' ) status = 'Updated' ;
428
+ if ( cmp . created == 'true' ) status = 'Created' ;
429
+ if ( cmp . deleted == 'true' ) status = 'Deleted' ;
430
+ if ( cmp . problem && cmp . problemType ) {
431
+ status = 'Error: ' + cmp . problem + ' (line ' + ( cmp . lineNumber || 0 ) + ', column ' + ( cmp . columnNumber || 0 ) + ')' ;
432
+ }
433
+ return status ;
434
+ }
435
+
436
+ if ( deployResult . details && deployResult . details . componentSuccesses ) {
437
+ for ( let i = 0 ; i < deployResult . details . componentSuccesses . length ; i ++ ) {
438
+ let componentType = deployResult . details . componentSuccesses [ i ] . componentType ;
439
+ if ( utils . isBlank ( componentType ) ) continue ;
440
+ if ( ! componentLables . hasOwnProperty ( componentType ) ) continue ;
441
+ deployResult . details . componentSuccesses [ i ] [ 'componentTypeLabel' ] = componentLables [ componentType ] ;
442
+ deployResult . details . componentSuccesses [ i ] [ 'status' ] = getStatus ( deployResult . details . componentSuccesses [ i ] ) ;
443
+ }
444
+ }
445
+ if ( deployResult . details && deployResult . details . componentFailures ) {
446
+ for ( let i = 0 ; i < deployResult . details . componentFailures . length ; i ++ ) {
447
+ let componentType = deployResult . details . componentFailures [ i ] . componentType ;
448
+ if ( utils . isBlank ( componentType ) ) continue ;
449
+ if ( ! componentLables . hasOwnProperty ( componentType ) ) continue ;
450
+ deployResult . details . componentFailures [ i ] [ 'componentTypeLabel' ] = componentLables [ componentType ] ;
451
+ deployResult . details . componentSuccesses [ i ] [ 'status' ] = getStatus ( deployResult . details . componentSuccesses [ i ] ) ;
452
+ }
453
+ }
454
+ fs . writeFileSync ( filePath , JSON . stringify ( deployResult ) ) ;
455
+ return deployResult ;
456
+ }
457
+
381
458
}
382
459
383
460
module . exports = Pipeline ;
0 commit comments