mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
51 lines
1012 B
TypeScript
51 lines
1012 B
TypeScript
import * as core from '@actions/core'
|
|
|
|
export type RetryOptions = {
|
|
doNotRetry?: number[]
|
|
enabled?: boolean
|
|
}
|
|
|
|
export type RequestOptions = {
|
|
retries?: number
|
|
}
|
|
|
|
export function getRetryOptions(
|
|
retries: number,
|
|
exemptStatusCodes: number[]
|
|
): [RetryOptions, RequestOptions] {
|
|
if (retries <= 0) {
|
|
return [{enabled: false}, {}]
|
|
}
|
|
|
|
const retryOptions: RetryOptions = {
|
|
enabled: true
|
|
}
|
|
|
|
if (exemptStatusCodes.length > 0) {
|
|
retryOptions.doNotRetry = exemptStatusCodes
|
|
}
|
|
|
|
const requestOptions: RequestOptions = {
|
|
retries
|
|
}
|
|
|
|
core.debug(
|
|
`GitHub client configured with: (retries: ${
|
|
requestOptions.retries
|
|
}, retry-exempt-status-code: ${
|
|
retryOptions?.doNotRetry ?? 'octokit default: [400, 401, 403, 404, 422]'
|
|
})`
|
|
)
|
|
|
|
return [retryOptions, requestOptions]
|
|
}
|
|
|
|
export function parseNumberArray(listString: string): number[] {
|
|
if (!listString) {
|
|
return []
|
|
}
|
|
|
|
const split = listString.trim().split(',')
|
|
return split.map(x => parseInt(x))
|
|
}
|