Compare commits

...

17 Commits

Author SHA1 Message Date
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
Frank
f90afba39a revert setFailed to setOutput 2020-07-19 10:08:45 +02:00
Frank Jogeleit
82c8e38c69 Merge pull request #9 from fjogeleit/fix-invalid-http-error-output
convert error into string an mark build as failed
2020-07-19 10:06:08 +02:00
Frank
4e4ff2b320 convert error into string an mark build as failed 2020-07-19 10:04:58 +02:00
Frank Jogeleit
348745cc31 Update README.md 2020-06-30 10:30:02 +02:00
Frank
d3ea5fce44 Improve Request Error Handling 2020-06-08 19:59:37 +02:00
Frank Jogeleit
5d7e3ef283 Merge pull request #5 from fjogeleit/fix-bearer-token-header
Fix Header Name for Bearer Authorization
2020-05-06 20:45:21 +02:00
Frank
089a11111a Fix Header Name for Bearer Authorization 2020-05-06 20:43:17 +02:00
Frank Jogeleit
f7cd714b2c Add Test Action (#4)
* Don't apply "data" on GET Requests
* Add Test Workflow
* Add Debug output for Instance Config and Request Data
2020-04-21 14:17:51 +02:00
Frank
acd894b2e1 update readme 2020-04-21 14:16:49 +02:00
Frank
8ed097ea3f fix basic auth method 2020-04-21 14:09:38 +02:00
Frank
b9373e0ef3 add auth test 2020-04-21 14:07:56 +02:00
Frank
65d4ab42a4 add post test 2020-04-21 13:58:56 +02:00
Frank
193a7dd98c update data payload 2020-04-21 13:55:30 +02:00
Frank
3b9f5efa1c Move workflow in the right folder 2020-04-21 13:47:34 +02:00
Frank
cfc342658b Add Test Action 2020-04-21 13:44:56 +02:00
6 changed files with 89 additions and 14 deletions

32
.github/workflows/test.yml vendored Normal file
View File

@@ -0,0 +1,32 @@
name: Test
on: [push, pull_request]
jobs:
request:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
ref: ${{ github.ref }}
- name: Request Postment Echo GET
uses: ./
with:
url: 'https://postman-echo.com/get'
method: 'GET'
- name: Request Postment Echo POST
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
- name: Request Postment Echo BasicAuth
uses: ./
with:
url: 'https://postman-echo.com/basic-auth'
method: 'GET'
username: 'postman'
password: 'password'

View File

@@ -2,7 +2,7 @@
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
Exmaple Usage:
Example Usage:
```
jobs:
deployment
@@ -32,3 +32,11 @@ jobs:
### Output
- `response` Request Response as JSON String
### Debug Informations
Enable Debug mode to get informations about
- Instance Configuration (Url / Timeout / Headers)
- Request Data (Body / Auth / Method)

View File

@@ -29,6 +29,9 @@ inputs:
bearerToken:
description: 'Bearer Authentication Token'
required: false
customHeaders:
description: 'Custom HTTP Headers'
required: false
outputs:
response:
description: 'HTTP Response Content'

28
dist/index.js vendored
View File

@@ -2597,6 +2597,9 @@ module.exports = function httpAdapter(config) {
const core = __webpack_require__(470);
const axios = __webpack_require__(53);
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
let auth = undefined
let customHeaders = {}
@@ -2620,7 +2623,7 @@ if (!!core.getInput('username') || !!core.getInput('password')) {
}
if (!!core.getInput('bearerToken')) {
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
const instanceConfig = {
@@ -2629,25 +2632,38 @@ const instanceConfig = {
headers: { ...headers, ...customHeaders }
}
core.debug(JSON.stringify(instanceConfig))
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
(async() => {
try {
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method: core.getInput('method') || 'POST',
data: JSON.parse(core.getInput('data') || '{}')
method,
data
}
core.debug(JSON.stringify(requestData))
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
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);
}
}
})()

View File

@@ -1,6 +1,6 @@
{
"name": "http-request-action",
"version": "1.0.0",
"version": "1.3.2",
"description": "",
"main": "src/index.js",
"private": false,

View File

@@ -1,6 +1,9 @@
const core = require("@actions/core");
const axios = require("axios");
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
let auth = undefined
let customHeaders = {}
@@ -24,7 +27,7 @@ if (!!core.getInput('username') || !!core.getInput('password')) {
}
if (!!core.getInput('bearerToken')) {
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
const instanceConfig = {
@@ -33,24 +36,37 @@ const instanceConfig = {
headers: { ...headers, ...customHeaders }
}
core.debug(JSON.stringify(instanceConfig))
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
const instance = axios.create(instanceConfig);
(async() => {
try {
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method: core.getInput('method') || 'POST',
data: JSON.parse(core.getInput('data') || '{}')
method,
data
}
core.debug(JSON.stringify(requestData))
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
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);
}
}
})()