mirror of
https://github.com/actions/github-script.git
synced 2025-12-09 12:26:21 +00:00
Add retry plugin
This commit is contained in:
47
src/main.ts
47
src/main.ts
@@ -3,6 +3,7 @@ import * as exec from '@actions/exec'
|
||||
import {context, getOctokit} from '@actions/github'
|
||||
import * as glob from '@actions/glob'
|
||||
import * as io from '@actions/io'
|
||||
import {retry} from '@octokit/plugin-retry'
|
||||
import {callAsyncFunction} from './async-function'
|
||||
import {wrapRequire} from './wrap-require'
|
||||
|
||||
@@ -13,6 +14,14 @@ type Options = {
|
||||
log?: Console
|
||||
userAgent?: string
|
||||
previews?: string[]
|
||||
retry?: {
|
||||
doNotRetry?: number[]
|
||||
enabled?: boolean
|
||||
}
|
||||
request?: {
|
||||
retries: number
|
||||
retryAfter: number
|
||||
}
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
@@ -20,13 +29,40 @@ async function main(): Promise<void> {
|
||||
const debug = core.getInput('debug')
|
||||
const userAgent = core.getInput('user-agent')
|
||||
const previews = core.getInput('previews')
|
||||
const retries = parseInt(core.getInput('retries'))
|
||||
const retryAfter = parseInt(core.getInput('retry-after'))
|
||||
const doNotRetry = parseNumberArray(core.getInput('do-not-retry'))
|
||||
|
||||
const opts: Options = {}
|
||||
if (debug === 'true') opts.log = console
|
||||
if (userAgent != null) opts.userAgent = userAgent
|
||||
if (previews != null) opts.previews = previews.split(',')
|
||||
|
||||
const github = getOctokit(token, opts)
|
||||
if (retries > 0) {
|
||||
if (doNotRetry.length > 0) {
|
||||
opts.retry = {doNotRetry}
|
||||
}
|
||||
|
||||
opts.request = {
|
||||
retries,
|
||||
retryAfter
|
||||
}
|
||||
|
||||
core.info(
|
||||
`GitHub client configured with: (retries: ${retries}, retryAfter: ${retryAfter}, doNotRetry: ${
|
||||
doNotRetry.length == 0
|
||||
? 'octokit default: [400, 401, 403, 404, 422]'
|
||||
: doNotRetry
|
||||
})`
|
||||
)
|
||||
} else {
|
||||
opts.retry = {
|
||||
enabled: false
|
||||
}
|
||||
}
|
||||
|
||||
const github = getOctokit(token, opts, retry)
|
||||
|
||||
const script = core.getInput('script', {required: true})
|
||||
|
||||
// Using property/value shorthand on `require` (e.g. `{require}`) causes compilation errors.
|
||||
@@ -68,3 +104,12 @@ function handleError(err: any): void {
|
||||
console.error(err)
|
||||
core.setFailed(`Unhandled error: ${err}`)
|
||||
}
|
||||
|
||||
function parseNumberArray(listString: string): number[] {
|
||||
if (!listString) {
|
||||
return []
|
||||
}
|
||||
|
||||
const split = listString.trim().split(',')
|
||||
return split.map(x => parseInt(x))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user