diff --git a/lib/githubFetcher.js b/lib/githubFetcher.js index 9ccad4e..9ab6269 100644 --- a/lib/githubFetcher.js +++ b/lib/githubFetcher.js @@ -10,6 +10,7 @@ class GitHubFetcher { this.tokenFactory = tokenFactory; this.options = options; this.logger = options.logger; + this.options.reconfigure = this.reconfigure.bind(this); this.getQueue = async.queue(this._callGitHubTask.bind(this), options.concurrency || 5); } @@ -36,7 +37,7 @@ class GitHubFetcher { const self = this; const etagPromise = checkEtag ? this.store.etag(request.type, request.url) : Q(null); return etagPromise.then(etag => { - this._getFromGitHub(request, etag).then(githubResponse => { + return this._getFromGitHub(request, etag).then(githubResponse => { const status = githubResponse.statusCode; if (status !== 200 && status !== 304) { if (status === 409 || status === 204) { @@ -85,6 +86,11 @@ class GitHubFetcher { if (error) { return deferred.reject(error); } + // If response indicates something that may be related to Auth, note the token used + if ([401, 403, 404].includes(response.statusCode)) { + const token = options.headers.authorization.slice(6); + request.addMeta({ token: `${token.slice(0, 2)}..${token.slice(-2)}` }); + } request.addMeta({ status: response.statusCode, fetch: Date.now() - start }); deferred.resolve(response); }); @@ -187,7 +193,10 @@ class GitHubFetcher { const result = { orgs: { tokenTraits: ['admin'] }, org: { tokenTraits: ['admin'] }, + repos: { tokenTraits: ['admin'] }, + repo: { tokenTraits: ['admin'] }, teams: { tokenTraits: ['admin'] }, + team: { tokenTraits: ['admin'] }, members: { tokenTraits: ['admin'] }, collaborators: { tokenTraits: ['push'] }, reactions: { headers: { Accept: 'application/vnd.github.squirrel-girl-preview' } },