@@ -16,7 +16,11 @@ module.exports = {
1616 getFile : getFile ,
1717 getBranches : getBranches ,
1818 createHooks : createHooks ,
19- deleteHooks : deleteHooks
19+ deleteHooks : deleteHooks ,
20+ get_oauth2 :get_oauth2 ,
21+ api_call :api_call ,
22+ parse_link_header :parse_link_header ,
23+ pageinated_api_call :pageinated_api_call
2024} ;
2125
2226/**
@@ -32,7 +36,7 @@ module.exports = {
3236 */
3337function createHooks ( reponame , url , secret , token , callback ) {
3438 var qpm = { access_token : token } ;
35- var post_url = GITHUB_API_ENDPOINT + ' /repos/' + reponame + ' /hooks' ;
39+ var post_url = ` ${ GITHUB_API_ENDPOINT } /repos/${ reponame } /hooks` ;
3640 debug ( 'CREATE WEBHOOK URL:' , post_url , url ) ;
3741 superagent
3842 . post ( post_url )
@@ -52,12 +56,11 @@ function createHooks(reponame, url, secret, token, callback) {
5256
5357 var badStatusErr ;
5458 if ( res . statusCode === 404 ) {
55- badStatusErr = new Error ( ' Cannot create webhooks; are you sure you have admin rights?\nFeel free to manually create a webhook for ' + url ) ;
59+ badStatusErr = new Error ( ` Cannot create webhooks; are you sure you have admin rights?\nFeel free to manually create a webhook for ${ url } ` ) ;
5660 badStatusErr . statusCode = res . statusCode ;
5761 return callback ( badStatusErr ) ;
58- }
59- else if ( res . statusCode !== 201 ) {
60- badStatusErr = new Error ( 'Bad status code: ' + res . statusCode ) ;
62+ } else if ( res . statusCode !== 201 ) {
63+ badStatusErr = new Error ( `Bad status code: ${ res . statusCode } ` ) ;
6164 badStatusErr . statusCode = res . statusCode ;
6265 return callback ( badStatusErr ) ;
6366 }
@@ -76,11 +79,11 @@ function createHooks(reponame, url, secret, token, callback) {
7679 * @param {Function } callback function(error, response, body)
7780 */
7881function deleteHooks ( reponame , url , token , callback ) {
79- var apiUrl = GITHUB_API_ENDPOINT + ' /repos/' + reponame + ' /hooks' ;
80- debug ( ' Delete hooks for ' + reponame + ' , identified by ' + url ) ;
82+ var apiUrl = ` ${ GITHUB_API_ENDPOINT } /repos/${ reponame } /hooks` ;
83+ debug ( ` Delete hooks for ${ reponame } , identified by ${ url } ` ) ;
8184 superagent
8285 . get ( apiUrl )
83- . set ( 'Authorization' , ' token ' + token )
86+ . set ( 'Authorization' , ` token ${ token } ` )
8487 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
8588 . end ( function ( err , res ) {
8689 if ( err ) return callback ( err ) ;
@@ -95,13 +98,13 @@ function deleteHooks(reponame, url, token, callback) {
9598 hooks . push ( function ( next ) {
9699 superagent
97100 . del ( hook . url )
98- . set ( 'Authorization' , ' token ' + token )
101+ . set ( 'Authorization' , ` token ${ token } ` )
99102 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
100103 . end ( function ( err , res ) {
101- if ( err ) return next ( new Error ( ' Failed to delete webhook ' + hook . url + ' Error: ' + err ) ) ;
104+ if ( err ) return next ( new Error ( ` Failed to delete webhook ${ hook . url } Error: ${ err } ` ) ) ;
102105 if ( res . status !== 204 ) {
103106 debug ( 'bad status' , res . status , hook . id , hook . url ) ;
104- return next ( new Error ( ' Failed to delete a webhook: status for url ' + hook . url + ': ' + res . status ) ) ;
107+ return next ( new Error ( ` Failed to delete a webhook: status for url ${ hook . url } : ${ res . status } ` ) ) ;
105108 }
106109 next ( ) ;
107110 } ) ;
@@ -115,9 +118,8 @@ function deleteHooks(reponame, url, token, callback) {
115118 } ) ;
116119}
117120
118-
119121function getBranches ( accessToken , owner , repo , done ) {
120- var path = ' /repos/' + owner + '/' + repo + ' /git/refs/heads' ;
122+ var path = ` /repos/${ owner } / ${ repo } /git/refs/heads` ;
121123 pageinated_api_call ( path , accessToken , function ( err , res ) {
122124 var branches = [ ] ;
123125 if ( res && res . data ) {
@@ -130,13 +132,13 @@ function getBranches(accessToken, owner, repo, done) {
130132}
131133
132134function getFile ( filename , ref , accessToken , owner , repo , done ) {
133- var uri = GITHUB_API_ENDPOINT + ' /repos/' + owner + '/' + repo + ' /contents/' + filename ;
135+ var uri = ` ${ GITHUB_API_ENDPOINT } /repos/${ owner } / ${ repo } /contents/${ filename } ` ;
134136 var req = superagent . get ( uri ) . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' ) ;
135137 if ( ref ) {
136138 req = req . query ( { ref : ref } ) ;
137139 }
138140 if ( accessToken ) {
139- req = req . set ( 'Authorization' , ' token ' + accessToken ) ;
141+ req = req . set ( 'Authorization' , ` token ${ accessToken } ` ) ;
140142 }
141143 req . end ( function ( err , res ) {
142144 if ( err ) return done ( err , null ) ;
@@ -158,19 +160,19 @@ function getFile(filename, ref, accessToken, owner, repo, done) {
158160 * @param {Function } callback function(error, response, body)
159161 * @param {Object } client An alternative superagent instance to use.
160162 */
161- var get_oauth2 = module . exports . get_oauth2 = function ( url , q_params , access_token , callback , client ) {
163+ function get_oauth2 ( url , q_params , access_token , callback , client ) {
162164 // If the user provided a superagent instance, use that.
163165 client = client || superagent ;
164166 // Construct the query. Allow the user to override the access_token through q_params.
165167 var query = _ . assign ( { } , { access_token : access_token } , q_params ) ;
166168 debug ( 'GET OAUTH2 URL:' , url ) ;
167- debug ( ' Inside get_oauth2: Callback type: ' + typeof callback + ' Number of arguments expected by: ' + callback . length ) ;
169+ debug ( ` Inside get_oauth2: Callback type: ${ typeof callback } Number of arguments expected by: ${ callback . length } ` ) ;
168170 client
169171 . get ( url )
170172 . query ( query )
171173 . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
172174 . end ( callback ) ;
173- } ;
175+ }
174176
175177/**
176178 * api_call()
@@ -182,7 +184,7 @@ var get_oauth2 = module.exports.get_oauth2 = function (url, q_params, access_tok
182184 * @param {Function } callback function(error, response, de-serialized json)
183185 * @param {Object } client An alternative superagent instance to use.
184186 */
185- var api_call = module . exports . api_call = function ( path , access_token , callback , client ) {
187+ function api_call ( path , access_token , callback , client ) {
186188 // If the user provided a superagent instance, use that.
187189 client = client || superagent ;
188190 var url = GITHUB_API_ENDPOINT + path ;
@@ -192,19 +194,19 @@ var api_call = module.exports.api_call = function (path, access_token, callback,
192194 var data = res . body ;
193195 callback ( null , res , data ) ;
194196 } else {
195- debug ( " We get an error from the API: " + error ) ;
197+ debug ( ` We get an error from the API: ${ error } ` ) ;
196198 callback ( error , res , null ) ;
197199 }
198200 } , client ) ;
199- } ;
201+ }
200202
201203/**
202204 * parse_link_header()
203205 *
204206 * Parse the Github Link HTTP header used for pagination
205207 * http://developer.github.com/v3/#pagination
206208 */
207- var parse_link_header = module . exports . parse_link_header = function parse_link_header ( header ) {
209+ function parse_link_header ( header ) {
208210 if ( header . length === 0 ) {
209211 throw new Error ( 'input must not be of zero length' ) ;
210212 }
@@ -224,8 +226,7 @@ var parse_link_header = module.exports.parse_link_header = function parse_link_h
224226 } ) ;
225227
226228 return links ;
227- } ;
228-
229+ }
229230
230231/**
231232 * pageinated_api_call()
@@ -238,7 +239,7 @@ var parse_link_header = module.exports.parse_link_header = function parse_link_h
238239 * @param {Function } callback function(error, response, de-serialized json)
239240 * @param {Object } client An alternative superagent instance to use.
240241 */
241- var pageinated_api_call = module . exports . pageinated_api_call = function ( path , access_token , callback , client ) {
242+ function pageinated_api_call ( path , access_token , callback , client ) {
242243 // If the user provided a superagent instance, use that.
243244 client = client || superagent ;
244245
@@ -282,13 +283,13 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
282283 }
283284 } else {
284285 if ( ! error ) {
285- debug ( " We did not get an error, but status code was: " + res . statusCode ) ;
286+ debug ( ` We did not get an error, but status code was: ${ res . statusCode } ` ) ;
286287 if ( res . statusCode === 401 || res . statusCode === 403 ) {
287- return callback ( new Error ( 'Github app is not authorized. Did you revoke access?' ) )
288+ return callback ( new Error ( 'Github app is not authorized. Did you revoke access?' ) ) ;
288289 }
289- return callback ( new Error ( ' Status code is ' + res . statusCode + ' not 200. Body: ' + res . body ) )
290+ return callback ( new Error ( ` Status code is ${ res . statusCode } not 200. Body: ${ res . body } ` ) ) ;
290291 } else {
291- debug ( " We did get an error from the API " + error ) ;
292+ debug ( ` We did get an error from the API ${ error } ` ) ;
292293 return callback ( error , null ) ;
293294 }
294295 }
@@ -297,7 +298,7 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
297298
298299 // Start from page 1
299300 loop ( base_url , 1 ) ;
300- } ;
301+ }
301302
302303/**
303304 * get_github_repos()
@@ -343,7 +344,7 @@ function getRepos(token, username, callback) {
343344 group : githubRepo . owner . login ,
344345 display_url : githubRepo . html_url ,
345346 config : {
346- url : ' git://' + githubRepo . clone_url . split ( '//' ) [ 1 ] ,
347+ url : ` git://${ githubRepo . clone_url . split ( '//' ) [ 1 ] } ` ,
347348 owner : githubRepo . owner . login ,
348349 repo : githubRepo . name ,
349350 auth : {
@@ -356,7 +357,7 @@ function getRepos(token, username, callback) {
356357 // For each Org, fetch the teams it has in parallel
357358 var group = this . group ( ) ;
358359 _ . each ( org_memberships , function ( org ) {
359- api_call ( ' /orgs/' + org . login + ' /teams' , token , group ( ) ) ;
360+ api_call ( ` /orgs/${ org . login } /teams` , token , group ( ) ) ;
360361 } ) ;
361362 } ,
362363 function fetchTeamDetails ( err , results ) {
@@ -382,7 +383,7 @@ function getRepos(token, username, callback) {
382383 // For each Team, fetch the detailed info (including privileges)
383384 var group = this . group ( ) ;
384385 _ . each ( teams , function ( team ) {
385- api_call ( ' /teams/' + team . id , token , group ( ) ) ;
386+ api_call ( ` /teams/${ team . id } ` , token , group ( ) ) ;
386387 } ) ;
387388 } ,
388389 function filterTeams ( err , results ) {
@@ -408,7 +409,7 @@ function getRepos(token, username, callback) {
408409 return ;
409410 }
410411 team_detail_requests [ team_details . id ] = team_details ;
411- var url = ' /teams/' + team_details . id + ' /members/' + username ;
412+ var url = ` /teams/${ team_details . id } /members/${ username } ` ;
412413 debug ( 'TEAM DETAIL URL' , url ) ;
413414 api_call ( url , token , group ( ) ) ;
414415 } ) ;
@@ -419,21 +420,17 @@ function getRepos(token, username, callback) {
419420 function fetchFilteredTeamRepos ( err , results ) {
420421 if ( err ) {
421422 debug ( 'get_github_repos(): Error with admin team memberships: %s' , err ) ;
422- return callback ( err )
423+ return callback ( err ) ;
423424 }
424- var team_detail_requests = this . team_detail_requests ;
425425 var group = this . group ( ) ;
426426
427427 _ . each ( results , function ( result ) {
428428 var team_id = result . req . path . match ( / t e a m s \/ ( [ 0 - 9 ] * ) / i) [ 1 ] ;
429- debug ( " We get the following repo path: " + util . inspect ( result . req . path ) ) ;
429+ debug ( ` We get the following repo path: ${ util . inspect ( result . req . path ) } ` ) ;
430430
431- // todo team_detail is unused
432- var team_detail = team_detail_requests [ parseInt ( team_id , 10 ) ] ;
433431 if ( result . statusCode === 204 ) {
434- pageinated_api_call ( ' /teams/' + team_id + ' /repos' , token , group ( ) ) ;
432+ pageinated_api_call ( ` /teams/${ team_id } /repos` , token , group ( ) ) ;
435433 }
436-
437434 } ) ;
438435 } ,
439436 // Reduce all the results and call output callback.
@@ -453,7 +450,7 @@ function getRepos(token, username, callback) {
453450 display_name : team_repo . full_name ,
454451 group : team_repo . owner . login ,
455452 config : {
456- url : ' git://' + team_repo . clone_url . split ( '//' ) [ 1 ] ,
453+ url : ` git://${ team_repo . clone_url . split ( '//' ) [ 1 ] } ` ,
457454 owner : team_repo . owner . login ,
458455 repo : team_repo . name ,
459456 auth : {
0 commit comments