diff --git a/lib/main.js b/lib/main.js index f1aeaed3..00e4aa23 100644 --- a/lib/main.js +++ b/lib/main.js @@ -34,11 +34,12 @@ Object.defineProperty(exports, "__esModule", { value: true }); exports.getPayload = void 0; const core_1 = require("@actions/core"); const github = __importStar(require("@actions/github")); +const axios_1 = __importDefault(require("axios")); const format_1 = require("./format"); +const https_proxy_agent_1 = require("https-proxy-agent"); const input_1 = require("./input"); const utils_1 = require("./utils"); const validate_1 = require("./validate"); -const https_proxy_agent_1 = __importDefault(require("https-proxy-agent")); function run() { return __awaiter(this, void 0, void 0, function* () { try { @@ -68,16 +69,24 @@ function wrapWebhook(webhook, payload) { const fullProxy = process.env['http_proxy'] || process.env['HTTP_PROXY'] || process.env['https_proxy'] || process.env['HTTPS_PROXY']; const host = fullProxy ? fullProxy.split(':')[0] : ''; const port = fullProxy ? parseInt(fullProxy.split(':')[1]) : ''; - const proxy = host && port ? { host, port } : {}; - let options = { - method: 'POST', - body: JSON.stringify(payload), - headers: { 'content-type': 'application/json' }, - }; - if (proxy) { - options = Object.assign(Object.assign({}, options), { agent: https_proxy_agent_1.default(proxy) }); + let proxy = host && port ? { proxy: { host, port } } : {}; + if (fullProxy) { + const agent = new https_proxy_agent_1.HttpsProxyAgent(fullProxy); + proxy = Object.assign(Object.assign({}, proxy), { httpAgent: agent, httpsAgent: agent }); } - yield fetch(webhook, options); + const client = axios_1.default.create(proxy); + client.interceptors.request.use((config) => { + utils_1.logInfo(JSON.stringify(config)); + return config; + }); + client.interceptors.response.use((axiosResponse) => { + utils_1.logInfo(JSON.stringify(axiosResponse)); + return axiosResponse; + }, (error) => { + utils_1.logInfo(JSON.stringify(error)); + return error; + }); + yield client.post(webhook, payload); } catch (e) { if (e.response) {