mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 00:55:52 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
2ac119cf97 | ||
|
|
ff8539eb83 | ||
|
|
f90afba39a | ||
|
|
82c8e38c69 | ||
|
|
4e4ff2b320 | ||
|
|
348745cc31 | ||
|
|
d3ea5fce44 | ||
|
|
5d7e3ef283 | ||
|
|
089a11111a | ||
|
|
f7cd714b2c | ||
|
|
acd894b2e1 | ||
|
|
8ed097ea3f | ||
|
|
b9373e0ef3 | ||
|
|
65d4ab42a4 | ||
|
|
193a7dd98c | ||
|
|
3b9f5efa1c | ||
|
|
cfc342658b |
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'
|
||||||
10
README.md
10
README.md
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
|
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
|
||||||
|
|
||||||
Exmaple Usage:
|
Example Usage:
|
||||||
```
|
```
|
||||||
jobs:
|
jobs:
|
||||||
deployment
|
deployment
|
||||||
@@ -32,3 +32,11 @@ jobs:
|
|||||||
### Output
|
### Output
|
||||||
|
|
||||||
- `response` Request Response as JSON String
|
- `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)
|
||||||
|
|||||||
@@ -29,6 +29,9 @@ inputs:
|
|||||||
bearerToken:
|
bearerToken:
|
||||||
description: 'Bearer Authentication Token'
|
description: 'Bearer Authentication Token'
|
||||||
required: false
|
required: false
|
||||||
|
customHeaders:
|
||||||
|
description: 'Custom HTTP Headers'
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
response:
|
response:
|
||||||
description: 'HTTP Response Content'
|
description: 'HTTP Response Content'
|
||||||
|
|||||||
28
dist/index.js
vendored
28
dist/index.js
vendored
@@ -2597,6 +2597,9 @@ module.exports = function httpAdapter(config) {
|
|||||||
const core = __webpack_require__(470);
|
const core = __webpack_require__(470);
|
||||||
const axios = __webpack_require__(53);
|
const axios = __webpack_require__(53);
|
||||||
|
|
||||||
|
const METHOD_GET = 'GET'
|
||||||
|
const METHOD_POST = 'POST'
|
||||||
|
|
||||||
let auth = undefined
|
let auth = undefined
|
||||||
let customHeaders = {}
|
let customHeaders = {}
|
||||||
|
|
||||||
@@ -2620,7 +2623,7 @@ if (!!core.getInput('username') || !!core.getInput('password')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!!core.getInput('bearerToken')) {
|
if (!!core.getInput('bearerToken')) {
|
||||||
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instanceConfig = {
|
const instanceConfig = {
|
||||||
@@ -2629,25 +2632,38 @@ const instanceConfig = {
|
|||||||
headers: { ...headers, ...customHeaders }
|
headers: { ...headers, ...customHeaders }
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(JSON.stringify(instanceConfig))
|
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||||
|
|
||||||
const instance = axios.create(instanceConfig);
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
try {
|
try {
|
||||||
|
const method = core.getInput('method') || METHOD_POST;
|
||||||
|
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
auth,
|
auth,
|
||||||
method: core.getInput('method') || 'POST',
|
method,
|
||||||
data: JSON.parse(core.getInput('data') || '{}')
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(JSON.stringify(requestData))
|
core.debug('Request Data: ' + JSON.stringify(requestData))
|
||||||
|
|
||||||
const response = await instance.request(requestData)
|
const response = await instance.request(requestData)
|
||||||
|
|
||||||
core.setOutput('response', JSON.stringify(response.data))
|
core.setOutput('response', JSON.stringify(response.data))
|
||||||
} catch (error) {
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "http-request-action",
|
"name": "http-request-action",
|
||||||
"version": "1.0.0",
|
"version": "1.3.2",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"private": false,
|
"private": false,
|
||||||
|
|||||||
28
src/index.js
28
src/index.js
@@ -1,6 +1,9 @@
|
|||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const axios = require("axios");
|
const axios = require("axios");
|
||||||
|
|
||||||
|
const METHOD_GET = 'GET'
|
||||||
|
const METHOD_POST = 'POST'
|
||||||
|
|
||||||
let auth = undefined
|
let auth = undefined
|
||||||
let customHeaders = {}
|
let customHeaders = {}
|
||||||
|
|
||||||
@@ -24,7 +27,7 @@ if (!!core.getInput('username') || !!core.getInput('password')) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!!core.getInput('bearerToken')) {
|
if (!!core.getInput('bearerToken')) {
|
||||||
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instanceConfig = {
|
const instanceConfig = {
|
||||||
@@ -33,24 +36,37 @@ const instanceConfig = {
|
|||||||
headers: { ...headers, ...customHeaders }
|
headers: { ...headers, ...customHeaders }
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(JSON.stringify(instanceConfig))
|
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||||
|
|
||||||
const instance = axios.create(instanceConfig);
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
(async() => {
|
(async() => {
|
||||||
try {
|
try {
|
||||||
|
const method = core.getInput('method') || METHOD_POST;
|
||||||
|
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
auth,
|
auth,
|
||||||
method: core.getInput('method') || 'POST',
|
method,
|
||||||
data: JSON.parse(core.getInput('data') || '{}')
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
core.debug(JSON.stringify(requestData))
|
core.debug('Request Data: ' + JSON.stringify(requestData))
|
||||||
|
|
||||||
const response = await instance.request(requestData)
|
const response = await instance.request(requestData)
|
||||||
|
|
||||||
core.setOutput('response', JSON.stringify(response.data))
|
core.setOutput('response', JSON.stringify(response.data))
|
||||||
} catch (error) {
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})()
|
})()
|
||||||
|
|||||||
Reference in New Issue
Block a user