robot.auth as integration or installation

This commit is contained in:
Brandon Keepers 2017-03-30 15:00:37 -07:00
parent dbc48c14f5
commit 5d8e229353
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
1 changed files with 14 additions and 7 deletions

View File

@ -28,13 +28,20 @@ class Robot {
}
async auth(id) {
const token = await this.cache.wrap(`integration:${id}:token`, () => {
this.log.info(`creating token for installation ${id}`);
return this.integration.createToken(id);
}, {ttl: 60 * 60});
let github;
if(id) {
const token = await this.cache.wrap(`integration:${id}:token`, () => {
this.log.info(`creating token for installation ${id}`);
return this.integration.createToken(id);
}, {ttl: 60 * 60});
github = new GitHubApi({debug: process.env.LOG_LEVEL === 'trace'});
github.authenticate({type: 'token', token: token.token});
} else {
github = await this.integration.asIntegration();
}
const github = new GitHubApi({debug: process.env.LOG_LEVEL === 'trace'});
github.authenticate({type: 'token', token: token.token});
return probotEnhancedClient(github);
}
@ -46,7 +53,7 @@ class Robot {
function probotEnhancedClient(github) {
github = rateLimitedClient(github);
github.paginate = require('./lib/paginate');
github.paginate = require('./paginate');
return github;
}