@@ -47,6 +47,7 @@ function createHooks(reponame, url, secret, token, callback) {
4747 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
4848 . end ( function ( err , res ) {
4949 if ( err ) return callback ( err ) ;
50+
5051 if ( res . statusCode !== 201 ) {
5152 var badStatusErr = new Error ( 'Bad status code: ' + res . statusCode ) ;
5253 badStatusErr . statusCode = res . statusCode ;
@@ -73,7 +74,8 @@ function deleteHooks(reponame, url, token, callback) {
7374 . get ( apiUrl )
7475 . set ( 'Authorization' , 'token ' + token )
7576 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
76- . end ( function ( res ) { //CHECK: have a callback with the first param as err and process that err
77+ . end ( function ( err , res ) {
78+ if ( err ) return callback ( err ) ;
7779 if ( res . status > 300 ) {
7880 debug ( 'Error getting hooks' , res . status , res . text ) ;
7981 return callback ( res . status ) ;
@@ -87,7 +89,8 @@ function deleteHooks(reponame, url, token, callback) {
8789 . del ( hook . url )
8890 . set ( 'Authorization' , 'token ' + token )
8991 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
90- . end ( function ( res ) { //CHECK: have a callback with the first param as err and process that err
92+ . end ( function ( err , res ) {
93+ if ( err ) return next ( new Error ( 'Failed to delete webhook ' + hook . url + 'Error: ' + err ) ) ;
9194 if ( res . status !== 204 ) {
9295 debug ( 'bad status' , res . status , hook . id , hook . url ) ;
9396 return next ( new Error ( 'Failed to delete a webhook: status for url ' + hook . url + ': ' + res . status ) ) ;
@@ -127,7 +130,8 @@ function getFile(filename, ref, accessToken, owner, repo, done) {
127130 if ( accessToken ) {
128131 req = req . set ( 'Authorization' , 'token ' + accessToken ) ;
129132 }
130- req . end ( function ( res ) { //CHECK: have a callback with the first param as err and process that err
133+ req . end ( function ( err , res ) {
134+ if ( err ) return done ( err , null ) ;
131135 if ( res . error ) return done ( res . error , null ) ;
132136 if ( ! res . body . content ) {
133137 return done ( ) ;
@@ -176,11 +180,11 @@ var api_call = module.exports.api_call = function (path, access_token, callback,
176180 var url = GITHUB_API_ENDPOINT + path ;
177181 debug ( 'API CALL:' , url , access_token ) ;
178182 get_oauth2 ( url , { } , access_token , function ( error , res ) {
179- debug ( "We get an error from the API: " + error ) ;
180183 if ( ! error && res . statusCode == 200 ) {
181184 var data = res . body ;
182185 callback ( null , res , data ) ;
183186 } else {
187+ debug ( "We get an error from the API: " + error ) ;
184188 callback ( error , res , null ) ;
185189 }
186190 } , client ) ;
@@ -245,7 +249,7 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
245249 function loop ( uri , page ) {
246250 debug ( 'PAGINATED API CALL URL:' , uri ) ;
247251 get_oauth2 ( uri , { per_page : 30 , page : page } , access_token , function ( error , res ) {
248- debug ( "We get an error: " + error ) ;
252+
249253 if ( ! error && res . statusCode == 200 ) {
250254 var data ;
251255 try {
@@ -389,27 +393,16 @@ function getRepos(token, username, callback) {
389393 } ) ;
390394 // For each Team with admin privs, test for membership
391395 var group = this . group ( ) ;
392- debug ( "****************************************************************\nThis is: " + JSON . stringify ( this , null , 4 ) ) ; //CHECK: undefined
393- debug ( "****************************************************************\ngroup is: " + JSON . stringify ( group , null , 4 ) ) ; //CHECK: undefined
394396
395397 var team_detail_requests = { } ;
396398 _ . each ( team_details , function ( team_details ) {
397399 if ( team_details . permission != 'admin' ) {
398400 return ;
399401 }
400402 team_detail_requests [ team_details . id ] = team_details ;
401- var url = GITHUB_API_ENDPOINT + '/teams/' + team_details . id + '/members/' + username ;
403+ var url = '/teams/' + team_details . id + '/members/' + username ;
402404 debug ( 'TEAM DETAIL URL' , url ) ;
403- get_oauth2 ( url , { } , token , group ( ) ) ; //<------------------- this is a problem
404- //get_oauth sends this callback as it is to superagent
405- //superagent expects a callback that takes two arguments
406- //in the other places it works because we are sending group() as
407- //as a parameter to api_call or pageinated_api_call, and they are now correctly wrapping
408- //get_oauth, passing in a callback that expects two arguments
409- //if we were to replace this get_oauth2 call by a call to api_call,
410- //it would probably work as a hack, but the intention behind group()
411- //and this.group() is yet to be understood by me
412-
405+ api_call ( url , token , group ( ) ) ;
413406 } ) ;
414407 this . team_detail_requests = team_detail_requests ;
415408 } ,
0 commit comments