From b59e27dec5df2007e44ce945a82864d51e679c55 Mon Sep 17 00:00:00 2001 From: andrurodr Date: Fri, 4 Mar 2022 09:52:41 -0300 Subject: [PATCH] build v1.9.1 --- lib/input.js | 20 ++++++++++++-------- lib/main.js | 7 ++++--- lib/utils.js | 6 +++++- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/input.js b/lib/input.js index b672e84a..65405e53 100644 --- a/lib/input.js +++ b/lib/input.js @@ -37,7 +37,7 @@ exports.statusOpts = { } }; function getInputs() { - const webhook = core.getInput('webhook').trim() || process.env.DISCORD_WEBHOOK || ''; + const webhook = core.getInput('webhook', { required: true, trimWhitespace: true }) || process.env.DISCORD_WEBHOOK || ''; const webhooks = webhook.split('\n').filter(x => x || false); webhooks.forEach((w, i) => { core.setSecret(w); @@ -48,17 +48,21 @@ function getInputs() { const nodetail = utils_1.stob(core.getInput('nodetail')); const nocontext = nodetail || utils_1.stob(core.getInput('nocontext')); const noprefix = nodetail || utils_1.stob(core.getInput('noprefix')); + const proxyHost = core.getInput('proxyHost', { required: false, trimWhitespace: true }); + const proxyPort = utils_1.asNumber(core.getInput('proxyPort', { required: false, trimWhitespace: true })); const inputs = { webhooks: webhooks, - status: core.getInput('status').trim().toLowerCase(), - description: core.getInput('description').trim(), - title: (core.getInput('title') || core.getInput('job')).trim(), - image: core.getInput('image').trim(), + status: core.getInput('status', { trimWhitespace: true }).toLowerCase(), + description: core.getInput('description', { trimWhitespace: true }), + title: (core.getInput('title') || core.getInput('job', { trimWhitespace: true })), + image: core.getInput('image', { trimWhitespace: true }), color: parseInt(core.getInput('color')), - username: core.getInput('username').trim(), - avatar_url: core.getInput('avatar_url').trim(), + username: core.getInput('username', { trimWhitespace: true }), + avatar_url: core.getInput('avatar_url', { trimWhitespace: true }), nocontext: nocontext, - noprefix: noprefix + noprefix: noprefix, + proxyHost, + proxyPort }; if (!inputs.webhooks.length) { throw new Error("no webhook is given"); diff --git a/lib/main.js b/lib/main.js index e606dbd5..b04b8f5b 100644 --- a/lib/main.js +++ b/lib/main.js @@ -50,18 +50,19 @@ function run() { utils_1.logInfo(JSON.stringify(payload, null, 2)); core_1.endGroup(); utils_1.logInfo(`Triggering ${inputs.webhooks.length} webhook${inputs.webhooks.length > 1 ? 's' : ''}...`); - yield Promise.all(inputs.webhooks.map(w => wrapWebhook(w.trim(), payload))); + yield Promise.all(inputs.webhooks.map(w => wrapWebhook(w.trim(), payload, inputs.proxyHost, inputs.proxyPort))); } catch (e) { utils_1.logError(`Unexpected failure: ${e} (${e.message})`); } }); } -function wrapWebhook(webhook, payload) { +function wrapWebhook(webhook, payload, proxyHost, proxyPort) { return function () { return __awaiter(this, void 0, void 0, function* () { try { - yield axios_1.default.post(webhook, payload); + const config = proxyHost && proxyPort ? { proxy: { host: proxyHost, port: proxyPort } } : {}; + yield axios_1.default.post(webhook, payload, config); } catch (e) { if (e.response) { diff --git a/lib/utils.js b/lib/utils.js index 42a0c2fb..033fd913 100644 --- a/lib/utils.js +++ b/lib/utils.js @@ -19,7 +19,7 @@ var __importStar = (this && this.__importStar) || function (mod) { return result; }; Object.defineProperty(exports, "__esModule", { value: true }); -exports.stob = exports.logWarning = exports.logInfo = exports.logDebug = exports.logError = void 0; +exports.asNumber = exports.stob = exports.logWarning = exports.logInfo = exports.logDebug = exports.logError = void 0; const core = __importStar(require("@actions/core")); const NOFAIL = core.getInput('nofail').trim().toLowerCase() === 'true'; function logError(msg) { @@ -42,3 +42,7 @@ function stob(s) { return s.trim().toLowerCase() === 'true'; } exports.stob = stob; +function asNumber(s) { + return s ? parseInt(s) : undefined; +} +exports.asNumber = asNumber;