-
Notifications
You must be signed in to change notification settings - Fork 129
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: use retry and throttle octokit plugins (#487)
Co-authored-by: Jonas Pauthier <jonas.pauthier@gmail.com> Co-authored-by: Gregor Martynus <39992+gr2m@users.noreply.github.com>
- Loading branch information
1 parent
94a0a7b
commit 3dc59ec
Showing
23 changed files
with
1,745 additions
and
18,442 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/** | ||
* Default exponential backoff configuration for retries. | ||
*/ | ||
const RETRY_CONF = { | ||
// By default, Octokit does not retry on 404s. | ||
// But we want to retry on 404s to account for replication lag. | ||
doNotRetry: [400, 401, 403, 422], | ||
}; | ||
|
||
module.exports = {RETRY_CONF}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
/** | ||
* Default configuration for throttle. | ||
* @see https://github.com/octokit/plugin-throttling.js#options | ||
*/ | ||
const THROTTLE_CONF = {}; | ||
|
||
module.exports = {THROTTLE_CONF}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* istanbul ignore file */ | ||
|
||
// If maintaining @octokit/core and the separate plugins gets to cumbersome | ||
// then the `octokit` package can be used which has all these plugins included. | ||
// However the `octokit` package has a lot of other things we don't care about. | ||
// We use only the bits we need to minimize the size of the package. | ||
const {Octokit} = require('@octokit/core'); | ||
const {paginateRest} = require('@octokit/plugin-paginate-rest'); | ||
const {retry} = require('@octokit/plugin-retry'); | ||
const {throttling} = require('@octokit/plugin-throttling'); | ||
|
||
const {RETRY_CONF} = require('./definitions/retry'); | ||
const {THROTTLE_CONF} = require('./definitions/throttle'); | ||
const {version} = require('../package.json'); | ||
|
||
const onRetry = (retryAfter, options, octokit, retryCount) => { | ||
octokit.log.warn(`Request quota exhausted for request ${options.method} ${options.url}`); | ||
|
||
if (retryCount <= RETRY_CONF.retries) { | ||
octokit.log.debug(`Will retry after ${retryAfter}.`); | ||
return true; | ||
} | ||
}; | ||
|
||
const SemanticReleaseOctokit = Octokit.plugin(paginateRest, retry, throttling).defaults({ | ||
userAgent: `@semantic-release/github v${version}`, | ||
retry: RETRY_CONF, | ||
throttle: { | ||
...THROTTLE_CONF, | ||
onRateLimit: onRetry, | ||
onSecondaryRateLimit: onRetry, | ||
}, | ||
}); | ||
|
||
module.exports = SemanticReleaseOctokit; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.