Fix null handling, covered by integration tests

`core.getInput()` always returns a string, so testing for 'not null'
is always true. This then leads to previews set to an array with
a single empty string, breaking accept-header output.

Updated eslint rules should help avoid this issue in future, and new
integration tests verify that the github client configuration now
reflects the intended configuration options.
This commit is contained in:
Martijn Pieters 2023-03-30 16:05:10 +01:00
parent 36d245c808
commit 454e5d7e69
No known key found for this signature in database
6 changed files with 1523 additions and 1323 deletions

View file

@ -6,10 +6,10 @@ import * as glob from '@actions/glob'
import * as io from '@actions/io'
import {retry} from '@octokit/plugin-retry'
import {RequestRequestOptions} from '@octokit/types'
import fetch from 'node-fetch'
import {callAsyncFunction} from './async-function'
import {getRetryOptions, parseNumberArray, RetryOptions} from './retry-options'
import {wrapRequire} from './wrap-require'
import fetch from 'node-fetch'
process.on('unhandledRejection', handleError)
main().catch(handleError)
@ -24,7 +24,7 @@ type Options = {
async function main(): Promise<void> {
const token = core.getInput('github-token', {required: true})
const debug = core.getInput('debug')
const debug = core.getBooleanInput('debug')
const userAgent = core.getInput('user-agent')
const previews = core.getInput('previews')
const retries = parseInt(core.getInput('retries'))
@ -37,11 +37,12 @@ async function main(): Promise<void> {
defaultGitHubOptions
)
const opts: Options = {}
if (debug === 'true') opts.log = console
if (userAgent != null) opts.userAgent = userAgent
if (previews != null) opts.previews = previews.split(',')
if (retryOpts) opts.retry = retryOpts
const opts: Options = {
retry: retryOpts
}
if (debug) opts.log = console
if (userAgent) opts.userAgent = userAgent
if (previews) opts.previews = previews.split(',')
if (requestOpts) opts.request = requestOpts
const github = getOctokit(token, opts, retry)

View file

@ -36,7 +36,7 @@ export function getRetryOptions(
`GitHub client configured with: (retries: ${
requestOptions.retries
}, retry-exempt-status-code: ${
retryOptions?.doNotRetry ?? 'octokit default: [400, 401, 403, 404, 422]'
retryOptions.doNotRetry ?? 'octokit default: [400, 401, 403, 404, 422]'
})`
)