@@ -85,6 +85,24 @@ Github.prototype.getRepo = function (repo, cb) {
8585 } , cb ) ;
8686} ;
8787
88+ Github . prototype . getRepoContent = function ( repo , fullPath , cb ) {
89+ debug ( 'getRepoFile' , formatArgs ( arguments ) ) ;
90+ debug ( 'getting repo "' + repo + '" file :' + fullPath ) ;
91+ var split = repo . split ( '/' ) ;
92+ var userKey = keyPrefix + ( this . token ? this . tokenHash : 'runnable' ) ;
93+ var usernameKey = new redisTypes . String ( userKey + ':getRepo:' + repo + ':content:' + fullPath ) ;
94+ this . _runQueryAgainstCache ( {
95+ query : this . repos . getContent ,
96+ debug : 'this.repos.getContent' ,
97+ opts : {
98+ user : split [ 0 ] ,
99+ repo : split [ 1 ] ,
100+ path : fullPath
101+ } ,
102+ stringKey : usernameKey
103+ } , cb ) ;
104+ } ;
105+
88106Github . prototype . getDeployKeys = function ( repo , cb ) {
89107 debug ( 'getDeployKeys' , formatArgs ( arguments ) ) ;
90108 debug ( 'getting repo keys for ' + repo ) ;
@@ -258,10 +276,16 @@ Github.prototype._runQueryAgainstCache = function (options, cb) {
258276 runQuery ( false , cb ) ;
259277 }
260278
279+ /* jshint maxcomplexity:6 */
261280 function runQuery ( sendConditionalHeader , cb ) {
262281 debug ( 'runQuery; query:' , options . debug ) ;
263282 // this is a shim so we can get a hold of the full github response
264- self . _httpSend = self . httpSend ;
283+ //self._httpSend = self.httpSend;
284+ if ( sendConditionalHeader ) {
285+ cacheQueue [ stringKey . key ] = self . httpSend ;
286+ } else {
287+ self . _httpSend = self . httpSend ;
288+ }
265289 self . httpSend = function ( ) {
266290 var args = Array . prototype . slice . call ( arguments ) ;
267291 if ( typeof args [ 2 ] === 'function' ) {
@@ -271,21 +295,29 @@ Github.prototype._runQueryAgainstCache = function (options, cb) {
271295 httpSendCb ( err , res ) ;
272296 } ) ;
273297 }
274- self . _httpSend . apply ( self , args ) ;
298+ if ( sendConditionalHeader ) {
299+ cacheQueue [ stringKey . key ] . apply ( self , args ) ;
300+ } else {
301+ self . _httpSend . apply ( self , args ) ;
302+ }
275303 } ;
276304 if ( sendConditionalHeader ) {
277305 if ( ! opts . headers ) { opts . headers = { } ; }
278306 opts . headers [ 'if-none-match' ] = keypather . get ( cachedData , 'meta.etag' ) ;
279307 }
280308 query ( opts , function ( err , data ) {
309+ if ( sendConditionalHeader ) {
310+ self . httpSend = cacheQueue [ stringKey . key ] ;
311+ } else {
312+ self . httpSend = self . _httpSend ;
313+ }
281314 if ( err ) {
282315 if ( err . code && err . message ) {
283316 return cb ( Boom . create ( err . code , err . message ) ) ;
284317 } else {
285318 return cb ( err ) ;
286319 }
287320 }
288- self . httpSend = self . _httpSend ;
289321
290322 if ( sendConditionalHeader && / ^ 3 0 4 .* / . test ( data . meta . status ) ) {
291323 cache304Response ( stringKey , function ( ) {
@@ -302,6 +334,7 @@ Github.prototype._runQueryAgainstCache = function (options, cb) {
302334 }
303335 } ) ;
304336 }
337+ /* jshint maxcomplexity:5 */
305338
306339 function cache304Response ( key , cb ) {
307340 var cc = parseCacheControl ( keypather . get ( githubResponse , 'headers.cache-control' ) ) ;
0 commit comments