Skip to content

Commit

Permalink
Revert axios, update action to node v16
Browse files Browse the repository at this point in the history
  • Loading branch information
DavideViolante committed Dec 2, 2022
1 parent 559de8d commit 39c8144
Show file tree
Hide file tree
Showing 5 changed files with 472 additions and 3,211 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
pr-automerge:
runs-on: ubuntu-latest
steps:
- uses: davideviolante/pr-automerge-action@v1.3.2
- uses: davideviolante/pr-automerge-action@v1.3.3
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
Expand Down
2 changes: 1 addition & 1 deletion action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ inputs:
required: false
default: 'dev'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'
176 changes: 119 additions & 57 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,6 @@ const file_command_1 = __nccwpck_require__(717);
const utils_1 = __nccwpck_require__(5278);
const os = __importStar(__nccwpck_require__(2037));
const path = __importStar(__nccwpck_require__(1017));
const uuid_1 = __nccwpck_require__(8974);
const oidc_utils_1 = __nccwpck_require__(8041);
/**
* The code to exit an action
Expand Down Expand Up @@ -201,20 +200,9 @@ function exportVariable(name, val) {
process.env[name] = convertedVal;
const filePath = process.env['GITHUB_ENV'] || '';
if (filePath) {
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
// These should realistically never happen, but just in case someone finds a way to exploit uuid generation let's not allow keys or values that contain the delimiter.
if (name.includes(delimiter)) {
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
}
if (convertedVal.includes(delimiter)) {
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
}
const commandValue = `${name}<<${delimiter}${os.EOL}${convertedVal}${os.EOL}${delimiter}`;
file_command_1.issueCommand('ENV', commandValue);
}
else {
command_1.issueCommand('set-env', { name }, convertedVal);
return file_command_1.issueFileCommand('ENV', file_command_1.prepareKeyValueMessage(name, val));
}
command_1.issueCommand('set-env', { name }, convertedVal);
}
exports.exportVariable = exportVariable;
/**
Expand All @@ -232,7 +220,7 @@ exports.setSecret = setSecret;
function addPath(inputPath) {
const filePath = process.env['GITHUB_PATH'] || '';
if (filePath) {
file_command_1.issueCommand('PATH', inputPath);
file_command_1.issueFileCommand('PATH', inputPath);
}
else {
command_1.issueCommand('add-path', {}, inputPath);
Expand Down Expand Up @@ -272,7 +260,10 @@ function getMultilineInput(name, options) {
const inputs = getInput(name, options)
.split('\n')
.filter(x => x !== '');
return inputs;
if (options && options.trimWhitespace === false) {
return inputs;
}
return inputs.map(input => input.trim());
}
exports.getMultilineInput = getMultilineInput;
/**
Expand Down Expand Up @@ -305,8 +296,12 @@ exports.getBooleanInput = getBooleanInput;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function setOutput(name, value) {
const filePath = process.env['GITHUB_OUTPUT'] || '';
if (filePath) {
return file_command_1.issueFileCommand('OUTPUT', file_command_1.prepareKeyValueMessage(name, value));
}
process.stdout.write(os.EOL);
command_1.issueCommand('set-output', { name }, value);
command_1.issueCommand('set-output', { name }, utils_1.toCommandValue(value));
}
exports.setOutput = setOutput;
/**
Expand Down Expand Up @@ -435,7 +430,11 @@ exports.group = group;
*/
// eslint-disable-next-line @typescript-eslint/no-explicit-any
function saveState(name, value) {
command_1.issueCommand('save-state', { name }, value);
const filePath = process.env['GITHUB_STATE'] || '';
if (filePath) {
return file_command_1.issueFileCommand('STATE', file_command_1.prepareKeyValueMessage(name, value));
}
command_1.issueCommand('save-state', { name }, utils_1.toCommandValue(value));
}
exports.saveState = saveState;
/**
Expand Down Expand Up @@ -501,13 +500,14 @@ var __importStar = (this && this.__importStar) || function (mod) {
return result;
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.issueCommand = void 0;
exports.prepareKeyValueMessage = exports.issueFileCommand = void 0;
// We use any as a valid input type
/* eslint-disable @typescript-eslint/no-explicit-any */
const fs = __importStar(__nccwpck_require__(7147));
const os = __importStar(__nccwpck_require__(2037));
const uuid_1 = __nccwpck_require__(8974);
const utils_1 = __nccwpck_require__(5278);
function issueCommand(command, message) {
function issueFileCommand(command, message) {
const filePath = process.env[`GITHUB_${command}`];
if (!filePath) {
throw new Error(`Unable to find environment variable for file command ${command}`);
Expand All @@ -519,7 +519,22 @@ function issueCommand(command, message) {
encoding: 'utf8'
});
}
exports.issueCommand = issueCommand;
exports.issueFileCommand = issueFileCommand;
function prepareKeyValueMessage(key, value) {
const delimiter = `ghadelimiter_${uuid_1.v4()}`;
const convertedValue = utils_1.toCommandValue(value);
// These should realistically never happen, but just in case someone finds a
// way to exploit uuid generation let's not allow keys or values that contain
// the delimiter.
if (key.includes(delimiter)) {
throw new Error(`Unexpected input: name should not contain the delimiter "${delimiter}"`);
}
if (convertedValue.includes(delimiter)) {
throw new Error(`Unexpected input: value should not contain the delimiter "${delimiter}"`);
}
return `${key}<<${delimiter}${os.EOL}${convertedValue}${os.EOL}${delimiter}`;
}
exports.prepareKeyValueMessage = prepareKeyValueMessage;
//# sourceMappingURL=file-command.js.map

/***/ }),
Expand Down Expand Up @@ -6877,6 +6892,11 @@ events.forEach(function (event) {
};
});

var InvalidUrlError = createErrorType(
"ERR_INVALID_URL",
"Invalid URL",
TypeError
);
// Error types with codes
var RedirectionError = createErrorType(
"ERR_FR_REDIRECTION_FAILURE",
Expand Down Expand Up @@ -6937,10 +6957,10 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
}

// Validate input and shift parameters if necessary
if (!(typeof data === "string" || typeof data === "object" && ("length" in data))) {
if (!isString(data) && !isBuffer(data)) {
throw new TypeError("data should be a string, Buffer or Uint8Array");
}
if (typeof encoding === "function") {
if (isFunction(encoding)) {
callback = encoding;
encoding = null;
}
Expand Down Expand Up @@ -6969,11 +6989,11 @@ RedirectableRequest.prototype.write = function (data, encoding, callback) {
// Ends the current native request
RedirectableRequest.prototype.end = function (data, encoding, callback) {
// Shift parameters if necessary
if (typeof data === "function") {
if (isFunction(data)) {
callback = data;
data = encoding = null;
}
else if (typeof encoding === "function") {
else if (isFunction(encoding)) {
callback = encoding;
encoding = null;
}
Expand Down Expand Up @@ -7132,25 +7152,30 @@ RedirectableRequest.prototype._performRequest = function () {
// If specified, use the agent corresponding to the protocol
// (HTTP and HTTPS use different types of agents)
if (this._options.agents) {
var scheme = protocol.substr(0, protocol.length - 1);
var scheme = protocol.slice(0, -1);
this._options.agent = this._options.agents[scheme];
}

// Create the native request
// Create the native request and set up its event handlers
var request = this._currentRequest =
nativeProtocol.request(this._options, this._onNativeResponse);
this._currentUrl = url.format(this._options);

// Set up event handlers
request._redirectable = this;
for (var e = 0; e < events.length; e++) {
request.on(events[e], eventHandlers[events[e]]);
for (var event of events) {
request.on(event, eventHandlers[event]);
}

// RFC7230§5.3.1: When making a request directly to an origin server, […]
// a client MUST send only the absolute path […] as the request-target.
this._currentUrl = /^\//.test(this._options.path) ?
url.format(this._options) :
// When making a request to a proxy, […]
// a client MUST send the target URI in absolute-form […].
this._options.path;

// End a redirected request
// (The first request must be ended explicitly with RedirectableRequest#end)
if (this._isRedirect) {
// Write the request entity and end.
// Write the request entity and end
var i = 0;
var self = this;
var buffers = this._requestBodyBuffers;
Expand Down Expand Up @@ -7224,10 +7249,21 @@ RedirectableRequest.prototype._processResponse = function (response) {
return;
}

// Store the request headers if applicable
var requestHeaders;
var beforeRedirect = this._options.beforeRedirect;
if (beforeRedirect) {
requestHeaders = Object.assign({
// The Host header was set by nativeProtocol.request
Host: response.req.getHeader("host"),
}, this._options.headers);
}

// RFC7231§6.4: Automatic redirection needs to done with
// care for methods not known to be safe, […]
// RFC7231§6.4.2–3: For historical reasons, a user agent MAY change
// the request method from POST to GET for the subsequent request.
var method = this._options.method;
if ((statusCode === 301 || statusCode === 302) && this._options.method === "POST" ||
// RFC7231§6.4.4: The 303 (See Other) status code indicates that
// the server is redirecting the user agent to a different resource […]
Expand Down Expand Up @@ -7255,7 +7291,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
redirectUrl = url.resolve(currentUrl, location);
}
catch (cause) {
this.emit("error", new RedirectionError(cause));
this.emit("error", new RedirectionError({ cause: cause }));
return;
}

Expand All @@ -7275,10 +7311,18 @@ RedirectableRequest.prototype._processResponse = function (response) {
}

// Evaluate the beforeRedirect callback
if (typeof this._options.beforeRedirect === "function") {
var responseDetails = { headers: response.headers };
if (isFunction(beforeRedirect)) {
var responseDetails = {
headers: response.headers,
statusCode: statusCode,
};
var requestDetails = {
url: currentUrl,
method: method,
headers: requestHeaders,
};
try {
this._options.beforeRedirect.call(null, this._options, responseDetails);
beforeRedirect(this._options, responseDetails, requestDetails);
}
catch (err) {
this.emit("error", err);
Expand All @@ -7292,7 +7336,7 @@ RedirectableRequest.prototype._processResponse = function (response) {
this._performRequest();
}
catch (cause) {
this.emit("error", new RedirectionError(cause));
this.emit("error", new RedirectionError({ cause: cause }));
}
};

Expand All @@ -7314,15 +7358,19 @@ function wrap(protocols) {
// Executes a request, following redirects
function request(input, options, callback) {
// Parse parameters
if (typeof input === "string") {
var urlStr = input;
if (isString(input)) {
var parsed;
try {
input = urlToOptions(new URL(urlStr));
parsed = urlToOptions(new URL(input));
}
catch (err) {
/* istanbul ignore next */
input = url.parse(urlStr);
parsed = url.parse(input);
}
if (!isString(parsed.protocol)) {
throw new InvalidUrlError({ input });
}
input = parsed;
}
else if (URL && (input instanceof URL)) {
input = urlToOptions(input);
Expand All @@ -7332,7 +7380,7 @@ function wrap(protocols) {
options = input;
input = { protocol: protocol };
}
if (typeof options === "function") {
if (isFunction(options)) {
callback = options;
options = null;
}
Expand All @@ -7343,6 +7391,9 @@ function wrap(protocols) {
maxBodyLength: exports.maxBodyLength,
}, input, options);
options.nativeProtocols = nativeProtocols;
if (!isString(options.host) && !isString(options.hostname)) {
options.hostname = "::1";
}

assert.equal(options.protocol, protocol, "protocol mismatch");
debug("options", options);
Expand Down Expand Up @@ -7400,37 +7451,48 @@ function removeMatchingHeaders(regex, headers) {
undefined : String(lastValue).trim();
}

function createErrorType(code, defaultMessage) {
function CustomError(cause) {
function createErrorType(code, message, baseClass) {
// Create constructor
function CustomError(properties) {
Error.captureStackTrace(this, this.constructor);
if (!cause) {
this.message = defaultMessage;
}
else {
this.message = defaultMessage + ": " + cause.message;
this.cause = cause;
}
Object.assign(this, properties || {});
this.code = code;
this.message = this.cause ? message + ": " + this.cause.message : message;
}
CustomError.prototype = new Error();

// Attach constructor and set default properties
CustomError.prototype = new (baseClass || Error)();
CustomError.prototype.constructor = CustomError;
CustomError.prototype.name = "Error [" + code + "]";
CustomError.prototype.code = code;
return CustomError;
}

function abortRequest(request) {
for (var e = 0; e < events.length; e++) {
request.removeListener(events[e], eventHandlers[events[e]]);
for (var event of events) {
request.removeListener(event, eventHandlers[event]);
}
request.on("error", noop);
request.abort();
}

function isSubdomain(subdomain, domain) {
const dot = subdomain.length - domain.length - 1;
assert(isString(subdomain) && isString(domain));
var dot = subdomain.length - domain.length - 1;
return dot > 0 && subdomain[dot] === "." && subdomain.endsWith(domain);
}

function isString(value) {
return typeof value === "string" || value instanceof String;
}

function isFunction(value) {
return typeof value === "function";
}

function isBuffer(value) {
return typeof value === "object" && ("length" in value);
}

// Exports
module.exports = wrap({ http: http, https: https });
module.exports.wrap = wrap;
Expand Down

0 comments on commit 39c8144

Please sign in to comment.