Skip to content

Commit c31408e

Browse files
author
Ilya Radchenko
committed
Merge pull request #43 from oliversalzburg/feature/debug
Use debug instead of console
2 parents 033cf0d + 82672b2 commit c31408e

File tree

5 files changed

+77
-73
lines changed

5 files changed

+77
-73
lines changed

lib/api.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function deleteHooks(reponame, url, token, callback) {
8989
.set('User-Agent', 'StriderCD (http://stridercd.com)')
9090
.end(function (res) {
9191
if (res.status !== 204) {
92-
console.log('bad status', res.status, hook.id, hook.url);
92+
debug('bad status', res.status, hook.id, hook.url);
9393
return next(new Error('Failed to delete a webhook: status for url ' + hook.url + ': ' + res.status));
9494
}
9595
next();
@@ -151,7 +151,7 @@ var get_oauth2 = module.exports.get_oauth2 = function (url, q_params, access_tok
151151
client = client || superagent;
152152
// Construct the query. Allow the user to override the access_token through q_params.
153153
var query = _.assign({}, {access_token : access_token}, q_params);
154-
console.debug('GET OAUTH2 URL:', url);
154+
debug('GET OAUTH2 URL:', url);
155155
client
156156
.get(url)
157157
.query(query)
@@ -173,7 +173,7 @@ var api_call = module.exports.api_call = function (path, access_token, callback,
173173
// If the user provided a superagent instance, use that.
174174
client = client || superagent;
175175
var url = GITHUB_API_ENDPOINT + path;
176-
console.debug('API CALL:', url, access_token);
176+
debug('API CALL:', url, params, access_token);
177177
get_oauth2(url, {}, access_token, function (error, res, body) {
178178
if (!error && res.statusCode == 200) {
179179
var data = JSON.parse(body);
@@ -231,8 +231,8 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
231231
var base_url = GITHUB_API_ENDPOINT + path;
232232

233233
if (!access_token) {
234-
console.error('Error in request - no access token');
235-
console.trace();
234+
debug('Error in request - no access token');
235+
debug(new Error().stack);
236236
}
237237

238238
// This is a left fold,
@@ -241,7 +241,7 @@ var pageinated_api_call = module.exports.pageinated_api_call = function (path, a
241241
var pages = [];
242242

243243
function loop(uri, page) {
244-
console.debug('PAGINATED API CALL URL:', uri);
244+
debug('PAGINATED API CALL URL:', uri);
245245
get_oauth2(uri, {per_page: 30, page: page}, access_token, function (error, res, body) {
246246
if (!error && res.statusCode == 200) {
247247
var data;
@@ -310,7 +310,7 @@ function getRepos(token, username, callback) {
310310
},
311311
function fetchOrgTeams(err, githubRepos, githubOrgas) {
312312
if (err) {
313-
console.error('get_github_repos() - Error fetching repos & orgs: %s', err);
313+
debug('get_github_repos() - Error fetching repos & orgs: %s', err);
314314
return callback(err);
315315
}
316316
if (!githubRepos) return callback('Get repos failed; no response');
@@ -343,7 +343,7 @@ function getRepos(token, username, callback) {
343343
},
344344
function fetchTeamDetails(err, results) {
345345
if (err) {
346-
console.error('get_github_repos() - Error fetching Org Teams response - %s', err);
346+
debug('get_github_repos() - Error fetching Org Teams response - %s', err);
347347
return callback(err);
348348
}
349349
var teams = [];
@@ -354,7 +354,7 @@ function getRepos(token, username, callback) {
354354
teams.push(t);
355355
});
356356
} catch (e) {
357-
console.error('get_github_repos(): Error parsing JSON in Org Teams response - %s', e);
357+
debug('get_github_repos(): Error parsing JSON in Org Teams response - %s', e);
358358
}
359359
});
360360

@@ -366,7 +366,7 @@ function getRepos(token, username, callback) {
366366
},
367367
function filterTeams(err, results) {
368368
if (err) {
369-
console.error('get_github_repos() - Error fetching detailed team response - %s', err);
369+
debug('get_github_repos() - Error fetching detailed team response - %s', err);
370370
return callback(err);
371371
}
372372
var team_details = [];
@@ -375,7 +375,7 @@ function getRepos(token, username, callback) {
375375
var td = JSON.parse(result.body);
376376
team_details.push(td);
377377
} catch (e) {
378-
console.error('get_github_repos(): Error parsing JSON in detail team response - %s', e);
378+
debug('get_github_repos(): Error parsing JSON in detail team response - %s', e);
379379
}
380380
});
381381
// For each Team with admin privs, test for membership
@@ -387,7 +387,7 @@ function getRepos(token, username, callback) {
387387
}
388388
team_detail_requests[team_details.id] = team_details;
389389
var url = GITHUB_API_ENDPOINT + '/teams/' + team_details.id + '/members/' + username;
390-
console.debug('TEAM DETAIL URL', url);
390+
debug('TEAM DETAIL URL', url);
391391
get_oauth2(url, {}, token, group());
392392
});
393393
this.team_detail_requests = team_detail_requests;
@@ -396,7 +396,7 @@ function getRepos(token, username, callback) {
396396
// the list of repositories it has access to.
397397
function fetchFilteredTeamRepos(err, results) {
398398
if (err) {
399-
console.debug('get_github_repos(): Error with admin team memberships: %s', err);
399+
debug('get_github_repos(): Error with admin team memberships: %s', err);
400400
return callback(err)
401401
}
402402
var team_detail_requests = this.team_detail_requests;
@@ -421,7 +421,7 @@ function getRepos(token, username, callback) {
421421
// Reduce all the results and call output callback.
422422
function finalize(err, results) {
423423
if (err) {
424-
console.debug('get_github_repos(): Error with team repos request: %s', err);
424+
debug('get_github_repos(): Error with team repos request: %s', err);
425425
return callback(err);
426426
}
427427
_.each(results, function (result) {

lib/github.js

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
'use strict';
22

33
var _ = require('lodash');
4+
var debug = require('debug')('strider-github:github');
45
var gh = require('../../lib/github');
56
var User = require('../../lib/models').User;
67

@@ -23,11 +24,11 @@ function addConfiguredKeys(user, repos) {
2324
var already_configured = configuredReposList(user);
2425
_.each(repos, function (repo) {
2526
if (!repo) {
26-
console.error('addConfiguredKeys(): repo is %s', repo);
27+
debug('addConfiguredKeys(): repo is %s', repo);
2728
return;
2829
}
2930
if (repo.html_url === undefined) {
30-
console.error('addConfiguredKeys(): repo.html_url is undefined. Full repo: %j', repo);
31+
debug('addConfiguredKeys(): repo.html_url is undefined. Full repo: %j', repo);
3132
repo.configured = false;
3233
return;
3334
}
@@ -91,7 +92,7 @@ module.exports.github_webhooks_unset = function (req, res) {
9192
return;
9293
}
9394
var token = req.user.get('github.accessToken');
94-
console.debug('url: %s', url);
95+
debug('url: %s', url);
9596
req.user.get_repo_config(url, function (err, repo) {
9697
if (err || !repo) {
9798
results = {status: 'error', errors: [{message: 'invalid url for this user'}]};
@@ -100,7 +101,7 @@ module.exports.github_webhooks_unset = function (req, res) {
100101
}
101102
var gh_repo_path = url.replace(/^.*com/gi, '');
102103

103-
console.debug('github.github_webhooks_unset(): unsetting hooks for user %s on repo %s',
104+
debug('github.github_webhooks_unset(): unsetting hooks for user %s on repo %s',
104105
req.user.email, gh_repo_path);
105106
gh.unset_push_hook(gh_repo_path, token, function () {
106107
results = {status: 'ok', errors: []};
@@ -117,9 +118,9 @@ module.exports.post_manual_setup = function (req, res) {
117118
// check to see if this project already exists. if it does, error on that
118119
// Check whether someone else has already configured this repository
119120
User.findOne({'github_config.url': github_url.toLowerCase()}, function (err, user) {
120-
var r
121+
var r;
121122
if (user) {
122-
console.log('Dupe repo: ' + github_url + ' requested by ' + req.user.email);
123+
debug('Dupe repo: ' + github_url + ' requested by ' + req.user.email);
123124
res.statusCode = 400;
124125
r = {
125126
status: 'error',
@@ -131,15 +132,15 @@ module.exports.post_manual_setup = function (req, res) {
131132
// validate again (after backbone validation) bc api request could be from other source
132133
var p = gh.parse_github_url(github_url);
133134
if (p === null) {
134-
console.log('invalid github url: ' + github_url);
135+
debug('invalid github url: ' + github_url);
135136
res.statusCode = 400;
136137
r = {
137138
status: 'error',
138139
errors: 'Not a valid Github URL'
139140
};
140141
return res.end(JSON.stringify(r), null, '\t');
141142
}
142-
console.log('org: ' + p.org + ' - name: ' + p.repo);
143+
debug('org: ' + p.org + ' - name: ' + p.repo);
143144

144145
var repo_url = 'https://github.com/' + p.org + '/' + p.repo;
145146

@@ -155,7 +156,7 @@ module.exports.post_manual_setup = function (req, res) {
155156
};
156157

157158
var output = JSON.stringify(obj, null, '\t');
158-
console.debug('post_manual_setup() - output: %j', output);
159+
debug('post_manual_setup() - output: %j', output);
159160
res.end(output);
160161
});
161162
});

0 commit comments

Comments
 (0)