mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-22 03:41:00 -05:00
Add Test Action (#4)
* Don't apply "data" on GET Requests * Add Test Workflow * Add Debug output for Instance Config and Request Data
This commit is contained in:
commit
f7cd714b2c
4 changed files with 60 additions and 8 deletions
32
.github/workflows/test.yml
vendored
Normal file
32
.github/workflows/test.yml
vendored
Normal 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'
|
|
@ -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)
|
14
dist/index.js
vendored
14
dist/index.js
vendored
|
@ -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 = {}
|
||||
|
||||
|
@ -2629,19 +2632,22 @@ 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)
|
||||
|
||||
|
|
14
src/index.js
14
src/index.js
|
@ -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 = {}
|
||||
|
||||
|
@ -33,19 +36,22 @@ 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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue