Skip to content

Commit f2ade8f

Browse files
committed
[fix] jshint and minor fixes
1 parent a2da591 commit f2ade8f

File tree

1 file changed

+80
-64
lines changed

1 file changed

+80
-64
lines changed

app.js

Lines changed: 80 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ app.commands.repo = function file(link, cb) {
4949
app.commands.npm = function file(link, cb) {
5050
this.log.warn('Running on all available npm repositories that are hosted on github!!!'.red.bold);
5151
doNPMUpdate(cb);
52+
//npmShortCircuit(cb);
5253
};
5354

5455
app.commands.user = function file(user, cb) {
@@ -61,6 +62,17 @@ app.commands.file = function file(filename, cb) {
6162
doFileUpdate(filename, cb);
6263
};
6364

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+
}
6476
function doNPMUpdate(cb) {
6577
app.log.debug("doNPMUpdate");
6678
getNPMRepos(function (err, results) {
@@ -128,7 +140,7 @@ function doUserRepoUpdate(repoData, cb) {
128140
}
129141

130142
function doRepoUpdate(link, cb) {
131-
var re = /(http|ftp|https|git|file):\/\/(\/)?[\w\-] + (\.[\w\-] + ) + ([\w.,@?\^=%&:\/~ + #\-]*[\w@?\^=%&\/~ + #\-])?/gi,
143+
var re = /(http|ftp|https|git|file):\/\/(\/)?[\w\-]+(\.[\w\-]+)+([\w.,@?\^=%&:\/~+#\-]*[\w@?\^=%&\/~+#\-])?/gi,
132144
reSSH = /git@github\.com:.*\/.*(\.git$|$)/g;
133145

134146
if (XRegExp.test(link, re) || XRegExp.test(link, reSSH)) {
@@ -284,15 +296,15 @@ function submitPullRequest(username, user, repo, status, cb) {
284296
app.log.error('error: ' + error);
285297
if (error === null) {
286298
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) {
289301
cb(err);
290302
}
291303
} else {
292-
return cb(error);
304+
return cb(error);
293305
}
294306
}
295-
});
307+
});
296308
});
297309
}
298310

@@ -301,16 +313,17 @@ function cloneRepo(repo, forkedRepo, repoLocation, status, cb) {
301313
app.log.info("Skipping clone of" + forkedRepo.blue.bold);
302314
return cb(null, 'DONE');
303315
}
316+
var cmd, child;
304317
app.log.info("Attempting to clone " + forkedRepo.blue.bold);
305318
//ssh git@github.com:username/repo.git
306319
//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 + '"';
308321
app.log.debug('calling: "' + cmd.grey + '"');
309-
var child = exec(cmd,
322+
child = exec(cmd,
310323
function (error, stdout, stderr) {
311324
if (error !== null) {
312325
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) {
314327
app.log.warn(forkedRepo.blue.bold + ' FAILED cloned to '.red.bold + repoLocation.yellow.bold + ' : We may have already cloned this one!'.magenta.bold);
315328
return cb(null, 'OK'); //ok? should we assume it might not have been processed? Lets see where it goes... shouldn't hurt
316329
} else {
@@ -320,33 +333,34 @@ function cloneRepo(repo, forkedRepo, repoLocation, status, cb) {
320333
app.log.info(forkedRepo.blue.bold + ' Succesfully cloned to ' + repoLocation.yellow.bold);
321334
return cb(null, 'OK');
322335
}
323-
});
336+
});
324337
}
325338

326339
function switchBranch(forkedRepo, repoLocation, status, cb) {
327-
if (status == 'DONE') {
340+
if (status === 'DONE') {
328341
return cb(null, 'DONE');
329342
}
343+
var gitDir, cmd1, cmd2, child;
330344
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';
334348
app.log.debug('calling: "' + cmd1.grey + '"');
335-
var child = exec(cmd1,
349+
child = exec(cmd1,
336350
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') {
338352
app.log.warn('switchBranch::1: ' + forkedRepo.blue.bold + ' ERROR DETECTED!'.red.bold);
339353
console.dir(error);
340354
console.dir(stdout);
341355
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
343357
app.log.warn('The Repo might be empty or at first commit... no master found...'.red);
344358
return cb(null, 'DONE');
345359
} else {
346360
return cb(error);
347361
}
348362
} else {
349-
if (stderr == 'fatal: A branch named \'clean\' already exists.\n') {
363+
if (stderr === 'fatal: A branch named \'clean\' already exists.\n') {
350364
app.log.warn('A branch named \'clean\' ' + 'already exists'.red.bold + ' @' + repoLocation.yellow.bold);
351365
} else {
352366
app.log.info(forkedRepo.blue.bold + '@' + repoLocation.yellow.bold + ':clean branch ' + 'created'.green);
@@ -364,122 +378,124 @@ function switchBranch(forkedRepo, repoLocation, status, cb) {
364378
app.log.info(forkedRepo.blue.bold + '@' + repoLocation.yellow.bold + ':clean branch ' + 'checked out'.green.bold);
365379
return cb(null, 'OK');
366380
}
367-
});
381+
});
368382
}
369-
});
383+
});
370384
}
371385

372386
function commitRepo(forkedRepo, repoLocation, status, cb) {
373387

374-
if (status == 'DONE') {
388+
if (status === 'DONE') {
375389
return cb(null, 'DONE');
376390
}
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();
379394
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 + '"';
381396
app.log.debug('calling: "' + cmd.grey + '"');
382-
var child = exec(cmd,
397+
child = exec(cmd,
383398
function (error, stdout, stderr) {
384399
if (error !== null) {
385400
app.log.warn('commitRepo: ' + forkedRepo.blue.bold + ' ERROR DETECTED!'.red.bold);
386401
console.dir(error);
387402
console.dir(stdout);
388403
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') {
390405
app.log.info(forkedRepo.blue.bold + '@' + repoLocation.yellow.bold + ':clean branch ' + 'NOTHING TO COMMIT'.red.bold);
391406
return cb(null, 'DONE');
392407
} else {
393-
return cb(error);
408+
return cb(error);
394409
}
395410
} 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);
397412
return cb(null, 'OK');
398413
}
399-
});
414+
});
400415
}
401416

402417
function pushCommit(forkedRepo, repoLocation, status, cb) {
403-
if (status == 'DONE') {
418+
if (status === 'DONE') {
404419
return cb(null, 'DONE');
405420
}
406-
var gitDir= path.resolve(path.join(repoLocation,'.git')).toString();
421+
var gitDir, cmd, child;
422+
gitDir = path.resolve(path.join(repoLocation, '.git')).toString();
407423
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';
409425
app.log.debug('calling: "' + cmd.grey + '"');
410-
var child = exec(cmd,
426+
child = exec(cmd,
411427
function (error, stdout, stderr) {
412428
if (error !== null) {
413429
app.log.warn('pushCommit: ' + forkedRepo.blue.bold + ' ERROR DETECTED!'.red.bold);
414430
console.dir(error);
415431
console.dir(stdout);
416432
console.dir(stderr);
417433

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') {
419435
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);
420436
return cb(null, 'DONE');
421437
} else {
422438
return cb(error);
423439
}
424440
} 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);
426442
return cb(null, 'OK');
427443
}
428-
});
444+
});
429445
}
430446

431447
function notifyAvailability(forkedRepo, username, repo, repoLocation, status, cb) {
432-
var count = 0;
433-
var Available = false;
448+
var count = 0,
449+
Available = false;
434450
async.until(// wait for availability (whilst)
435451
function () {
436-
if (count % 2 === 0 ) {
452+
if (count % 2 === 0) {
437453
app.log.info('Waiting for ' + username.magenta.bold + '/' + repo.yellow.bold + ' to become available...');
438454
}
439455
request.head(forkedRepo, function (error, response, body) {
440-
if (!error && response.statusCode == 200) {
456+
if (!error && response.statusCode === 200) {
441457
Available = true;
442458
}
443459
});
444460
return count > 300 || Available;
445461
},
446-
function (cb) {
447-
count ++ ;
462+
function (cb) {
463+
count++;
448464
setTimeout(cb, 2000);
449-
},
465+
},
450466
function (err) {
451467
// 5 minutes have passed
452468
if (count > 300) {
453469
app.log.error('Unable to find forked repo ' + username.magenta.bold + '/' + repo.yellow.bold + ' after 5 minutes.');
454470

455471
} 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+
}
461478
}
462479
}
463-
}
464480
);
465481
}
466482

467483
function walkAndFix(link, status, cb) {
468-
if (status == 'DONE') {
484+
if (status === 'DONE') {
469485
return cb(null, 'DONE');
470486
}
471487
walk(link, function (err, results) {
472488
if (err) {
473489
return cb(err);
474490
}
475491

476-
async.map(results, doFileUpdate ,function (err, results) {
492+
async.map(results, doFileUpdate, function (err, results) {
477493
if (err) {
478494
return cb(err);
479495
}
480496
//app.log.debug(results);
481497
//app.log.debug(results.indexOf('OK'));
482-
if (results.indexOf('OK') == -1) {
498+
if (results.indexOf('OK') === -1) {
483499
app.log.warn('No changes to make for '.bold.red + link.yellow);
484500
return cb(null, 'DONE');
485501
} else {
@@ -491,7 +507,7 @@ function walkAndFix(link, status, cb) {
491507
}
492508

493509
function isNotOK(element, index, array) {
494-
return (element != 'OK');
510+
return (element !== 'OK');
495511
}
496512

497513
function filterString(str) {
@@ -503,23 +519,24 @@ function filterString(str) {
503519
function walk(dir, done) {
504520
var results = [];
505521
fs.readdir(dir, function (err, list) {
506-
if (err) { return done(err);}
522+
var pending, modList;
523+
if (err) { return done(err); }
507524

508-
var modList = list.filter(filterString);//filter out the undesirables
525+
modList = list.filter(filterString);//filter out the undesirables
509526
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); }
512529
list.forEach(function (file) {
513-
file = path.resolve(path.join(dir,file));
530+
file = path.resolve(path.join(dir, file));
514531
fs.stat(file, function (err, stat) {
515532
if (stat && stat.isDirectory()) {
516533
walk(file, function (err, res) {
517534
results = results.concat(res);
518-
if (!--pending) { done(null, results);}
535+
if (!--pending) { done(null, results); }
519536
});
520537
} else {
521538
results.push(file);
522-
if (!--pending) { done(null, results);}
539+
if (!--pending) { done(null, results); }
523540
}
524541
});
525542
});
@@ -541,14 +558,14 @@ function doFileUpdate(filename, cb) {
541558
replacement = "require('util')",
542559
replacementFull = "util = require('util')",
543560
replacementPart = 'util.',
544-
dataStr = data.toString();
561+
dataStr = data.toString(),
545562
fixedDoc = '';
546563

547564
if (XRegExp.test(dataStr, re)) {
548565
if (XRegExp.test(dataStr, reFull)) {
549566
fixedDoc = XRegExp.replace(XRegExp.replace(dataStr, rePart, replacementPart, 'all'), reFull, replacementFull, 'all');
550567
}
551-
else{
568+
else {
552569
fixedDoc = XRegExp.replace(dataStr, re, replacement, 'all');
553570
}
554571
//return cb(null, fixedDoc);
@@ -561,10 +578,9 @@ function doFileUpdate(filename, cb) {
561578
app.log.info(filename.blue.bold + ' was modified and changed!');
562579
return cb(null, 'OK');
563580
}
564-
});
581+
});
565582

566-
}
567-
else{
583+
} else {
568584
app.log.debug('No ' + 'require("sys")'.magenta.bold + ' text found in ' + filename.blue.bold);
569585
return cb(null, 'NO CHANGE');
570586
}

0 commit comments

Comments
 (0)