Skip to content

Commit

Permalink
feat: implement recommended octokit plugins throttle and retry
Browse files Browse the repository at this point in the history
  • Loading branch information
stdavis committed Jan 8, 2021
1 parent 42fc92f commit 56d9081
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 31 deletions.
168 changes: 140 additions & 28 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
"@oclif/command": "^1.8.0",
"@oclif/config": "^1.17.0",
"@oclif/plugin-help": "^3.2.0",
"@octokit/plugin-retry": "^3.0.6",
"@octokit/plugin-throttling": "^3.3.4",
"@octokit/rest": "^18.0.6",
"chalk": "^4.1.0",
"cli-ux": "^5.5.0",
Expand Down
28 changes: 25 additions & 3 deletions src/issues.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,38 @@
const { Octokit } = require('@octokit/rest');
const { Octokit } = require('@octokit/core');
const parseGitHubUrl = require('parse-github-url');
const { getRepoUrl } = require('./packages');
const cliProgress = require('cli-progress');
const debug = require('debug')('good-samaritan');
const chalk = require('chalk');
const { throttling } = require('@octokit/plugin-throttling');
const { retry } = require('@octokit/plugin-retry');

const getIssues = async (dependencies, token, labels) => {
/*
dependencies: { dep: <version string>, dep2: <version string> }
*/
const octokit = new Octokit({
auth: token
const MyOctokit = Octokit.plugin(throttling, retry);
const octokit = new MyOctokit({
auth: token,
throttle: {
onRateLimit: (retryAfter, options, octokit) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
);

if (options.request.retryCount === 0) {
// only retries once
octokit.log.info(`Retrying after ${retryAfter} seconds!`);
return true;
}
},
onAbuseLimit: (_, options, octokit) => {
// does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
);
}
}
});

console.log('gathering issues from packages...');
Expand Down

0 comments on commit 56d9081

Please sign in to comment.