Skip to content

Commit 23fdfe4

Browse files
committed
[fix] did some tweaks to individual repos and added support for git ssh url
1 parent e96e2f6 commit 23fdfe4

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

app.js

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,9 @@ function doUserRepoUpdate(repoData, cb){
7171

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

75-
if (XRegExp.test(link, re)) {
76+
if (XRegExp.test(link, re) || XRegExp.test(link, reSSH)) {
7677
app.log.info(link.blue.bold+' is a url');
7778
forkAndFix(link, cb);
7879
}else{
@@ -82,12 +83,12 @@ function doRepoUpdate(link, cb){
8283
}
8384

8485
function forkAndFix(link, cb){
85-
var parse = XRegExp(/.*github.com\/(.*)\/(.*?)(\.git$|$)/g);
86+
var parse = XRegExp(/.*github.com[\/|:](.*)\/(.*?)(\.git$|$)/g);
8687
var user = XRegExp.replace(link, parse, '$1');
8788
var repo = XRegExp.replace(link, parse, '$2');
8889
var forkedRepo = 'https://github.com/'+username+'/'+repo;
8990
var tmpDir = path.resolve(path.join('.','tmp'));
90-
var repoLocation = path.resolve(path.join(tmpDir,repo)).toString();
91+
var repoLocation = path.resolve(path.join(path.join(tmpDir,user), repo)).toString();
9192

9293
app.log.info('Forking '+user.magenta.bold+'/'+repo.yellow.bold);
9394
async.waterfall([
@@ -120,8 +121,7 @@ function forkAndFix(link, cb){
120121
if (err) {
121122
return cb(err);
122123
}
123-
app.log.info('node-migrator-bot '.grey+result);
124-
app.log.info('Done with '+link.blue.bold);
124+
app.log.info('node-migrator-bot'.grey+' Done with '.green+link.blue.bold+' RESULT: '.grey+result);
125125
return cb(null, result);
126126
});
127127
}
@@ -227,7 +227,12 @@ function cloneRepo(repo, forkedRepo, repoLocation, status, cb){
227227
var child = exec(cmd,
228228
function (error, stdout, stderr) {
229229
if (error !== null) {
230-
return cb(error);
230+
if (stderr.indexOf('already exists') != -1 ){
231+
app.log.warn(forkedRepo.blue.bold+' FAILED cloned to '.red.bold+repoLocation.yellow.bold+' : We may have already cloned this one!'.magenta.bold);
232+
return cb(null, 'OK'); //ok? should we assume it might not have been processed? Lets see where it goes... shouldn't hurt
233+
}else{
234+
return cb(error);
235+
}
231236
}else{
232237
app.log.info(forkedRepo.blue.bold+' Succesfully cloned to '+repoLocation.yellow.bold);
233238
return cb(null, 'OK');
@@ -243,10 +248,14 @@ function switchBranch(forkedRepo, repoLocation, status, cb){
243248
app.log.debug('calling: "'+cmd1.grey+'"');
244249
var child = exec(cmd1,
245250
function (error, stdout, stderr) {
246-
if (error !== null) {
251+
if (error !== null && stderr != 'fatal: A branch named \'clean\' already exists.\n' ) {
247252
return cb(error);
248253
}else{
249-
app.log.info(forkedRepo.blue.bold+'@'+repoLocation.yellow.bold+':clean branch '+'created'.green);
254+
if(stderr == 'fatal: A branch named \'clean\' already exists.\n'){
255+
app.log.warn('A branch named \'clean\' '+'already exists'.red.bold+' @'+repoLocation.yellow.bold);
256+
}else{
257+
app.log.info(forkedRepo.blue.bold+'@'+repoLocation.yellow.bold+':clean branch '+'created'.green);
258+
}
250259
app.log.debug('calling: "'+cmd2.grey+'"');
251260
var child2 = exec(cmd2,
252261
function (error, stdout, stderr) {
@@ -274,11 +283,8 @@ function commitRepo(forkedRepo, repoLocation, status, cb){
274283
var child = exec(cmd,
275284
function (error, stdout, stderr) {
276285
if (error !== null) {
277-
console.dir(error);
278286
app.log.debug('stdout: ' + stdout);
279-
console.dir(stdout);
280287
app.log.debug('stderr: ' + stderr);
281-
console.dir(stderr);
282288
if (stdout == '# On branch clean\nnothing to commit (working directory clean)\n'){
283289
app.log.info(forkedRepo.blue.bold+'@'+repoLocation.yellow.bold+':clean branch '+'NOTHING TO COMMIT'.red.bold);
284290
return cb(null, 'DONE');
@@ -303,12 +309,15 @@ function pushCommit(forkedRepo, repoLocation, status, cb){
303309
var child = exec(cmd,
304310
function (error, stdout, stderr) {
305311
if (error !== null) {
306-
console.dir(error);
307312
app.log.debug('stdout: ' + stdout);
308-
console.dir(stdout);
309313
app.log.debug('stderr: ' + stderr);
310-
console.dir(stdout);
311-
return cb(error);
314+
315+
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'){
316+
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);
317+
return cb(null, 'DONE');
318+
}else{
319+
return cb(error);
320+
}
312321
}else{
313322
app.log.info(forkedRepo.blue.bold+'@'+repoLocation.yellow.bold+':clean branch '+'COMMIT PUSHED'.green.bold);
314323
return cb(null, 'OK');
@@ -362,9 +371,10 @@ function walkAndFix(link, status, cb){
362371
if (err) {
363372
return cb(err);
364373
}
365-
app.log.debug(results);
366-
app.log.debug(results.indexOf('OK'));
374+
//app.log.debug(results);
375+
//app.log.debug(results.indexOf('OK'));
367376
if(results.indexOf('OK') == -1){
377+
app.log.warn('No changes to make for '.bold.red+link.yellow);
368378
return cb(null, 'DONE');
369379
}else{
370380
return cb(null, 'OK');

0 commit comments

Comments
 (0)