Compare commits

...

8 Commits

Author SHA1 Message Date
Frank Jogeleit
81e44c2059 Update Dependencies 2020-10-01 22:20:08 +02:00
Frank Jogeleit
cc4fc855b5 Merge pull request #14 from fjogeleit/dependabot/npm_and_yarn/actions/core-1.2.6
Bump @actions/core from 1.2.2 to 1.2.6
2020-10-01 22:16:26 +02:00
dependabot[bot]
c7cadd574f Bump @actions/core from 1.2.2 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.2 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-01 17:32:37 +00:00
Frank Jogeleit
3634ea0063 Fix removed config 2020-08-04 17:09:29 +02:00
Frank Jogeleit
b63e908234 Merge pull request #13 from fjogeleit/handle-empty-response
Add new input option "preventFailureOnNoResponse"
2020-07-30 18:31:32 +02:00
Frank Jogeleit
60ab747148 Split Action in multiple files to improve testing
Add a new InputOption to ignore a failure for no response receive
2020-07-30 18:27:27 +02:00
Frank Jogeleit
2ac119cf97 Merge pull request #11 from fjogeleit/add-customHeaders-to-action-config
Add customHeaders to action.yml
2020-07-21 09:30:17 +02:00
Frank
ff8539eb83 Add customHeaders to action.yml 2020-07-21 09:26:48 +02:00
8 changed files with 734 additions and 1105 deletions

View File

@@ -28,6 +28,7 @@ jobs:
|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 |'{}'|
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. Use 'true' (string) as value to enable it ||
### Output

View File

@@ -29,6 +29,12 @@ inputs:
bearerToken:
description: 'Bearer Authentication Token'
required: false
customHeaders:
description: 'Custom HTTP Headers'
required: false
preventFailureOnNoResponse:
description: 'Prevent this Action to fail if the request respond without an response'
required: false
outputs:
response:
description: 'HTTP Response Content'

1664
dist/index.js vendored

File diff suppressed because it is too large Load Diff

38
package-lock.json generated
View File

@@ -1,13 +1,13 @@
{
"name": "http-request-action",
"version": "1.0.0",
"version": "1.4.2",
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@actions/core": {
"version": "1.2.2",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz",
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg==",
"version": "1.2.6",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==",
"dev": true
},
"@zeit/ncc": {
@@ -16,33 +16,17 @@
"integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"version": "0.20.0",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.20.0.tgz",
"integrity": "sha512-ANA4rr2BDcmmAQLOKft2fufrtuvlqR+cXNNinUmvfeSNCOF98PZL+7M/v1zIdGo7OLjEA9J2gXJL+j4zGsl0bA==",
"requires": {
"follow-redirects": "1.5.10"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"requires": {
"ms": "2.0.0"
"follow-redirects": "^1.10.0"
}
},
"follow-redirects": {
"version": "1.5.10",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
"requires": {
"debug": "=3.1.0"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
"version": "1.13.0",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.0.tgz",
"integrity": "sha512-aq6gF1BEKje4a9i9+5jimNFIpq4Q1WiwBToeRK5NvZBd/TRsmW8BsJfOEGkr76TbOyPVD3OVDN910EcUNtRYEA=="
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "http-request-action",
"version": "1.3.2",
"version": "1.4.2",
"description": "",
"main": "src/index.js",
"private": false,
@@ -19,10 +19,10 @@
},
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
"devDependencies": {
"@actions/core": "^1.2.2"
"@actions/core": "^1.2.6"
},
"dependencies": {
"@zeit/ncc": "^0.21.1",
"axios": "^0.19.2"
"axios": "^0.20.0"
}
}

39
src/githubActions.js Normal file
View File

@@ -0,0 +1,39 @@
const core = require("@actions/core");
class GithubActions {
debug(message) {
core.debug(message)
}
warning(message) {
core.warning(message)
}
setOutput(name, output) {
core.setOutput(name, output)
}
setFailed(message) {
core.setFailed(message)
}
}
class LogActions {
debug(message) {
console.info(message)
}
warning(message) {
console.warn(message)
}
setOutput(name, output) {
console.log(name, output)
}
setFailed(message) {
console.error(message)
}
}
module.exports = { GithubActions, LogActions }

44
src/httpClient.js Normal file
View File

@@ -0,0 +1,44 @@
const axios = require("axios");
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse }) => {
try {
const instance = axios.create(instanceConfig);
const jsonData = method === METHOD_GET ? undefined : JSON.parse(data)
const requestData = {
auth,
method,
data: jsonData
}
actions.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
actions.setOutput('response', JSON.stringify(response.data))
} catch (error) {
if (error.toJSON) {
actions.setOutput(JSON.stringify(error.toJSON()));
}
if (error.response) {
actions.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
} else if (error.request && !preventFailureOnNoResponse) {
actions.setFailed(JSON.stringify({ error: "no response received" }));
} else if (error.request && preventFailureOnNoResponse) {
actions.warning(JSON.stringify(error));
} else {
actions.setFailed(error.message);
}
}
}
module.exports = {
request,
METHOD_POST,
METHOD_GET,
}

View File

@@ -1,8 +1,6 @@
const core = require("@actions/core");
const axios = require("axios");
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
const { request, METHOD_POST } = require('./httpClient');
const { GithubActions } = require('./githubActions');
let auth = undefined
let customHeaders = {}
@@ -38,35 +36,8 @@ const instanceConfig = {
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
const data = core.getInput('data') || '{}';
const method = core.getInput('method') || METHOD_POST;
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
(async() => {
try {
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method,
data
}
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {
if (error.toJSON) {
core.setOutput(JSON.stringify(error.toJSON()));
}
if (error.response) {
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
} else if (error.request) {
core.setFailed(JSON.stringify({ error: "no response received" }));
} else {
core.setFailed(error.message);
}
}
})()
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, actions: new GithubActions() })