feat: retry 403

This commit is contained in:
Peter Evans 2021-08-18 13:05:29 +09:00
parent ce53a56b63
commit 83dbed188f
4 changed files with 37 additions and 4 deletions

12
dist/index.js vendored
View file

@ -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'; const ERROR_PR_REVIEW_FROM_AUTHOR = 'Review cannot be requested from pull request author';
class GitHubHelper { class GitHubHelper {
constructor(token) { constructor(token) {
const options = {}; const options = {
retry: octokit_client_1.retryOptions
};
if (token) { if (token) {
options.auth = `${token}`; options.auth = `${token}`;
} }
@ -1176,7 +1178,7 @@ run();
"use strict"; "use strict";
Object.defineProperty(exports, "__esModule", ({ value: true })); Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.Octokit = void 0; exports.retryOptions = exports.Octokit = void 0;
const core_1 = __nccwpck_require__(6762); const core_1 = __nccwpck_require__(6762);
const plugin_paginate_rest_1 = __nccwpck_require__(4193); const plugin_paginate_rest_1 = __nccwpck_require__(4193);
const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044); const plugin_rest_endpoint_methods_1 = __nccwpck_require__(3044);
@ -1193,6 +1195,12 @@ function autoProxyAgent(octokit) {
options.request.agent = agent; options.request.agent = agent;
}); });
} }
exports.retryOptions = {
// Allow retry for 403 (rate-limiting / abuse detection)
doNotRetry: [400, 401, 404, 422],
retryAfterBaseValue: 2000,
retries: 3
};
/***/ }), /***/ }),

16
package-lock.json generated
View file

@ -14,6 +14,8 @@
"@octokit/core": "3.5.1", "@octokit/core": "3.5.1",
"@octokit/plugin-paginate-rest": "2.14.0", "@octokit/plugin-paginate-rest": "2.14.0",
"@octokit/plugin-rest-endpoint-methods": "5.5.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", "https-proxy-agent": "5.0.0",
"uuid": "8.3.2" "uuid": "8.3.2"
}, },
@ -1421,6 +1423,15 @@
"@octokit/core": ">=3" "@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": { "node_modules/@octokit/request": {
"version": "5.6.0", "version": "5.6.0",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.6.0.tgz", "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", "resolved": "https://registry.npmjs.org/before-after-hook/-/before-after-hook-2.2.2.tgz",
"integrity": "sha512-3pZEU3NT5BFUo/AD5ERPWOgQOCZITni6iavr5AUw5AUwQjMlI0kzu5btnyD39AF0gUEsDPwJT+oY1ORBJijPjQ==" "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": { "node_modules/brace-expansion": {
"version": "1.1.11", "version": "1.1.11",
"resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz",

View file

@ -1,6 +1,6 @@
import * as core from '@actions/core' import * as core from '@actions/core'
import {Inputs} from './create-pull-request' 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 = const ERROR_PR_REVIEW_FROM_AUTHOR =
'Review cannot be requested from pull request author' 'Review cannot be requested from pull request author'
@ -20,7 +20,9 @@ export class GitHubHelper {
private octokit: InstanceType<typeof Octokit> private octokit: InstanceType<typeof Octokit>
constructor(token: string) { constructor(token: string) {
const options: OctokitOptions = {} const options: OctokitOptions = {
retry: retryOptions
}
if (token) { if (token) {
options.auth = `${token}` options.auth = `${token}`
} }

View file

@ -23,3 +23,10 @@ function autoProxyAgent(octokit: Core) {
options.request.agent = agent options.request.agent = agent
}) })
} }
export const retryOptions = {
// Allow retry for 403 (rate-limiting / abuse detection)
doNotRetry: [400, 401, 404, 422],
retryAfterBaseValue: 2000,
retries: 3
}