mirror of
https://github.com/valitydev/repo-file-sync-action.git
synced 2024-11-06 09:55:21 +00:00
♻️ Throttle requests when hitting rate limit, fixes #49
This commit is contained in:
parent
228eceb431
commit
cee8520048
24950
dist/index.js
vendored
24950
dist/index.js
vendored
File diff suppressed because one or more lines are too long
12
package-lock.json
generated
12
package-lock.json
generated
@ -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": {
|
"@octokit/request": {
|
||||||
"version": "5.4.12",
|
"version": "5.4.12",
|
||||||
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.12.tgz",
|
"resolved": "https://registry.npmjs.org/@octokit/request/-/request-5.4.12.tgz",
|
||||||
@ -734,8 +743,7 @@
|
|||||||
"bottleneck": {
|
"bottleneck": {
|
||||||
"version": "2.19.5",
|
"version": "2.19.5",
|
||||||
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
|
"resolved": "https://registry.npmjs.org/bottleneck/-/bottleneck-2.19.5.tgz",
|
||||||
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw==",
|
"integrity": "sha512-VHiNCbI1lKdl44tGrhNfU3lup0Tj/ZBMJB5/2ZbNXRCPuRCO7ed2mgcK4r17y+KB2EfuYuRaVlwNbAeaWGSpbw=="
|
||||||
"dev": true
|
|
||||||
},
|
},
|
||||||
"brace-expansion": {
|
"brace-expansion": {
|
||||||
"version": "1.1.11",
|
"version": "1.1.11",
|
||||||
|
@ -29,6 +29,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": "^1.3.0",
|
"@actions/core": "^1.3.0",
|
||||||
"@actions/github": "^5.0.0",
|
"@actions/github": "^5.0.0",
|
||||||
|
"@octokit/plugin-throttling": "^3.4.1",
|
||||||
"@putout/git-status-porcelain": "^1.1.0",
|
"@putout/git-status-porcelain": "^1.1.0",
|
||||||
"action-input-parser": "^1.2.1",
|
"action-input-parser": "^1.2.1",
|
||||||
"fs-extra": "^10.0.0",
|
"fs-extra": "^10.0.0",
|
||||||
|
29
src/git.js
29
src/git.js
@ -1,5 +1,7 @@
|
|||||||
const { parse } = require('@putout/git-status-porcelain')
|
const { parse } = require('@putout/git-status-porcelain')
|
||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
|
const { GitHub, getOctokitOptions } = require('@actions/github/lib/utils')
|
||||||
|
const { throttling } = require('@octokit/plugin-throttling')
|
||||||
const path = require('path')
|
const path = require('path')
|
||||||
|
|
||||||
const {
|
const {
|
||||||
@ -16,6 +18,30 @@ const {
|
|||||||
|
|
||||||
const { dedent, execCmd } = require('./helpers')
|
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) => {
|
const init = (repo) => {
|
||||||
let github
|
let github
|
||||||
let baseBranch
|
let baseBranch
|
||||||
@ -211,5 +237,6 @@ const init = (repo) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
init
|
init,
|
||||||
|
getOctokit
|
||||||
}
|
}
|
@ -1,5 +1,4 @@
|
|||||||
const core = require('@actions/core')
|
const core = require('@actions/core')
|
||||||
const github = require('@actions/github')
|
|
||||||
const fs = require('fs')
|
const fs = require('fs')
|
||||||
|
|
||||||
const Git = require('./git')
|
const Git = require('./git')
|
||||||
@ -20,7 +19,8 @@ const {
|
|||||||
} = require('./config')
|
} = require('./config')
|
||||||
|
|
||||||
const run = async () => {
|
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()
|
const repos = await parseConfig()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user