Skip to content

Commit

Permalink
fix: use @octokit/plugin-throttling
Browse files Browse the repository at this point in the history
  • Loading branch information
jedwards1211 committed May 7, 2019
1 parent 53f97f1 commit 64b071d
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 2 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
},
"dependencies": {
"@babel/runtime": "^7.1.5",
"@octokit/plugin-throttling": "^2.4.0",
"@octokit/rest": "^16.25.1",
"chalk": "^2.4.2",
"js-base64": "^2.5.1",
Expand Down
30 changes: 28 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,39 @@ import npmRegistryFetch from 'npm-registry-fetch'
import { Base64 } from 'js-base64'
import parseChangelog, { type Release } from './changelog-parser'
import semver from 'semver'
import Octokit from '@octokit/rest'
import _Octokit from '@octokit/rest'
import octokitThrottling from '@octokit/plugin-throttling'
import getNpmToken from './getNpmToken'
import memoize from './util/memoize'

const Octokit = _Octokit.plugin(octokitThrottling)

const { GH_TOKEN } = process.env

const octokitOptions = {}
type LimitOptions = {
method: string,
url: string,
request: {
retryCount: number,
},
}

const octokitOptions: Object = {
throttle: {
onRateLimit: (retryAfter: number, options: LimitOptions) => {
octokit.log.warn(
`Request quota exhausted for request ${options.method} ${options.url}`
)
return options.request.retryCount < 3
},
onAbuseLimit: (retryAfter: number, options: LimitOptions) => {
// does not retry, only logs a warning
octokit.log.warn(
`Abuse detected for request ${options.method} ${options.url}`
)
},
},
}
if (GH_TOKEN) octokitOptions.auth = `token ${GH_TOKEN}`
const octokit = new Octokit(octokitOptions)

Expand Down
12 changes: 12 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -922,6 +922,13 @@
universal-user-agent "^2.0.1"
url-template "^2.0.8"

"@octokit/plugin-throttling@^2.4.0":
version "2.4.0"
resolved "https://registry.yarnpkg.com/@octokit/plugin-throttling/-/plugin-throttling-2.4.0.tgz#add1bd6a797aa210ce860e8bbe7f7505ba5e4d99"
integrity sha512-0bYfgQdqAtWiqXvS6oKMiousTno+e3pFoaYS57LpAp8p56Far49/vpGvbEvBUuNyoUFgOcTGm5WTpO1IPptHuQ==
dependencies:
bottleneck "^2.15.3"

"@octokit/request@3.0.1":
version "3.0.1"
resolved "https://registry.yarnpkg.com/@octokit/request/-/request-3.0.1.tgz#21e888c6dce80566ec69477360bab79f2f14861f"
Expand Down Expand Up @@ -1518,6 +1525,11 @@ bottleneck@^2.0.1:
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.13.0.tgz#875df17df9e62c76bea42b62af3a45c73a995c4f"
integrity sha512-9YmZ0aiKta2OAxTujKCS/INjGWCIGWK4Ff1nQpgHnR4CTjlk9jcnpaHOjPnMZPtqRXkqwKdtxZgvJ9udsXylaw==

bottleneck@^2.15.3:
version "2.18.0"
resolved "https://registry.yarnpkg.com/bottleneck/-/bottleneck-2.18.0.tgz#41fa63ae185b65435d789d1700334bc48222dacf"
integrity sha512-U1xiBRaokw4yEguzikOl0VrnZp6uekjpmfrh6rKtr1D+/jFjYCL6J83ZXlGtlBDwVdTmJJ+4Lg5FpB3xmLSiyA==

boxen@^1.2.1:
version "1.3.0"
resolved "https://registry.yarnpkg.com/boxen/-/boxen-1.3.0.tgz#55c6c39a8ba58d9c61ad22cd877532deb665a20b"
Expand Down

0 comments on commit 64b071d

Please sign in to comment.