From 943958105652f03f431bd6665ef27b369b25a715 Mon Sep 17 00:00:00 2001 From: Igor Davydenko Date: Mon, 25 May 2020 02:39:23 +0200 Subject: [PATCH] fix: Update to latest throttling plugin (#53) In attempt to fix unintentional retries on 422 error from GitHub, 1. Update to latest `@octokit/plugin-throttling` version 2. Depend on `@octokit/plugin-retry` plugin as well Issue: #52 --- package-lock.json | 38 ++++++++++++++++++++++++++++++++++---- package.json | 3 ++- src/main.ts | 35 ++++++++++++++++++++--------------- 3 files changed, 56 insertions(+), 20 deletions(-) diff --git a/package-lock.json b/package-lock.json index 4bef185ab..fb1fa7ae1 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "action-gh-release", - "version": "0.1.4", + "version": "0.1.5", "lockfileVersion": 1, "requires": true, "dependencies": { @@ -434,12 +434,42 @@ "universal-user-agent": "^4.0.0" } }, + "@octokit/plugin-retry": { + "version": "3.0.2", + "resolved": "https://registry.npmjs.org/@octokit/plugin-retry/-/plugin-retry-3.0.2.tgz", + "integrity": "sha512-k7xl2WLfLP7WirRXRHtCq5xGAIXBZHV9X3HVUJhPwe8/N8vVzxPcnnnBL5NpEep/+GQqFRdYxrkgz68VY3z2wA==", + "requires": { + "@octokit/types": "^4.0.1", + "bottleneck": "^2.15.3" + }, + "dependencies": { + "@octokit/types": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-4.0.1.tgz", + "integrity": "sha512-Ho6h7w2h9y8RRE8r656hIj1oiSbwbIHJGF5r9G5FOwS2VdDPq8QLGvsG4x6pKHpvyGK7j+43sAc2cJKMiFoIJw==", + "requires": { + "@types/node": ">= 8" + } + } + } + }, "@octokit/plugin-throttling": { - "version": "2.7.1", - "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-2.7.1.tgz", - "integrity": "sha512-08CKNFCpSpmOEAQBn6/MR8zbJgjP4+bplNUJbKlqJSNBHTO1NdsDHzBD4VeFYopOo7rBEySng4WifxNVaQ5bVw==", + "version": "3.2.1", + "resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.2.1.tgz", + "integrity": "sha512-CGr3IagYZLLV3pFgpTQUthQSS5K3BkHLlG8yXK+Op3UKBkYrTf+Y9pCebrDxt60d+VTQ1oxXCx+LVLYY3IhBZQ==", "requires": { + "@octokit/types": "^4.0.1", "bottleneck": "^2.15.3" + }, + "dependencies": { + "@octokit/types": { + "version": "4.0.1", + "resolved": "https://registry.npmjs.org/@octokit/types/-/types-4.0.1.tgz", + "integrity": "sha512-Ho6h7w2h9y8RRE8r656hIj1oiSbwbIHJGF5r9G5FOwS2VdDPq8QLGvsG4x6pKHpvyGK7j+43sAc2cJKMiFoIJw==", + "requires": { + "@types/node": ">= 8" + } + } } }, "@octokit/request": { diff --git a/package.json b/package.json index 66eaa571b..7a4d857a8 100644 --- a/package.json +++ b/package.json @@ -22,7 +22,8 @@ "dependencies": { "@actions/core": "^1.2.0", "@actions/github": "^2.0.0", - "@octokit/plugin-throttling": "^2.7.1", + "@octokit/plugin-retry": "^3.0.2", + "@octokit/plugin-throttling": "^3.2.1", "glob": "^7.1.6", "mime": "^2.4.4" }, diff --git a/src/main.ts b/src/main.ts index 3385248dc..d731d5a6c 100644 --- a/src/main.ts +++ b/src/main.ts @@ -10,23 +10,28 @@ async function run() { if (!config.input_tag_name && !isTag(config.github_ref)) { throw new Error(`⚠️ GitHub Releases requires a tag`); } - GitHub.plugin(require("@octokit/plugin-throttling")); + GitHub.plugin([ + require("@octokit/plugin-throttling"), + require("@octokit/plugin-retry") + ]); const gh = new GitHub(config.github_token, { - onRateLimit: (retryAfter, options) => { - console.warn( - `Request quota exhausted for request ${options.method} ${options.url}` - ); - if (options.request.retryCount === 0) { - // only retries once - console.log(`Retrying after ${retryAfter} seconds!`); - return true; + throttle: { + onRateLimit: (retryAfter, options) => { + console.warn( + `Request quota exhausted for request ${options.method} ${options.url}` + ); + if (options.request.retryCount === 0) { + // only retries once + console.log(`Retrying after ${retryAfter} seconds!`); + return true; + } + }, + onAbuseLimit: (retryAfter, options) => { + // does not retry, only logs a warning + console.warn( + `Abuse detected for request ${options.method} ${options.url}` + ); } - }, - onAbuseLimit: (retryAfter, options) => { - // does not retry, only logs a warning - console.warn( - `Abuse detected for request ${options.method} ${options.url}` - ); } }); let rel = await release(config, new GitHubReleaser(gh));