1
0
Fork 0

move constants to retry-options

pull/1503/head
Bethany 2023-08-23 10:36:33 -07:00
parent 4b6a4d80e1
commit 06e751600e
3 changed files with 14 additions and 32 deletions

View File

@ -2,19 +2,11 @@ import {GetArtifactResponse} from '../shared/interfaces'
import {getOctokit} from '@actions/github' import {getOctokit} from '@actions/github'
import {getUserAgentString} from '../shared/user-agent' import {getUserAgentString} from '../shared/user-agent'
import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils' import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils'
import {RetryOptions, getRetryOptions} from './retry-options' import {getRetryOptions} from './retry-options'
import {RequestRequestOptions} from '@octokit/types'
import {requestLog} from '@octokit/plugin-request-log' import {requestLog} from '@octokit/plugin-request-log'
import {retry} from '@octokit/plugin-retry' import {retry} from '@octokit/plugin-retry'
import * as core from '@actions/core' import * as core from '@actions/core'
import {OctokitOptions} from '@octokit/core/dist-types/types'
type Options = {
log?: Console
userAgent?: string
previews?: string[]
retry?: RetryOptions
request?: RequestRequestOptions
}
const maxRetryNumber = 5 const maxRetryNumber = 5
const exemptStatusCodes = [400, 401, 403, 404, 422] // https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14 const exemptStatusCodes = [400, 401, 403, 404, 422] // https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
@ -32,7 +24,7 @@ export async function getArtifact(
defaultGitHubOptions defaultGitHubOptions
) )
const opts: Options = { const opts: OctokitOptions = {
log: undefined, log: undefined,
userAgent: getUserAgentString(), userAgent: getUserAgentString(),
previews: undefined, previews: undefined,

View File

@ -2,26 +2,16 @@ import {info, warning, debug} from '@actions/core'
import {getOctokit} from '@actions/github' import {getOctokit} from '@actions/github'
import {ListArtifactsResponse, Artifact} from '../shared/interfaces' import {ListArtifactsResponse, Artifact} from '../shared/interfaces'
import {getUserAgentString} from '../shared/user-agent' import {getUserAgentString} from '../shared/user-agent'
import {RetryOptions, getRetryOptions} from './retry-options' import {getRetryOptions} from './retry-options'
import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils' import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils'
import {requestLog} from '@octokit/plugin-request-log' import {requestLog} from '@octokit/plugin-request-log'
import {retry} from '@octokit/plugin-retry' import {retry} from '@octokit/plugin-retry'
import {RequestRequestOptions} from '@octokit/types' import {OctokitOptions} from '@octokit/core/dist-types/types'
type Options = {
log?: Console
userAgent?: string
previews?: string[]
retry?: RetryOptions
request?: RequestRequestOptions
}
// Limiting to 1000 for perf reasons // Limiting to 1000 for perf reasons
const maximumArtifactCount = 1000 const maximumArtifactCount = 1000
const paginationCount = 100 const paginationCount = 100
const maxNumberOfPages = maximumArtifactCount / paginationCount const maxNumberOfPages = maximumArtifactCount / paginationCount
const maxRetryNumber = 5
const exemptStatusCodes = [400, 401, 403, 404, 422] // https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
export async function listArtifacts( export async function listArtifacts(
workflowRunId: number, workflowRunId: number,
@ -34,13 +24,9 @@ export async function listArtifacts(
) )
const artifacts: Artifact[] = [] const artifacts: Artifact[] = []
const [retryOpts, requestOpts] = getRetryOptions( const [retryOpts, requestOpts] = getRetryOptions(defaultGitHubOptions)
maxRetryNumber,
exemptStatusCodes,
defaultGitHubOptions
)
const opts: Options = { const opts: OctokitOptions = {
log: undefined, log: undefined,
userAgent: getUserAgentString(), userAgent: getUserAgentString(),
previews: undefined, previews: undefined,

View File

@ -7,10 +7,14 @@ export type RetryOptions = {
enabled?: boolean enabled?: boolean
} }
// Defaults for fetching artifacts
const defaultMaxRetryNumber = 5
const defaultExemptStatusCodes = [400, 401, 403, 404, 422] // https://github.com/octokit/plugin-retry.js/blob/9a2443746c350b3beedec35cf26e197ea318a261/src/index.ts#L14
export function getRetryOptions( export function getRetryOptions(
retries: number, defaultOptions: OctokitOptions,
exemptStatusCodes: number[], retries: number = defaultMaxRetryNumber,
defaultOptions: OctokitOptions exemptStatusCodes: number[] = defaultExemptStatusCodes
): [RetryOptions, RequestRequestOptions | undefined] { ): [RetryOptions, RequestRequestOptions | undefined] {
if (retries <= 0) { if (retries <= 0) {
return [{enabled: false}, defaultOptions.request] return [{enabled: false}, defaultOptions.request]