@@ -16,7 +16,11 @@ module.exports = {
16
16
getFile : getFile ,
17
17
getBranches : getBranches ,
18
18
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
20
24
} ;
21
25
22
26
/**
@@ -32,7 +36,7 @@ module.exports = {
32
36
*/
33
37
function createHooks ( reponame , url , secret , token , callback ) {
34
38
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` ;
36
40
debug ( 'CREATE WEBHOOK URL:' , post_url , url ) ;
37
41
superagent
38
42
. post ( post_url )
@@ -52,12 +56,11 @@ function createHooks(reponame, url, secret, token, callback) {
52
56
53
57
var badStatusErr ;
54
58
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 } ` ) ;
56
60
badStatusErr . statusCode = res . statusCode ;
57
61
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 } ` ) ;
61
64
badStatusErr . statusCode = res . statusCode ;
62
65
return callback ( badStatusErr ) ;
63
66
}
@@ -76,11 +79,11 @@ function createHooks(reponame, url, secret, token, callback) {
76
79
* @param {Function } callback function(error, response, body)
77
80
*/
78
81
function 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 } ` ) ;
81
84
superagent
82
85
. get ( apiUrl )
83
- . set ( 'Authorization' , ' token ' + token )
86
+ . set ( 'Authorization' , ` token ${ token } ` )
84
87
. set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
85
88
. end ( function ( err , res ) {
86
89
if ( err ) return callback ( err ) ;
@@ -95,13 +98,13 @@ function deleteHooks(reponame, url, token, callback) {
95
98
hooks . push ( function ( next ) {
96
99
superagent
97
100
. del ( hook . url )
98
- . set ( 'Authorization' , ' token ' + token )
101
+ . set ( 'Authorization' , ` token ${ token } ` )
99
102
. set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
100
103
. 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 } ` ) ) ;
102
105
if ( res . status !== 204 ) {
103
106
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 } ` ) ) ;
105
108
}
106
109
next ( ) ;
107
110
} ) ;
@@ -115,9 +118,8 @@ function deleteHooks(reponame, url, token, callback) {
115
118
} ) ;
116
119
}
117
120
118
-
119
121
function getBranches ( accessToken , owner , repo , done ) {
120
- var path = ' /repos/' + owner + '/' + repo + ' /git/refs/heads' ;
122
+ var path = ` /repos/${ owner } / ${ repo } /git/refs/heads` ;
121
123
pageinated_api_call ( path , accessToken , function ( err , res ) {
122
124
var branches = [ ] ;
123
125
if ( res && res . data ) {
@@ -130,13 +132,13 @@ function getBranches(accessToken, owner, repo, done) {
130
132
}
131
133
132
134
function 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 } ` ;
134
136
var req = superagent . get ( uri ) . set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' ) ;
135
137
if ( ref ) {
136
138
req = req . query ( { ref : ref } ) ;
137
139
}
138
140
if ( accessToken ) {
139
- req = req . set ( 'Authorization' , ' token ' + accessToken ) ;
141
+ req = req . set ( 'Authorization' , ` token ${ accessToken } ` ) ;
140
142
}
141
143
req . end ( function ( err , res ) {
142
144
if ( err ) return done ( err , null ) ;
@@ -158,19 +160,19 @@ function getFile(filename, ref, accessToken, owner, repo, done) {
158
160
* @param {Function } callback function(error, response, body)
159
161
* @param {Object } client An alternative superagent instance to use.
160
162
*/
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 ) {
162
164
// If the user provided a superagent instance, use that.
163
165
client = client || superagent ;
164
166
// Construct the query. Allow the user to override the access_token through q_params.
165
167
var query = _ . assign ( { } , { access_token : access_token } , q_params ) ;
166
168
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 } ` ) ;
168
170
client
169
171
. get ( url )
170
172
. query ( query )
171
173
. set ( 'User-Agent' , 'StriderCD (http://stridercd.com)' )
172
174
. end ( callback ) ;
173
- } ;
175
+ }
174
176
175
177
/**
176
178
* api_call()
@@ -182,7 +184,7 @@ var get_oauth2 = module.exports.get_oauth2 = function (url, q_params, access_tok
182
184
* @param {Function } callback function(error, response, de-serialized json)
183
185
* @param {Object } client An alternative superagent instance to use.
184
186
*/
185
- var api_call = module . exports . api_call = function ( path , access_token , callback , client ) {
187
+ function api_call ( path , access_token , callback , client ) {
186
188
// If the user provided a superagent instance, use that.
187
189
client = client || superagent ;
188
190
var url = GITHUB_API_ENDPOINT + path ;
@@ -192,19 +194,19 @@ var api_call = module.exports.api_call = function (path, access_token, callback,
192
194
var data = res . body ;
193
195
callback ( null , res , data ) ;
194
196
} else {
195
- debug ( " We get an error from the API: " + error ) ;
197
+ debug ( ` We get an error from the API: ${ error } ` ) ;
196
198
callback ( error , res , null ) ;
197
199
}
198
200
} , client ) ;
199
- } ;
201
+ }
200
202
201
203
/**
202
204
* parse_link_header()
203
205
*
204
206
* Parse the Github Link HTTP header used for pagination
205
207
* http://developer.github.com/v3/#pagination
206
208
*/
207
- var parse_link_header = module . exports . parse_link_header = function parse_link_header ( header ) {
209
+ function parse_link_header ( header ) {
208
210
if ( header . length === 0 ) {
209
211
throw new Error ( 'input must not be of zero length' ) ;
210
212
}
@@ -224,8 +226,7 @@ var parse_link_header = module.exports.parse_link_header = function parse_link_h
224
226
} ) ;
225
227
226
228
return links ;
227
- } ;
228
-
229
+ }
229
230
230
231
/**
231
232
* pageinated_api_call()
@@ -238,7 +239,7 @@ var parse_link_header = module.exports.parse_link_header = function parse_link_h
238
239
* @param {Function } callback function(error, response, de-serialized json)
239
240
* @param {Object } client An alternative superagent instance to use.
240
241
*/
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 ) {
242
243
// If the user provided a superagent instance, use that.
243
244
client = client || superagent ;
244
245
@@ -282,13 +283,13 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
282
283
}
283
284
} else {
284
285
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 } ` ) ;
286
287
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?' ) ) ;
288
289
}
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 } ` ) ) ;
290
291
} else {
291
- debug ( " We did get an error from the API " + error ) ;
292
+ debug ( ` We did get an error from the API ${ error } ` ) ;
292
293
return callback ( error , null ) ;
293
294
}
294
295
}
@@ -297,7 +298,7 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
297
298
298
299
// Start from page 1
299
300
loop ( base_url , 1 ) ;
300
- } ;
301
+ }
301
302
302
303
/**
303
304
* get_github_repos()
@@ -343,7 +344,7 @@ function getRepos(token, username, callback) {
343
344
group : githubRepo . owner . login ,
344
345
display_url : githubRepo . html_url ,
345
346
config : {
346
- url : ' git://' + githubRepo . clone_url . split ( '//' ) [ 1 ] ,
347
+ url : ` git://${ githubRepo . clone_url . split ( '//' ) [ 1 ] } ` ,
347
348
owner : githubRepo . owner . login ,
348
349
repo : githubRepo . name ,
349
350
auth : {
@@ -356,7 +357,7 @@ function getRepos(token, username, callback) {
356
357
// For each Org, fetch the teams it has in parallel
357
358
var group = this . group ( ) ;
358
359
_ . each ( org_memberships , function ( org ) {
359
- api_call ( ' /orgs/' + org . login + ' /teams' , token , group ( ) ) ;
360
+ api_call ( ` /orgs/${ org . login } /teams` , token , group ( ) ) ;
360
361
} ) ;
361
362
} ,
362
363
function fetchTeamDetails ( err , results ) {
@@ -382,7 +383,7 @@ function getRepos(token, username, callback) {
382
383
// For each Team, fetch the detailed info (including privileges)
383
384
var group = this . group ( ) ;
384
385
_ . each ( teams , function ( team ) {
385
- api_call ( ' /teams/' + team . id , token , group ( ) ) ;
386
+ api_call ( ` /teams/${ team . id } ` , token , group ( ) ) ;
386
387
} ) ;
387
388
} ,
388
389
function filterTeams ( err , results ) {
@@ -408,7 +409,7 @@ function getRepos(token, username, callback) {
408
409
return ;
409
410
}
410
411
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 } ` ;
412
413
debug ( 'TEAM DETAIL URL' , url ) ;
413
414
api_call ( url , token , group ( ) ) ;
414
415
} ) ;
@@ -419,21 +420,17 @@ function getRepos(token, username, callback) {
419
420
function fetchFilteredTeamRepos ( err , results ) {
420
421
if ( err ) {
421
422
debug ( 'get_github_repos(): Error with admin team memberships: %s' , err ) ;
422
- return callback ( err )
423
+ return callback ( err ) ;
423
424
}
424
- var team_detail_requests = this . team_detail_requests ;
425
425
var group = this . group ( ) ;
426
426
427
427
_ . each ( results , function ( result ) {
428
428
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 ) } ` ) ;
430
430
431
- // todo team_detail is unused
432
- var team_detail = team_detail_requests [ parseInt ( team_id , 10 ) ] ;
433
431
if ( result . statusCode === 204 ) {
434
- pageinated_api_call ( ' /teams/' + team_id + ' /repos' , token , group ( ) ) ;
432
+ pageinated_api_call ( ` /teams/${ team_id } /repos` , token , group ( ) ) ;
435
433
}
436
-
437
434
} ) ;
438
435
} ,
439
436
// Reduce all the results and call output callback.
@@ -453,7 +450,7 @@ function getRepos(token, username, callback) {
453
450
display_name : team_repo . full_name ,
454
451
group : team_repo . owner . login ,
455
452
config : {
456
- url : ' git://' + team_repo . clone_url . split ( '//' ) [ 1 ] ,
453
+ url : ` git://${ team_repo . clone_url . split ( '//' ) [ 1 ] } ` ,
457
454
owner : team_repo . owner . login ,
458
455
repo : team_repo . name ,
459
456
auth : {
0 commit comments