diff --git a/dist/index.js b/dist/index.js index 7159211e..636b3783 100644 --- a/dist/index.js +++ b/dist/index.js @@ -4012,13 +4012,15 @@ __webpack_async_result__(); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0__ = __nccwpck_require__(2186); /* harmony import */ var _actions_core__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__nccwpck_require__.n(_actions_core__WEBPACK_IMPORTED_MODULE_0__); /* harmony import */ var _octokit_action__WEBPACK_IMPORTED_MODULE_1__ = __nccwpck_require__(1231); +/* harmony import */ var _octokit_plugin_retry__WEBPACK_IMPORTED_MODULE_3__ = __nccwpck_require__(6298); /* harmony import */ var _octokit_plugin_throttling__WEBPACK_IMPORTED_MODULE_2__ = __nccwpck_require__(9968); + const token = _actions_core__WEBPACK_IMPORTED_MODULE_0__.getInput('token') || process.env.GITHUB_TOKEN; -const ThrottlingOctokit = _octokit_action__WEBPACK_IMPORTED_MODULE_1__/* .Octokit.plugin */ .v.plugin(_octokit_plugin_throttling__WEBPACK_IMPORTED_MODULE_2__/* .throttling */ .O); -const octokit = new ThrottlingOctokit({ +const RetryAndThrottlingOctokit = _octokit_action__WEBPACK_IMPORTED_MODULE_1__/* .Octokit.plugin */ .v.plugin(_octokit_plugin_throttling__WEBPACK_IMPORTED_MODULE_2__/* .throttling */ .O, _octokit_plugin_retry__WEBPACK_IMPORTED_MODULE_3__/* .retry */ .XD); +const octokit = new RetryAndThrottlingOctokit({ auth: `token ${token}`, throttle: { onRateLimit: (retryAfter, options, o, retryCount) => { @@ -4032,6 +4034,10 @@ Retry count: ${retryCount} _actions_core__WEBPACK_IMPORTED_MODULE_0__.warning(`SecondaryRateLimit detected for request ${options.method} ${options.url}`); return true; } + }, + retry: { + doNotRetry: ['429'], + maxRetries: 10 } }); @@ -17565,6 +17571,97 @@ exports.restEndpointMethods = restEndpointMethods; //# sourceMappingURL=index.js.map +/***/ }), + +/***/ 6298: +/***/ ((__unused_webpack_module, exports, __nccwpck_require__) => { + +"use strict"; +var __webpack_unused_export__; + + +__webpack_unused_export__ = ({ value: true }); + +function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } + +var Bottleneck = _interopDefault(__nccwpck_require__(1174)); +var requestError = __nccwpck_require__(537); + +// @ts-ignore +async function errorRequest(state, octokit, error, options) { + if (!error.request || !error.request.request) { + // address https://github.com/octokit/plugin-retry.js/issues/8 + throw error; + } + // retry all >= 400 && not doNotRetry + if (error.status >= 400 && !state.doNotRetry.includes(error.status)) { + const retries = options.request.retries != null ? options.request.retries : state.retries; + const retryAfter = Math.pow((options.request.retryCount || 0) + 1, 2); + throw octokit.retry.retryRequest(error, retries, retryAfter); + } + // Maybe eventually there will be more cases here + throw error; +} + +// @ts-nocheck +async function wrapRequest(state, octokit, request, options) { + const limiter = new Bottleneck(); + limiter.on("failed", function (error, info) { + const maxRetries = ~~error.request.request.retries; + const after = ~~error.request.request.retryAfter; + options.request.retryCount = info.retryCount + 1; + if (maxRetries > info.retryCount) { + // Returning a number instructs the limiter to retry + // the request after that number of milliseconds have passed + return after * state.retryAfterBaseValue; + } + }); + return limiter.schedule(requestWithGraphqlErrorHandling.bind(null, state, octokit, request), options); +} +async function requestWithGraphqlErrorHandling(state, octokit, request, options) { + const response = await request(request, options); + if (response.data && response.data.errors && /Something went wrong while executing your query/.test(response.data.errors[0].message)) { + // simulate 500 request error for retry handling + const error = new requestError.RequestError(response.data.errors[0].message, 500, { + request: options, + response + }); + return errorRequest(state, octokit, error, options); + } + return response; +} + +const VERSION = "4.1.3"; +function retry(octokit, octokitOptions) { + const state = Object.assign({ + enabled: true, + retryAfterBaseValue: 1000, + doNotRetry: [400, 401, 403, 404, 422], + retries: 3 + }, octokitOptions.retry); + if (state.enabled) { + octokit.hook.error("request", errorRequest.bind(null, state, octokit)); + octokit.hook.wrap("request", wrapRequest.bind(null, state, octokit)); + } + return { + retry: { + retryRequest: (error, retries, retryAfter) => { + error.request.request = Object.assign({}, error.request.request, { + retries: retries, + retryAfter: retryAfter + }); + return error; + } + } + }; +} +retry.VERSION = VERSION; + +__webpack_unused_export__ = VERSION; +exports.XD = retry; +//# sourceMappingURL=index.js.map + + /***/ }), /***/ 9968: diff --git a/package-lock.json b/package-lock.json index b6a92e74..a38a9e2d 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@actions/github": "^5.1.1", "@dqbd/tiktoken": "^1.0.6", "@octokit/action": "^5.0.2", + "@octokit/plugin-retry": "^4.1.3", "@octokit/plugin-throttling": "^5.0.1", "minimatch": "^9.0.0", "node-fetch": "^3.3.1", @@ -1926,6 +1927,21 @@ "@octokit/openapi-types": "^12.11.0" } }, + "node_modules/@octokit/plugin-retry": { + "version": "4.1.3", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-4.1.3.tgz", + "integrity": "sha512-3YKBj7d0J/4mpEc4xzMociWsMNl5lZqrpAnYcW6mqiSGF3wFjU+c6GHih6GLClk31JNvKDr0x9jc5cfm7evkZg==", + "dependencies": { + "@octokit/types": "^9.0.0", + "bottleneck": "^2.15.3" + }, + "engines": { + "node": ">= 14" + }, + "peerDependencies": { + "@octokit/core": ">=3" + } + }, "node_modules/@octokit/plugin-throttling": { "version": "5.0.1", "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-5.0.1.tgz", diff --git a/package.json b/package.json index 10f54c32..637fa10c 100644 --- a/package.json +++ b/package.json @@ -29,6 +29,7 @@ "@actions/github": "^5.1.1", "@dqbd/tiktoken": "^1.0.6", "@octokit/action": "^5.0.2", + "@octokit/plugin-retry": "^4.1.3", "@octokit/plugin-throttling": "^5.0.1", "minimatch": "^9.0.0", "node-fetch": "^3.3.1", diff --git a/src/octokit.ts b/src/octokit.ts index 9aa3e53b..c7c0977c 100644 --- a/src/octokit.ts +++ b/src/octokit.ts @@ -1,11 +1,12 @@ import * as core from '@actions/core' import {Octokit} from '@octokit/action' +import {retry} from '@octokit/plugin-retry' import {throttling} from '@octokit/plugin-throttling' const token = core.getInput('token') || process.env.GITHUB_TOKEN -const ThrottlingOctokit = Octokit.plugin(throttling) -export const octokit = new ThrottlingOctokit({ +const RetryAndThrottlingOctokit = Octokit.plugin(throttling, retry) +export const octokit = new RetryAndThrottlingOctokit({ auth: `token ${token}`, throttle: { onRateLimit: ( @@ -28,5 +29,9 @@ Retry count: ${retryCount} ) return true } + }, + retry: { + doNotRetry: ['429'], + maxRetries: 10 } })