@@ -49,6 +49,7 @@ app.commands.repo = function file(link, cb) {
49
49
app . commands . npm = function file ( link , cb ) {
50
50
this . log . warn ( 'Running on all available npm repositories that are hosted on github!!!' . red . bold ) ;
51
51
doNPMUpdate ( cb ) ;
52
+ //npmShortCircuit(cb);
52
53
} ;
53
54
54
55
app . commands . user = function file ( user , cb ) {
@@ -61,6 +62,17 @@ app.commands.file = function file(filename, cb) {
61
62
doFileUpdate ( filename , cb ) ;
62
63
} ;
63
64
65
+ function npmShortCircuit ( cb ) {
66
+ var ex = [ 'git://github.com/eller86/surrogate-pair.js.git' , 'git://github.com/vesln/surround.git' , 'git@github.com:sebv/sv-cake-utils.git' ] ;
67
+ async . forEachSeries ( ex , doRepoUpdate , function ( err ) {
68
+ if ( err ) {
69
+ app . log . warn ( 'Error processing npm repositories that are hosted on github!!!' . red . bold ) ;
70
+ return cb ( err ) ;
71
+ } else {
72
+ return cb ( null , 'OK' ) ;
73
+ }
74
+ } ) ;
75
+ }
64
76
function doNPMUpdate ( cb ) {
65
77
app . log . debug ( "doNPMUpdate" ) ;
66
78
getNPMRepos ( function ( err , results ) {
@@ -128,7 +140,7 @@ function doUserRepoUpdate(repoData, cb) {
128
140
}
129
141
130
142
function doRepoUpdate ( link , cb ) {
131
- var re = / ( h t t p | f t p | h t t p s | g i t | f i l e ) : \/ \/ ( \/ ) ? [ \w \- ] + ( \. [ \w \- ] + ) + ( [ \w . , @ ? \^ = % & a m p ; : \/ ~ + # \- ] * [ \w @ ? \^ = % & a m p ; \/ ~ + # \- ] ) ? / gi,
143
+ var re = / ( h t t p | f t p | h t t p s | g i t | f i l e ) : \/ \/ ( \/ ) ? [ \w \- ] + ( \. [ \w \- ] + ) + ( [ \w . , @ ? \^ = % & a m p ; : \/ ~ + # \- ] * [ \w @ ? \^ = % & a m p ; \/ ~ + # \- ] ) ? / gi,
132
144
reSSH = / g i t @ g i t h u b \. c o m : .* \/ .* ( \. g i t $ | $ ) / g;
133
145
134
146
if ( XRegExp . test ( link , re ) || XRegExp . test ( link , reSSH ) ) {
@@ -284,15 +296,15 @@ function submitPullRequest(username, user, repo, status, cb) {
284
296
app . log . error ( 'error: ' + error ) ;
285
297
if ( error === null ) {
286
298
try {
287
- throw new Error ( response . statusCode + ' ' + response . body . toString ( ) ) ;
288
- } catch ( err ) {
299
+ throw new Error ( response . statusCode + ' ' + response . body . toString ( ) ) ;
300
+ } catch ( err ) {
289
301
cb ( err ) ;
290
302
}
291
303
} else {
292
- return cb ( error ) ;
304
+ return cb ( error ) ;
293
305
}
294
306
}
295
- } ) ;
307
+ } ) ;
296
308
} ) ;
297
309
}
298
310
@@ -301,16 +313,17 @@ function cloneRepo(repo, forkedRepo, repoLocation, status, cb) {
301
313
app . log . info ( "Skipping clone of" + forkedRepo . blue . bold ) ;
302
314
return cb ( null , 'DONE' ) ;
303
315
}
316
+ var cmd , child ;
304
317
app . log . info ( "Attempting to clone " + forkedRepo . blue . bold ) ;
305
318
//ssh git@github .com:username/repo.git
306
319
//var cmd = 'git clone ' + forkedRepo + '.git "' + repoLocation + '"';
307
- var cmd = 'git clone git@github.com:' + username + '/' + repo + '.git "' + repoLocation + '"' ;
320
+ cmd = 'git clone git@github.com:' + username + '/' + repo + '.git "' + repoLocation + '"' ;
308
321
app . log . debug ( 'calling: "' + cmd . grey + '"' ) ;
309
- var child = exec ( cmd ,
322
+ child = exec ( cmd ,
310
323
function ( error , stdout , stderr ) {
311
324
if ( error !== null ) {
312
325
app . log . warn ( 'cloneRepo: ' + forkedRepo . blue . bold + ' ERROR DETECTED!' . red . bold ) ;
313
- if ( stderr . indexOf ( 'already exists' ) != - 1 ) {
326
+ if ( stderr . indexOf ( 'already exists' ) !== - 1 ) {
314
327
app . log . warn ( forkedRepo . blue . bold + ' FAILED cloned to ' . red . bold + repoLocation . yellow . bold + ' : We may have already cloned this one!' . magenta . bold ) ;
315
328
return cb ( null , 'OK' ) ; //ok? should we assume it might not have been processed? Lets see where it goes... shouldn't hurt
316
329
} else {
@@ -320,33 +333,34 @@ function cloneRepo(repo, forkedRepo, repoLocation, status, cb) {
320
333
app . log . info ( forkedRepo . blue . bold + ' Succesfully cloned to ' + repoLocation . yellow . bold ) ;
321
334
return cb ( null , 'OK' ) ;
322
335
}
323
- } ) ;
336
+ } ) ;
324
337
}
325
338
326
339
function switchBranch ( forkedRepo , repoLocation , status , cb ) {
327
- if ( status == 'DONE' ) {
340
+ if ( status === 'DONE' ) {
328
341
return cb ( null , 'DONE' ) ;
329
342
}
343
+ var gitDir , cmd1 , cmd2 , child ;
330
344
app . log . info ( "Attempting to switch branch on " + repoLocation . blue . bold ) ;
331
- var gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
332
- var cmd1 = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" branch clean' ;
333
- var cmd2 = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" checkout clean' ;
345
+ gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
346
+ cmd1 = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" branch clean' ;
347
+ cmd2 = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" checkout clean' ;
334
348
app . log . debug ( 'calling: "' + cmd1 . grey + '"' ) ;
335
- var child = exec ( cmd1 ,
349
+ child = exec ( cmd1 ,
336
350
function ( error , stdout , stderr ) {
337
- if ( error !== null && stderr != 'fatal: A branch named \'clean\' already exists.\n' ) {
351
+ if ( error !== null && stderr !== 'fatal: A branch named \'clean\' already exists.\n' ) {
338
352
app . log . warn ( 'switchBranch::1: ' + forkedRepo . blue . bold + ' ERROR DETECTED!' . red . bold ) ;
339
353
console . dir ( error ) ;
340
354
console . dir ( stdout ) ;
341
355
console . dir ( stderr ) ;
342
- if ( stderr == 'fatal: Not a valid object name: \'master\'.\n' ) { //sometimes if repo is empty or at first commit
356
+ if ( stderr === 'fatal: Not a valid object name: \'master\'.\n' ) { //sometimes if repo is empty or at first commit
343
357
app . log . warn ( 'The Repo might be empty or at first commit... no master found...' . red ) ;
344
358
return cb ( null , 'DONE' ) ;
345
359
} else {
346
360
return cb ( error ) ;
347
361
}
348
362
} else {
349
- if ( stderr == 'fatal: A branch named \'clean\' already exists.\n' ) {
363
+ if ( stderr === 'fatal: A branch named \'clean\' already exists.\n' ) {
350
364
app . log . warn ( 'A branch named \'clean\' ' + 'already exists' . red . bold + ' @' + repoLocation . yellow . bold ) ;
351
365
} else {
352
366
app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'created' . green ) ;
@@ -364,122 +378,124 @@ function switchBranch(forkedRepo, repoLocation, status, cb) {
364
378
app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'checked out' . green . bold ) ;
365
379
return cb ( null , 'OK' ) ;
366
380
}
367
- } ) ;
381
+ } ) ;
368
382
}
369
- } ) ;
383
+ } ) ;
370
384
}
371
385
372
386
function commitRepo ( forkedRepo , repoLocation , status , cb ) {
373
387
374
- if ( status == 'DONE' ) {
388
+ if ( status === 'DONE' ) {
375
389
return cb ( null , 'DONE' ) ;
376
390
}
377
- var message = "[fix] Changed require('sys') to require('util') for migration issues" ;
378
- var gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
391
+ var gitDir , cmd , child , message ;
392
+ message = "[fix] Changed require('sys') to require('util') for migration issues" ;
393
+ gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
379
394
app . log . info ( "Attempting a commit on " + repoLocation . blue . bold ) ;
380
- var cmd = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" commit -am "' + message + '"' ;
395
+ cmd = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" commit -am "' + message + '"' ;
381
396
app . log . debug ( 'calling: "' + cmd . grey + '"' ) ;
382
- var child = exec ( cmd ,
397
+ child = exec ( cmd ,
383
398
function ( error , stdout , stderr ) {
384
399
if ( error !== null ) {
385
400
app . log . warn ( 'commitRepo: ' + forkedRepo . blue . bold + ' ERROR DETECTED!' . red . bold ) ;
386
401
console . dir ( error ) ;
387
402
console . dir ( stdout ) ;
388
403
console . dir ( stderr ) ;
389
- if ( stdout == '# On branch clean\nnothing to commit (working directory clean)\n' ) {
404
+ if ( stdout === '# On branch clean\nnothing to commit (working directory clean)\n' ) {
390
405
app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'NOTHING TO COMMIT' . red . bold ) ;
391
406
return cb ( null , 'DONE' ) ;
392
407
} else {
393
- return cb ( error ) ;
408
+ return cb ( error ) ;
394
409
}
395
410
} else {
396
- app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'COMMIT' . green . bold ) ;
411
+ app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'COMMIT' . green . bold ) ;
397
412
return cb ( null , 'OK' ) ;
398
413
}
399
- } ) ;
414
+ } ) ;
400
415
}
401
416
402
417
function pushCommit ( forkedRepo , repoLocation , status , cb ) {
403
- if ( status == 'DONE' ) {
418
+ if ( status === 'DONE' ) {
404
419
return cb ( null , 'DONE' ) ;
405
420
}
406
- var gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
421
+ var gitDir , cmd , child ;
422
+ gitDir = path . resolve ( path . join ( repoLocation , '.git' ) ) . toString ( ) ;
407
423
app . log . info ( "Attempting a push commit on branch clean @" + repoLocation . blue . bold ) ;
408
- var cmd = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" push origin clean' ;
424
+ cmd = 'git --git-dir="' + gitDir + '" --work-tree="' + repoLocation + '" push origin clean' ;
409
425
app . log . debug ( 'calling: "' + cmd . grey + '"' ) ;
410
- var child = exec ( cmd ,
426
+ child = exec ( cmd ,
411
427
function ( error , stdout , stderr ) {
412
428
if ( error !== null ) {
413
429
app . log . warn ( 'pushCommit: ' + forkedRepo . blue . bold + ' ERROR DETECTED!' . red . bold ) ;
414
430
console . dir ( error ) ;
415
431
console . dir ( stdout ) ;
416
432
console . dir ( stderr ) ;
417
433
418
- if ( stdout == 'To prevent you from losing history, non-fast-forward updates were rejected\nMerge the remote changes before pushing again. See the \'Note about\nfast-forwards\' section of \'git push --help\' for details.\n' ) {
434
+ if ( stdout === 'To prevent you from losing history, non-fast-forward updates were rejected\nMerge the remote changes before pushing again. See the \'Note about\nfast-forwards\' section of \'git push --help\' for details.\n' ) {
419
435
app . log . warn ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'COMMIT NOT PUSHED' . red . bold + ' : We may have already pushed to this fork!' . magenta . bold ) ;
420
436
return cb ( null , 'DONE' ) ;
421
437
} else {
422
438
return cb ( error ) ;
423
439
}
424
440
} else {
425
- app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'COMMIT PUSHED' . green . bold ) ;
441
+ app . log . info ( forkedRepo . blue . bold + '@' + repoLocation . yellow . bold + ':clean branch ' + 'COMMIT PUSHED' . green . bold ) ;
426
442
return cb ( null , 'OK' ) ;
427
443
}
428
- } ) ;
444
+ } ) ;
429
445
}
430
446
431
447
function notifyAvailability ( forkedRepo , username , repo , repoLocation , status , cb ) {
432
- var count = 0 ;
433
- var Available = false ;
448
+ var count = 0 ,
449
+ Available = false ;
434
450
async . until ( // wait for availability (whilst)
435
451
function ( ) {
436
- if ( count % 2 === 0 ) {
452
+ if ( count % 2 === 0 ) {
437
453
app . log . info ( 'Waiting for ' + username . magenta . bold + '/' + repo . yellow . bold + ' to become available...' ) ;
438
454
}
439
455
request . head ( forkedRepo , function ( error , response , body ) {
440
- if ( ! error && response . statusCode == 200 ) {
456
+ if ( ! error && response . statusCode === 200 ) {
441
457
Available = true ;
442
458
}
443
459
} ) ;
444
460
return count > 300 || Available ;
445
461
} ,
446
- function ( cb ) {
447
- count ++ ;
462
+ function ( cb ) {
463
+ count ++ ;
448
464
setTimeout ( cb , 2000 ) ;
449
- } ,
465
+ } ,
450
466
function ( err ) {
451
467
// 5 minutes have passed
452
468
if ( count > 300 ) {
453
469
app . log . error ( 'Unable to find forked repo ' + username . magenta . bold + '/' + repo . yellow . bold + ' after 5 minutes.' ) ;
454
470
455
471
} else {
456
- app . log . info ( 'Forked repo ' + username . magenta . bold + '/' + repo . yellow . bold + ' Exists!' ) ;
457
- if ( Available ) {
458
- return cb ( null , 'DONE' ) ; //Change to 'DONE' if you dont want to clone
459
- } else {
460
- return cb ( "error: Timeout" ) ;
472
+ app . log . info ( 'Forked repo ' + username . magenta . bold + '/' + repo . yellow . bold + ' Exists!' ) ;
473
+ if ( Available ) {
474
+ return cb ( null , 'OK' ) ; //Change to 'DONE' if you dont want to clone
475
+ } else {
476
+ return cb ( "error: Timeout" ) ;
477
+ }
461
478
}
462
479
}
463
- }
464
480
) ;
465
481
}
466
482
467
483
function walkAndFix ( link , status , cb ) {
468
- if ( status == 'DONE' ) {
484
+ if ( status === 'DONE' ) {
469
485
return cb ( null , 'DONE' ) ;
470
486
}
471
487
walk ( link , function ( err , results ) {
472
488
if ( err ) {
473
489
return cb ( err ) ;
474
490
}
475
491
476
- async . map ( results , doFileUpdate , function ( err , results ) {
492
+ async . map ( results , doFileUpdate , function ( err , results ) {
477
493
if ( err ) {
478
494
return cb ( err ) ;
479
495
}
480
496
//app.log.debug(results);
481
497
//app.log.debug(results.indexOf('OK'));
482
- if ( results . indexOf ( 'OK' ) == - 1 ) {
498
+ if ( results . indexOf ( 'OK' ) === - 1 ) {
483
499
app . log . warn ( 'No changes to make for ' . bold . red + link . yellow ) ;
484
500
return cb ( null , 'DONE' ) ;
485
501
} else {
@@ -491,7 +507,7 @@ function walkAndFix(link, status, cb) {
491
507
}
492
508
493
509
function isNotOK ( element , index , array ) {
494
- return ( element != 'OK' ) ;
510
+ return ( element !== 'OK' ) ;
495
511
}
496
512
497
513
function filterString ( str ) {
@@ -503,23 +519,24 @@ function filterString(str) {
503
519
function walk ( dir , done ) {
504
520
var results = [ ] ;
505
521
fs . readdir ( dir , function ( err , list ) {
506
- if ( err ) { return done ( err ) ; }
522
+ var pending , modList ;
523
+ if ( err ) { return done ( err ) ; }
507
524
508
- var modList = list . filter ( filterString ) ; //filter out the undesirables
525
+ modList = list . filter ( filterString ) ; //filter out the undesirables
509
526
list = modList ;
510
- var pending = list . length ;
511
- if ( ! pending ) { return done ( null , results ) ; }
527
+ pending = list . length ;
528
+ if ( ! pending ) { return done ( null , results ) ; }
512
529
list . forEach ( function ( file ) {
513
- file = path . resolve ( path . join ( dir , file ) ) ;
530
+ file = path . resolve ( path . join ( dir , file ) ) ;
514
531
fs . stat ( file , function ( err , stat ) {
515
532
if ( stat && stat . isDirectory ( ) ) {
516
533
walk ( file , function ( err , res ) {
517
534
results = results . concat ( res ) ;
518
- if ( ! -- pending ) { done ( null , results ) ; }
535
+ if ( ! -- pending ) { done ( null , results ) ; }
519
536
} ) ;
520
537
} else {
521
538
results . push ( file ) ;
522
- if ( ! -- pending ) { done ( null , results ) ; }
539
+ if ( ! -- pending ) { done ( null , results ) ; }
523
540
}
524
541
} ) ;
525
542
} ) ;
@@ -541,14 +558,14 @@ function doFileUpdate(filename, cb) {
541
558
replacement = "require('util')" ,
542
559
replacementFull = "util = require('util')" ,
543
560
replacementPart = 'util.' ,
544
- dataStr = data . toString ( ) ;
561
+ dataStr = data . toString ( ) ,
545
562
fixedDoc = '' ;
546
563
547
564
if ( XRegExp . test ( dataStr , re ) ) {
548
565
if ( XRegExp . test ( dataStr , reFull ) ) {
549
566
fixedDoc = XRegExp . replace ( XRegExp . replace ( dataStr , rePart , replacementPart , 'all' ) , reFull , replacementFull , 'all' ) ;
550
567
}
551
- else {
568
+ else {
552
569
fixedDoc = XRegExp . replace ( dataStr , re , replacement , 'all' ) ;
553
570
}
554
571
//return cb(null, fixedDoc);
@@ -561,10 +578,9 @@ function doFileUpdate(filename, cb) {
561
578
app . log . info ( filename . blue . bold + ' was modified and changed!' ) ;
562
579
return cb ( null , 'OK' ) ;
563
580
}
564
- } ) ;
581
+ } ) ;
565
582
566
- }
567
- else {
583
+ } else {
568
584
app . log . debug ( 'No ' + 'require("sys")' . magenta . bold + ' text found in ' + filename . blue . bold ) ;
569
585
return cb ( null , 'NO CHANGE' ) ;
570
586
}
0 commit comments