♻️ Throttle requests when hitting rate limit, fixes #49

This commit is contained in:
BetaHuhn 2021-05-29 13:31:24 +02:00
parent 228eceb431
commit cee8520048
5 changed files with 3763 additions and 21233 deletions

24950
dist/index.js vendored

File diff suppressed because one or more lines are too long

12
package-lock.json generated
View File

@ -277,6 +277,15 @@
}
}
},
"@octokit/plugin-throttling": {
"version": "3.4.1",
"resolved": "https://registry.npmjs.org/@octokit/plugin-throttling/-/plugin-throttling-3.4.1.tgz",
"integrity": "sha512-qCQ+Z4AnL9OrXvV59EH3GzPxsB+WyqufoCjiCJXJxTbnt3W+leXbXw5vHrMp4NG9ltw00McFWIxIxNQAzLNoTA==",
"requires": {
"@octokit/types": "^6.0.1",
"bottleneck": "^2.15.3"
}
},
"@octokit/request": {
"version": "5.4.12",
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.12.tgz",
@ -734,8 +743,7 @@
"bottleneck": {
"version": "2.19.5",
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==",
"dev": true
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
},
"brace-expansion": {
"version": "1.1.11",

View File

@ -29,6 +29,7 @@
"dependencies": {
"@actions/core": "^1.3.0",
"@actions/github": "^5.0.0",
"@octokit/plugin-throttling": "^3.4.1",
"@putout/git-status-porcelain": "^1.1.0",
"action-input-parser": "^1.2.1",
"fs-extra": "^10.0.0",

View File

@ -1,5 +1,7 @@
const { parse } = require('@putout/git-status-porcelain')
const core = require('@actions/core')
const { GitHub, getOctokitOptions } = require('@actions/github/lib/utils')
const { throttling } = require('@octokit/plugin-throttling')
const path = require('path')
const {
@ -16,6 +18,30 @@ const {
const { dedent, execCmd } = require('./helpers')
const getOctokit = (token) => {
const Octokit = GitHub.plugin(throttling)
const options = getOctokitOptions(token, {
throttle: {
onRateLimit: (retryAfter, options) => {
core.warning(`Request quota exhausted for request ${ options.method } ${ options.url }`)
if (options.request.retryCount === 0) {
// only retries once
core.info(`Retrying after ${ retryAfter } seconds!`)
return true
}
},
onAbuseLimit: (retryAfter, options) => {
// does not retry, only logs a warning
core.warning(`Abuse detected for request ${ options.method } ${ options.url }`)
}
}
})
return new Octokit(options)
}
const init = (repo) => {
let github
let baseBranch
@ -211,5 +237,6 @@ const init = (repo) => {
}
module.exports = {
init
init,
getOctokit
}

View File

@ -1,5 +1,4 @@
const core = require('@actions/core')
const github = require('@actions/github')
const fs = require('fs')
const Git = require('./git')
@ -20,7 +19,8 @@ const {
} = require('./config')
const run = async () => {
const client = github.getOctokit(GITHUB_TOKEN)
const client = Git.getOctokit(GITHUB_TOKEN)
// const client = github.getOctokit(GITHUB_TOKEN)
const repos = await parseConfig()