Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Fix overriding request options from @actions/github #293

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 2 .licenses/npm/@actions/github.dep.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

44 changes: 36 additions & 8 deletions 44 __test__/get-retry-options.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,38 +4,66 @@ import {getRetryOptions} from '../src/retry-options'

describe('getRequestOptions', () => {
test('retries disabled if retries == 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(0, [400, 500, 502])
const [retryOptions, requestOptions] = getRetryOptions(
0,
[400, 500, 502],
[]
)

expect(retryOptions.enabled).toBe(false)
expect(retryOptions.doNotRetry).toBeFalsy()

expect(requestOptions.retries).toBeFalsy()
expect(requestOptions?.retries).toBeFalsy()
})

test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, [400, 500, 502])
const [retryOptions, requestOptions] = getRetryOptions(
1,
[400, 500, 502],
[]
)

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])

expect(requestOptions.retries).toEqual(1)
expect(requestOptions?.retries).toEqual(1)
})

test('properties set if retries > 0', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, [400, 500, 502])
const [retryOptions, requestOptions] = getRetryOptions(
1,
[400, 500, 502],
[]
)

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toEqual([400, 500, 502])

expect(requestOptions.retries).toEqual(1)
expect(requestOptions?.retries).toEqual(1)
})

test('retryOptions.doNotRetry not set if exemptStatusCodes isEmpty', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, [])
const [retryOptions, requestOptions] = getRetryOptions(1, [], [])

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toBeUndefined()

expect(requestOptions.retries).toEqual(1)
expect(requestOptions?.retries).toEqual(1)
})

test('requestOptions does not override defaults from @actions/github', async () => {
const [retryOptions, requestOptions] = getRetryOptions(1, [], {
request: {
agent: 'default-user-agent'
},
foo: 'bar'
})

expect(retryOptions.enabled).toBe(true)
expect(retryOptions.doNotRetry).toBeUndefined()

expect(requestOptions?.retries).toEqual(1)
expect(requestOptions?.agent).toEqual('default-user-agent')
expect(requestOptions?.foo).toBeUndefined() // this should not be in the `options.request` object, but at the same level as `request`
})
})
20 changes: 14 additions & 6 deletions 20 dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.getOctokitOptions = exports.GitHub = exports.context = void 0;
exports.getOctokitOptions = exports.GitHub = exports.defaults = exports.context = void 0;
const Context = __importStar(__webpack_require__(53));
const Utils = __importStar(__webpack_require__(914));
// octokit + plugins
Expand All @@ -255,13 +255,13 @@ const plugin_rest_endpoint_methods_1 = __webpack_require__(45);
const plugin_paginate_rest_1 = __webpack_require__(193);
exports.context = new Context.Context();
const baseUrl = Utils.getApiBaseUrl();
const defaults = {
exports.defaults = {
baseUrl,
request: {
agent: Utils.getProxyAgent(baseUrl)
}
};
exports.GitHub = core_1.Octokit.plugin(plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_paginate_rest_1.paginateRest).defaults(defaults);
exports.GitHub = core_1.Octokit.plugin(plugin_rest_endpoint_methods_1.restEndpointMethods, plugin_paginate_rest_1.paginateRest).defaults(exports.defaults);
/**
* Convience function to correctly format Octokit Options to pass into the constructor.
*
Expand Down Expand Up @@ -13322,6 +13322,9 @@ var exec = __webpack_require__(514);
// EXTERNAL MODULE: ./node_modules/@actions/github/lib/github.js
var lib_github = __webpack_require__(438);

// EXTERNAL MODULE: ./node_modules/@actions/github/lib/utils.js
var utils = __webpack_require__(30);

// EXTERNAL MODULE: ./node_modules/@actions/glob/lib/glob.js
var glob = __webpack_require__(90);

Expand All @@ -13340,18 +13343,22 @@ function callAsyncFunction(args, source) {

// CONCATENATED MODULE: ./src/retry-options.ts

function getRetryOptions(retries, exemptStatusCodes) {
function getRetryOptions(retries, exemptStatusCodes, defaultOptions) {
var _a;
if (retries <= 0) {
return [{ enabled: false }, {}];
return [{ enabled: false }, defaultOptions.request];
}
const retryOptions = {
enabled: true
};
if (exemptStatusCodes.length > 0) {
retryOptions.doNotRetry = exemptStatusCodes;
}
// The GitHub type has some defaults for `options.request`
// see: https://github.com/actions/toolkit/blob/4fbc5c941a57249b19562015edbd72add14be93d/packages/github/src/utils.ts#L15
// We pass these in here so they are not overidden.
const requestOptions = {
...defaultOptions.request,
retries
};
Object(core.debug)(`GitHub client configured with: (retries: ${requestOptions.retries}, retry-exempt-status-code: ${(_a = retryOptions === null || retryOptions === void 0 ? void 0 : retryOptions.doNotRetry) !== null && _a !== void 0 ? _a : 'octokit default: [400, 401, 403, 404, 422]'})`);
Expand Down Expand Up @@ -13401,6 +13408,7 @@ const wrapRequire = new Proxy(require, {




process.on('unhandledRejection', handleError);
main().catch(handleError);
async function main() {
Expand All @@ -13410,7 +13418,7 @@ async function main() {
const previews = Object(core.getInput)('previews');
const retries = parseInt(Object(core.getInput)('retries'));
const exemptStatusCodes = parseNumberArray(Object(core.getInput)('retry-exempt-status-codes'));
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes);
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes, utils.defaults);
const opts = {};
if (debug === 'true')
opts.log = console;
Expand Down
18 changes: 9 additions & 9 deletions 18 package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions 4 package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "github-script",
"description": "A GitHub action for executing a simple script",
"version": "6.3.0",
"version": "6.3.1",
"author": "GitHub",
"license": "MIT",
"main": "dist/index.js",
Expand Down Expand Up @@ -55,4 +55,4 @@
"ts-jest": "^27.0.5",
"typescript": "^4.3.5"
}
}
}
17 changes: 9 additions & 8 deletions 17 src/main.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import * as core from '@actions/core'
import * as exec from '@actions/exec'
import {context, getOctokit} from '@actions/github'
import {defaults as defaultGitHubOptions} from '@actions/github/lib/utils'
import * as glob from '@actions/glob'
import * as io from '@actions/io'
import {retry} from '@octokit/plugin-retry'
import {RequestRequestOptions} from '@octokit/types'
import {callAsyncFunction} from './async-function'
import {
getRetryOptions,
parseNumberArray,
RequestOptions,
RetryOptions
} from './retry-options'
import {getRetryOptions, parseNumberArray, RetryOptions} from './retry-options'
import {wrapRequire} from './wrap-require'

process.on('unhandledRejection', handleError)
Expand All @@ -21,7 +18,7 @@ type Options = {
userAgent?: string
previews?: string[]
retry?: RetryOptions
request?: RequestOptions
request?: RequestRequestOptions
}

async function main(): Promise<void> {
Expand All @@ -33,7 +30,11 @@ async function main(): Promise<void> {
const exemptStatusCodes = parseNumberArray(
core.getInput('retry-exempt-status-codes')
)
const [retryOpts, requestOpts] = getRetryOptions(retries, exemptStatusCodes)
const [retryOpts, requestOpts] = getRetryOptions(
retries,
exemptStatusCodes,
defaultGitHubOptions
)

const opts: Options = {}
if (debug === 'true') opts.log = console
Expand Down
19 changes: 11 additions & 8 deletions 19 src/retry-options.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import * as core from '@actions/core'
import {OctokitOptions} from '@octokit/core/dist-types/types'
import {RequestRequestOptions} from '@octokit/types'

export type RetryOptions = {
doNotRetry?: number[]
enabled?: boolean
}

export type RequestOptions = {
retries?: number
}

export function getRetryOptions(
retries: number,
exemptStatusCodes: number[]
): [RetryOptions, RequestOptions] {
exemptStatusCodes: number[],
defaultOptions: OctokitOptions
): [RetryOptions, RequestRequestOptions | undefined] {
if (retries <= 0) {
return [{enabled: false}, {}]
return [{enabled: false}, defaultOptions.request]
}

const retryOptions: RetryOptions = {
Expand All @@ -25,7 +24,11 @@ export function getRetryOptions(
retryOptions.doNotRetry = exemptStatusCodes
}

const requestOptions: RequestOptions = {
// The GitHub type has some defaults for `options.request`
// see: https://github.com/actions/toolkit/blob/4fbc5c941a57249b19562015edbd72add14be93d/packages/github/src/utils.ts#L15
// We pass these in here so they are not overidden.
const requestOptions: RequestRequestOptions = {
...defaultOptions.request,
retries
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.