Skip to content

Commit 1f9230e

Browse files
Cleanup
1 parent 96a94fd commit 1f9230e

11 files changed

+203
-169
lines changed

.editorconfig

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,22 @@
1-
# editorconfig.org
1+
# Strider Editor/IDE Settings
2+
# This file is used to promote consistent source code standards
3+
# amongst all Strider-CD contributors.
4+
# More information can be found here: http://editorconfig.org/
5+
6+
# General Settings
27
root = true
38

9+
# Settings for all files
410
[*]
511
indent_style = space
612
indent_size = 2
713
end_of_line = lf
814
charset = utf-8
915
trim_trailing_whitespace = true
1016
insert_final_newline = true
11-
continuation_indent = 4
1217

13-
[package.json]
14-
indent_style = space
15-
indent_size = 2
18+
[*.hbs]
19+
insert_final_newline = false
20+
21+
[*.{diff,md}]
22+
trim_trailing_whitespace = false

.eslintrc

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
{
2+
"parserOptions": {
3+
"ecmaVersion": 6,
4+
"sourceType": "script"
5+
},
6+
"env": {
7+
"node": true,
8+
"es6": true
9+
},
10+
"extends": "eslint:recommended",
11+
"rules": {
12+
"indent": [2, 2],
13+
"brace-style": [2, "1tbs"],
14+
"quotes": [2, "single"],
15+
"semi": [2, "always"],
16+
"comma-style": [2, "last"],
17+
"one-var": [2, "never"],
18+
"strict": [2, "global"],
19+
"prefer-template": 2,
20+
"no-console": 0,
21+
"no-use-before-define": [2, "nofunc"],
22+
"no-underscore-dangle": 0,
23+
"no-constant-condition": 0,
24+
"space-before-function-paren": [2, {"anonymous": "always", "named": "never"}],
25+
"func-style": [2, "declaration"]
26+
}
27+
}

.jshintrc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,3 @@ language: node_js
22
node_js:
33
- "4"
44
- "node"
5-
6-
sudo: false

lib/api.js

Lines changed: 40 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -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
*/
3337
function 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
*/
7881
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}`);
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-
119121
function 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

132134
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}`;
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(/teams\/([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: {

lib/github.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ module.exports.github_metadata = function (req, res) {
6060
req.user['github_metadata'] = {};
6161
req.user['github_metadata'][req.user.github.id] = data;
6262
addConfiguredKeys(req.user, data.repos);
63-
req.user.save(function (err, user) {
63+
req.user.save(function () {
6464
var output = JSON.stringify(data, null, '\t');
6565
res.end(output);
6666
});
@@ -120,7 +120,7 @@ module.exports.post_manual_setup = function (req, res) {
120120
User.findOne({'github_config.url': github_url.toLowerCase()}, function (err, user) {
121121
var r;
122122
if (user) {
123-
debug('Dupe repo: ' + github_url + ' requested by ' + req.user.email);
123+
debug(`Dupe repo: ${github_url} requested by ${req.user.email}`);
124124
res.statusCode = 400;
125125
r = {
126126
status: 'error',
@@ -132,17 +132,17 @@ module.exports.post_manual_setup = function (req, res) {
132132
// validate again (after backbone validation) bc api request could be from other source
133133
var p = gh.parse_github_url(github_url);
134134
if (p === null) {
135-
debug('invalid github url: ' + github_url);
135+
debug(`invalid github url: ${github_url}`);
136136
res.statusCode = 400;
137137
r = {
138138
status: 'error',
139139
errors: 'Not a valid Github URL'
140140
};
141141
return res.end(JSON.stringify(r), null, '\t');
142142
}
143-
debug('org: ' + p.org + ' - name: ' + p.repo);
143+
debug(`org: ${p.org} - name: ${p.repo}`);
144144

145-
var repo_url = 'https://github.com/' + p.org + '/' + p.repo;
145+
var repo_url = `https://github.com/${p.org}/${p.repo}`;
146146

147147
gh.setup_integration_manual(req, p.org, repo_url,
148148
function (webhook, deploy_key_title, deploy_public_key) {

0 commit comments

Comments
 (0)