From 0170dcbc3132c12f85f5ead3c1e0a9e98b244cb5 Mon Sep 17 00:00:00 2001 From: Frank Date: Wed, 25 Mar 2020 11:15:19 +0100 Subject: [PATCH] Add support for custom headers --- README.md | 1 + src/index.js | 12 +++++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index aec13e8..3ecfd9f 100644 --- a/README.md +++ b/README.md @@ -27,6 +27,7 @@ jobs: |username| Username for Basic Auth || |password| Password for Basic Auth || |bearerToken| Bearer Authentication Token (without Bearer Prefix) || +|customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'| ### Output diff --git a/src/index.js b/src/index.js index 5bf5abf..940b29d 100644 --- a/src/index.js +++ b/src/index.js @@ -2,6 +2,16 @@ const core = require("@actions/core"); const axios = require("axios"); const auth = {} +let customHeaders = {} + +if (!!core.getInput('customHeaders')) { + try { + customHeaders = JSON.parse(core.getInput('customHeaders')); + } catch(error) { + core.error('Could not parse customHeaders string value') + } +} + const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' } if (!!core.getInput('username')) { @@ -19,7 +29,7 @@ if (!!core.getInput('bearerToken')) { const instance = axios.create({ baseURL: core.getInput('url', { required: true }), timeout: parseInt(core.getInput('timeout') || 5000, 10), - headers + headers: { ...headers, ...customHeaders } });