From 83dbed188f76ab04433c639ec214df65e26bc15c Mon Sep 17 00:00:00 2001 From: Peter Evans <18365890+peter-evans@users.noreply.github.com> Date: Wed, 18 Aug 2021 13:05:29 +0900 Subject: [PATCH] feat: retry 403 --- dist/index.js | 12 ++++++++++-- package-lock.json | 16 ++++++++++++++++ src/github-helper.ts | 6 ++++-- src/octokit-client.ts | 7 +++++++ 4 files changed, 37 insertions(+), 4 deletions(-) diff --git a/dist/index.js b/dist/index.js index cd9069b..8f12a2a 100644 --- a/dist/index.js +++ b/dist/index.js @@ -984,7 +984,9 @@ const octokit_client_1 = __nccwpck_require__(5040); const ERROR_PR_REVIEW_FROM_AUTHOR = 'Review cannot be requested from pull request author'; class GitHubHelper { constructor(token) { - const options = {}; + const options = { + retry: octokit_client_1.retryOptions + }; if (token) { options.auth = `${token}`; } @@ -1176,7 +1178,7 @@ run(); "use strict"; Object.defineProperty(exports, "__esModule", ({ value: true })); -exports.Octokit = void 0; +exports.retryOptions = exports.Octokit = void 0; const core_1 = __nccwpck_require__(6762); const plugin_paginate_rest_1 = __nccwpck_require__(4193); const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044); @@ -1193,6 +1195,12 @@ function autoProxyAgent(octokit) { options.request.agent = agent; }); } +exports.retryOptions = { + // Allow retry for 403 (rate-limiting / abuse detection) + doNotRetry: [400, 401, 404, 422], + retryAfterBaseValue: 2000, + retries: 3 +}; /***/ }), diff --git a/package-lock.json b/package-lock.json index 85b7786..4136a37 100644 --- a/package-lock.json +++ b/package-lock.json @@ -14,6 +14,8 @@ "@octokit/core": "3.5.1", "@octokit/plugin-paginate-rest": "2.14.0", "@octokit/plugin-rest-endpoint-methods": "5.5.0", + "@octokit/plugin-retry": "3.0.7", + "bottleneck": "2.19.5", "https-proxy-agent": "5.0.0", "uuid": "8.3.2" }, @@ -1421,6 +1423,15 @@ "@octokit/core": ">=3" } }, + "node_modules/@octokit/plugin-retry": { + "version": "3.0.7", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.7.tgz", + "integrity": "sha512-n08BPfVeKj5wnyH7IaOWnuKbx+e9rSJkhDHMJWXLPv61625uWjsN8G7sAW3zWm9n9vnS4friE7LL/XLcyGeG8Q==", + "dependencies": { + "@octokit/types": "^6.0.3", + "bottleneck": "^2.15.3" + } + }, "node_modules/@octokit/request": { "version": "5.6.0", "resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.0.tgz", @@ -2179,6 +2190,11 @@ "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz", "integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" }, + "node_modules/bottleneck": { + "version": "2.19.5", + "resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz", + "integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==" + }, "node_modules/brace-expansion": { "version": "1.1.11", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", diff --git a/src/github-helper.ts b/src/github-helper.ts index f72659a..7d4ab02 100644 --- a/src/github-helper.ts +++ b/src/github-helper.ts @@ -1,6 +1,6 @@ import * as core from '@actions/core' import {Inputs} from './create-pull-request' -import {Octokit, OctokitOptions} from './octokit-client' +import {Octokit, OctokitOptions, retryOptions} from './octokit-client' const ERROR_PR_REVIEW_FROM_AUTHOR = 'Review cannot be requested from pull request author' @@ -20,7 +20,9 @@ export class GitHubHelper { private octokit: InstanceType constructor(token: string) { - const options: OctokitOptions = {} + const options: OctokitOptions = { + retry: retryOptions + } if (token) { options.auth = `${token}` } diff --git a/src/octokit-client.ts b/src/octokit-client.ts index c436433..a329075 100644 --- a/src/octokit-client.ts +++ b/src/octokit-client.ts @@ -23,3 +23,10 @@ function autoProxyAgent(octokit: Core) { options.request.agent = agent }) } + +export const retryOptions = { + // Allow retry for 403 (rate-limiting / abuse detection) + doNotRetry: [400, 401, 404, 422], + retryAfterBaseValue: 2000, + retries: 3 +}