Skip to content

Commit

Permalink
feat: Use the retry plugin for octokit (#492)
Browse files Browse the repository at this point in the history
Co-authored-by: Aori Nevo <aorin@amazon.com>
  • Loading branch information
Borgstrom ♔ and aorinevo authored Sep 9, 2021
1 parent 05809b2 commit 278709d
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 3 deletions.
9 changes: 9 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
"lib"
],
"dependencies": {
"@octokit/plugin-retry": "^3.0.9",
"@octokit/rest": "^18.1.0",
"@types/js-yaml": "^3.12.6",
"chalk": "^4.1.0",
Expand Down
13 changes: 10 additions & 3 deletions src/services/github.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
/* eslint-disable class-methods-use-this */
import { Octokit } from '@octokit/rest';
import { retry } from '@octokit/plugin-retry';
import { RestEndpointMethodTypes } from '@octokit/plugin-rest-endpoint-methods'
import _ from 'lodash';
import netrc from 'netrc';

const VALID_SEARCH_TYPES: ReadonlyArray<string> = ['code', 'repositories'] as const;

interface SearchTypeAndQueryParams {
const RetryableOctokit = Octokit.plugin(retry);

interface SearchTypeAndQueryParams {
search_type?: string
search_query: string
}
Expand All @@ -26,8 +29,12 @@ export default class GithubService {
set a token on the 'password' field in ~/.netrc for api.github.com`);
}

this.octokit = new Octokit({
auth: token
this.octokit = new RetryableOctokit({
auth: token,
retry: {
// By default the doNotRetry setting includes 403, which means we face secondary rate limits
doNotRetry: [400, 401, 404, 422],
}
});
}
}
Expand Down

0 comments on commit 278709d

Please sign in to comment.