forked from mirrors/probot
Add paginate to default github client object
This commit is contained in:
parent
4b483938f8
commit
dbc48c14f5
|
@ -0,0 +1,11 @@
|
|||
module.exports = async function paginate(responsePromise, callback) {
|
||||
let response = await responsePromise;
|
||||
let collection = await callback(response);
|
||||
|
||||
while (this.hasNextPage(response)) {
|
||||
response = await this.getNextPage(response);
|
||||
collection = collection.concat(await callback(response));
|
||||
}
|
||||
|
||||
return collection;
|
||||
}
|
10
lib/robot.js
10
lib/robot.js
|
@ -35,7 +35,7 @@ class Robot {
|
|||
|
||||
const github = new GitHubApi({debug: process.env.LOG_LEVEL === 'trace'});
|
||||
github.authenticate({type: 'token', token: token.token});
|
||||
return rateLimitedClient(github);
|
||||
return probotEnhancedClient(github);
|
||||
}
|
||||
|
||||
log(...args) {
|
||||
|
@ -43,6 +43,14 @@ class Robot {
|
|||
}
|
||||
}
|
||||
|
||||
function probotEnhancedClient(github) {
|
||||
github = rateLimitedClient(github);
|
||||
|
||||
github.paginate = require('./lib/paginate');
|
||||
|
||||
return github;
|
||||
}
|
||||
|
||||
// Hack client to only allow one request at a time with a 1s delay
|
||||
// https://github.com/mikedeboer/node-github/issues/526
|
||||
function rateLimitedClient(github) {
|
||||
|
|
Loading…
Reference in New Issue