mirror of
https://github.com/actions/github-script.git
synced 2025-12-08 16:16:21 +00:00
Merge pull request #293 from luketomlinson/main
Fix overriding request options from @actions/github
This commit is contained in:
2
.licenses/npm/@actions/github.dep.yml
generated
2
.licenses/npm/@actions/github.dep.yml
generated
@@ -1,6 +1,6 @@
|
||||
---
|
||||
name: "@actions/github"
|
||||
version: 5.1.0
|
||||
version: 5.1.1
|
||||
type: npm
|
||||
summary: Actions github lib
|
||||
homepage: https://github.com/actions/toolkit/tree/main/packages/github
|
||||
|
||||
@@ -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
dist/index.js
vendored
20
dist/index.js
vendored
@@ -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
|
||||
@@ -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.
|
||||
*
|
||||
@@ -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);
|
||||
|
||||
@@ -13340,10 +13343,10 @@ 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
|
||||
@@ -13351,7 +13354,11 @@ function getRetryOptions(retries, exemptStatusCodes) {
|
||||
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]'})`);
|
||||
@@ -13401,6 +13408,7 @@ const wrapRequire = new Proxy(require, {
|
||||
|
||||
|
||||
|
||||
|
||||
process.on('unhandledRejection', handleError);
|
||||
main().catch(handleError);
|
||||
async function main() {
|
||||
@@ -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;
|
||||
|
||||
18
package-lock.json
generated
18
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "github-script",
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"lockfileVersion": 2,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "github-script",
|
||||
"version": "6.3.0",
|
||||
"version": "6.3.1",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.9.1",
|
||||
@@ -52,9 +52,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/github": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz",
|
||||
"integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==",
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.1.tgz",
|
||||
"integrity": "sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==",
|
||||
"dependencies": {
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@octokit/core": "^3.6.0",
|
||||
@@ -6242,9 +6242,9 @@
|
||||
}
|
||||
},
|
||||
"@actions/github": {
|
||||
"version": "5.1.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.0.tgz",
|
||||
"integrity": "sha512-tuI80F7JQIhg77ZTTgUAPpVD7ZnP9oHSPN8xw7LOwtA4vEMbAjWJNbmLBfV7xua7r016GyjzWLuec5cs8f/a8A==",
|
||||
"version": "5.1.1",
|
||||
"resolved": "https://registry.npmjs.org/@actions/github/-/github-5.1.1.tgz",
|
||||
"integrity": "sha512-Nk59rMDoJaV+mHCOJPXuvB1zIbomlKS0dmSIqPGxd0enAXBnOfn4VWF+CGtRCwXZG9Epa54tZA7VIRlJDS8A6g==",
|
||||
"requires": {
|
||||
"@actions/http-client": "^2.0.1",
|
||||
"@octokit/core": "^3.6.0",
|
||||
@@ -10972,4 +10972,4 @@
|
||||
"dev": true
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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",
|
||||
@@ -55,4 +55,4 @@
|
||||
"ts-jest": "^27.0.5",
|
||||
"typescript": "^4.3.5"
|
||||
}
|
||||
}
|
||||
}
|
||||
17
src/main.ts
17
src/main.ts
@@ -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)
|
||||
@@ -21,7 +18,7 @@ type Options = {
|
||||
userAgent?: string
|
||||
previews?: string[]
|
||||
retry?: RetryOptions
|
||||
request?: RequestOptions
|
||||
request?: RequestRequestOptions
|
||||
}
|
||||
|
||||
async function main(): Promise<void> {
|
||||
@@ -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
|
||||
|
||||
@@ -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 = {
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user