mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2024-11-28 23:00:58 -05:00
Init Action
This commit is contained in:
parent
a0a85cecb8
commit
df0f4b3bfd
7 changed files with 3782 additions and 0 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
node_modules
|
33
README.md
Normal file
33
README.md
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
# HTTP Request Action
|
||||||
|
|
||||||
|
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
|
||||||
|
|
||||||
|
Exmaple Usage:
|
||||||
|
```
|
||||||
|
jobs:
|
||||||
|
deployment
|
||||||
|
- name: Deploy Stage
|
||||||
|
uses: fjogeleit/http-request-action@master
|
||||||
|
with:
|
||||||
|
url: 'https://ansible.io/api/v2/job_templates/84/launch/'
|
||||||
|
method: 'POST'
|
||||||
|
username: ${{ secrets.AWX_USER }}
|
||||||
|
password: ${{ secrets.AWX_PASSWORD }}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Input Arguments
|
||||||
|
|
||||||
|
|Argument| Description | Default |
|
||||||
|
|--------|---------------|-----------|
|
||||||
|
|url | Request URL | _required_ Field |
|
||||||
|
|method | Request Method| POST |
|
||||||
|
|contentType | Request ContentType| application/json |
|
||||||
|
|data | Request Body Content as JSON String, only for POST / PUT / PATCH Requests | '{}' |
|
||||||
|
|timeout| Request Timeout in ms | 5000 (5s) |
|
||||||
|
|username| Username for Basic Auth ||
|
||||||
|
|password| Password for Basic Auth ||
|
||||||
|
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|
||||||
|
|
||||||
|
### Output
|
||||||
|
|
||||||
|
- `response` Request Response as JSON String
|
37
action.yml
Normal file
37
action.yml
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
name: 'HTTP Request Action'
|
||||||
|
description: 'Create any HTTP Request'
|
||||||
|
inputs:
|
||||||
|
url:
|
||||||
|
description: 'Request URL'
|
||||||
|
required: true
|
||||||
|
method:
|
||||||
|
description: 'Request Method'
|
||||||
|
required: false
|
||||||
|
default: 'POST'
|
||||||
|
contentType:
|
||||||
|
description: 'Content Type'
|
||||||
|
required: false
|
||||||
|
default: 'application/json'
|
||||||
|
data:
|
||||||
|
description: 'Request Body as JSON String'
|
||||||
|
required: false
|
||||||
|
default: '{}'
|
||||||
|
username:
|
||||||
|
description: 'Auth Username'
|
||||||
|
required: false
|
||||||
|
password:
|
||||||
|
description: 'Auth Password'
|
||||||
|
required: false
|
||||||
|
timeout:
|
||||||
|
description: 'Request Timeout in Sec'
|
||||||
|
required: false
|
||||||
|
default: '5000'
|
||||||
|
bearerToken:
|
||||||
|
description: 'Bearer Authentication Token'
|
||||||
|
required: false
|
||||||
|
outputs:
|
||||||
|
response:
|
||||||
|
description: 'HTTP Response Content'
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'dist/index.js'
|
3597
dist/index.js
vendored
Normal file
3597
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
48
package-lock.json
generated
Normal file
48
package-lock.json
generated
Normal file
|
@ -0,0 +1,48 @@
|
||||||
|
{
|
||||||
|
"name": "http-request-action",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"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==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"@zeit/ncc": {
|
||||||
|
"version": "0.21.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz",
|
||||||
|
"integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw=="
|
||||||
|
},
|
||||||
|
"axios": {
|
||||||
|
"version": "0.19.2",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
|
||||||
|
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
|
||||||
|
"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": {
|
||||||
|
"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="
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
package.json
Normal file
28
package.json
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
{
|
||||||
|
"name": "http-request-action",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "",
|
||||||
|
"main": "src/index.js",
|
||||||
|
"private": false,
|
||||||
|
"scripts": {
|
||||||
|
"build": "ncc build src/index.js -o dist"
|
||||||
|
},
|
||||||
|
"repository": {
|
||||||
|
"type": "git",
|
||||||
|
"url": "git+https://github.com/fjogeleit/http-request-action.git"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"license": "ISC",
|
||||||
|
"bugs": {
|
||||||
|
"url": "https://github.com/fjogeleit/http-request-action/issues"
|
||||||
|
},
|
||||||
|
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
|
||||||
|
"devDependencies": {
|
||||||
|
"@actions/core": "^1.2.2"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@zeit/ncc": "^0.21.1",
|
||||||
|
"axios": "^0.19.2"
|
||||||
|
}
|
||||||
|
}
|
38
src/index.js
Normal file
38
src/index.js
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
const core = require("@actions/core");
|
||||||
|
const axios = require("axios");
|
||||||
|
|
||||||
|
const auth = {}
|
||||||
|
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
||||||
|
|
||||||
|
if (!!core.getInput('username')) {
|
||||||
|
auth.username = core.getInput('username');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!core.getInput('password')) {
|
||||||
|
auth.password = core.getInput('password');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!!core.getInput('bearerToken')) {
|
||||||
|
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
const instance = axios.create({
|
||||||
|
baseURL: core.getInput('url', { required: true }),
|
||||||
|
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||||
|
headers
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
(async() => {
|
||||||
|
try {
|
||||||
|
const response = await instance.request({
|
||||||
|
auth,
|
||||||
|
method: core.getInput('method') || 'POST',
|
||||||
|
data: JSON.parse(core.getInput('data') || '{}')
|
||||||
|
})
|
||||||
|
|
||||||
|
core.setOutput('response', JSON.stringify(response.data))
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
|
||||||
|
}
|
||||||
|
})()
|
Loading…
Reference in a new issue