From b6aceb4a82917e3230bd7d959b18359e04259537 Mon Sep 17 00:00:00 2001 From: coderaiser Date: Mon, 19 Nov 2012 07:51:44 -0500 Subject: [PATCH] added ability to read trees from github --- lib/client/storage/_github.js | 33 ++++++++++++++++++++++++++------- lib/server/auth.js | 4 +--- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/lib/client/storage/_github.js b/lib/client/storage/_github.js index ca1538fb..f1219223 100644 --- a/lib/client/storage/_github.js +++ b/lib/client/storage/_github.js @@ -12,7 +12,7 @@ var CloudCommander, Util, DOM, $, Github, cb; ClientIdURL = APIURL + '/client_id', CLIENT_ID, Cache = DOM.Cache, - GitHub, + GithubLocal, User, GithubStore = {}; @@ -72,7 +72,7 @@ var CloudCommander, Util, DOM, $, Github, cb; /* PUBLICK FUNCTIONS */ GithubStore.basicLogin = function(pUser, pPasswd){ - cloudcmd.Storage.Github = GitHub = new Github({ + cloudcmd.Storage.Github = GithubLocal = new Github({ username: pUser, password: pPasswd, auth : 'basic' @@ -80,12 +80,12 @@ var CloudCommander, Util, DOM, $, Github, cb; }; GithubStore.Login = function(pToken){ - cloudcmd.Storage.Github = Github = new Github({ + cloudcmd.Storage.Github = GithubLocal = new Github({ token : pToken, auth : 'oauth' }); - User = Github.getUser(); + User = GithubLocal.getUser(); }; function init(pCallBack){ @@ -124,18 +124,37 @@ var CloudCommander, Util, DOM, $, Github, cb; } function getUserData(){ - var lShowRepos = function(pError, pRepos){ - Util.log('Repositories: '); + var lName, lRepoNames, + lGetTree = function(pError ,pData){ + Util.log('Tree of ripository ' + lRepoNames[0].name + ': '); + var lTree = pData || []; if(!pError) + for(var i = 0, n = lTree.length; i < n ; i++) + if( !Util.isContainStr(lTree[i].path, '/') ) + console.log(lTree[i].path); + else + Util.log(pError); + }, + + lShowRepos = function(pError, pRepos){ + lRepoNames = pRepos || []; + Util.log('Repositories: '); + if(!pError){ for(var i = 0, n = pRepos.length; i < n ; i++) console.log(pRepos[i].name); + + var lRepo = GithubLocal.getRepo(lName, pRepos[0].name); + lRepo.getTree('master?recursive=true', lGetTree); + } else DOM.Cache.remove('token'); }, lShowUserInfo = function(pError, pData){ if(!pError){ - console.log('Hello ' + pData.name + ' :)!'); + lName = pData.name; + + console.log('Hello ' + lName + ' :)!'); User.repos(lShowRepos); } else diff --git a/lib/server/auth.js b/lib/server/auth.js index 4793de97..025e9ee6 100644 --- a/lib/server/auth.js +++ b/lib/server/auth.js @@ -44,9 +44,7 @@ lClientId = lEnv.oauth_client_id || lId, lClientSecret = lEnv.oauth_client_secret || lSecret; - - console.log(lEnv); - + var data = qs.stringify({ client_id : lClientId, client_secret : lClientSecret,