mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 00:55:52 +08:00
Compare commits
39 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0929a0c636 | ||
|
|
bd043fe286 | ||
|
|
7626a13e42 | ||
|
|
48dc3972df | ||
|
|
84e61f1a56 | ||
|
|
42677b964e | ||
|
|
b6bb4fa030 | ||
|
|
de202bb090 | ||
|
|
eff73a48f7 | ||
|
|
f91c5933c4 | ||
|
|
3a9531bb34 | ||
|
|
0cc64a5579 | ||
|
|
81e44c2059 | ||
|
|
cc4fc855b5 | ||
|
|
c7cadd574f | ||
|
|
3634ea0063 | ||
|
|
b63e908234 | ||
|
|
60ab747148 | ||
|
|
2ac119cf97 | ||
|
|
ff8539eb83 | ||
|
|
f90afba39a | ||
|
|
82c8e38c69 | ||
|
|
4e4ff2b320 | ||
|
|
348745cc31 | ||
|
|
d3ea5fce44 | ||
|
|
5d7e3ef283 | ||
|
|
089a11111a | ||
|
|
f7cd714b2c | ||
|
|
acd894b2e1 | ||
|
|
8ed097ea3f | ||
|
|
b9373e0ef3 | ||
|
|
65d4ab42a4 | ||
|
|
193a7dd98c | ||
|
|
3b9f5efa1c | ||
|
|
cfc342658b | ||
|
|
bd6ff9fa68 | ||
|
|
748170326f | ||
|
|
b52a6b1b8b | ||
|
|
8f0ce9cdaf |
64
.github/workflows/test.yml
vendored
Normal file
64
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
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 POST with Unescaped Newline
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
escapeData: 'true'
|
||||||
|
data: >-
|
||||||
|
{
|
||||||
|
"key":"multi line\ntest
|
||||||
|
text"
|
||||||
|
}
|
||||||
|
|
||||||
|
- name: Request Postment Echo BasicAuth
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/basic-auth'
|
||||||
|
method: 'GET'
|
||||||
|
username: 'postman'
|
||||||
|
password: 'password'
|
||||||
|
|
||||||
|
- name: Request Postment Echo with 404 Response and ignore failure code
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/status/404'
|
||||||
|
method: 'GET'
|
||||||
|
ignoreStatusCodes: '404'
|
||||||
|
|
||||||
|
- name: Create Test File
|
||||||
|
id: image
|
||||||
|
run: |
|
||||||
|
echo "test" > testfile.txt
|
||||||
|
|
||||||
|
- name: Request Postment Echo POST Multipart
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
url: 'https://postman-echo.com/post'
|
||||||
|
method: 'POST'
|
||||||
|
data: '{ "key": "value" }'
|
||||||
|
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
|
||||||
57
README.md
57
README.md
@@ -1,21 +1,23 @@
|
|||||||
# HTTP Request Action
|
# HTTP Request Action
|
||||||
|
|
||||||
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
|
**Create HTTP Requests from GitHub Actions.** This action allows GitHub events to engage with tools like Ansible AWX that use HTTP APIs.
|
||||||
|
|
||||||
Exmaple Usage:
|
### Example
|
||||||
```
|
```yaml
|
||||||
jobs:
|
jobs:
|
||||||
deployment
|
deployment:
|
||||||
- name: Deploy Stage
|
runs-on: ubuntu-latest
|
||||||
uses: fjogeleit/http-request-action@master
|
steps:
|
||||||
with:
|
- name: Deploy Stage
|
||||||
url: 'https://ansible.io/api/v2/job_templates/84/launch/'
|
uses: fjogeleit/http-request-action@master
|
||||||
method: 'POST'
|
with:
|
||||||
username: ${{ secrets.AWX_USER }}
|
url: 'https://ansible.io/api/v2/job_templates/84/launch/'
|
||||||
password: ${{ secrets.AWX_PASSWORD }}
|
method: 'POST'
|
||||||
|
username: ${{ secrets.AWX_USER }}
|
||||||
|
password: ${{ secrets.AWX_PASSWORD }}
|
||||||
```
|
```
|
||||||
|
|
||||||
### Input Arguments
|
### Request Configuration
|
||||||
|
|
||||||
|Argument| Description | Default |
|
|Argument| Description | Default |
|
||||||
|--------|---------------|-----------|
|
|--------|---------------|-----------|
|
||||||
@@ -23,12 +25,39 @@ jobs:
|
|||||||
|method | Request Method| POST |
|
|method | Request Method| POST |
|
||||||
|contentType | Request ContentType| application/json |
|
|contentType | Request ContentType| application/json |
|
||||||
|data | Request Body Content as JSON String, only for POST / PUT / PATCH Requests | '{}' |
|
|data | Request Body Content as JSON String, only for POST / PUT / PATCH Requests | '{}' |
|
||||||
|
|files | Map of key / absolute file paths send as multipart/form-data request to the API, if set the contentType is set to multipart/form-data, values provided by data will be added as additional FormData values, nested objects are not supported. **Example provided in the _test_ Workflow of this Action** | '{}' |
|
||||||
|timeout| Request Timeout in ms | 5000 (5s) |
|
|timeout| Request Timeout in ms | 5000 (5s) |
|
||||||
|username| Username for Basic Auth ||
|
|username| Username for Basic Auth ||
|
||||||
|password| Password for Basic Auth ||
|
|password| Password for Basic Auth ||
|
||||||
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|
||||||
|customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'|
|
|customHeaders| Additional header values as JSON string, keys in this object overwrite default headers like Content-Type |'{}'|
|
||||||
|
|escapeData| Escape newlines in data string content. Use 'true' (string) as value to enable it ||
|
||||||
|
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. Use 'true' (string) as value to enable it ||
|
||||||
|
|ignoreStatusCodes| Prevent this Action to fail if the request respond with one of the configured Status Codes. Example: '404,401' ||
|
||||||
|
|
||||||
### Output
|
### Response
|
||||||
|
|
||||||
- `response` Request Response as JSON String
|
| Variable | Description |
|
||||||
|
|---|---|
|
||||||
|
`response` | Response as JSON String
|
||||||
|
|
||||||
|
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- name: Make Request
|
||||||
|
id: myRequest
|
||||||
|
uses: fjogeleit/http-request-action@master
|
||||||
|
with:
|
||||||
|
url: "http://yoursite.com/api"
|
||||||
|
- name: Show Response
|
||||||
|
run: echo ${{ steps.myRequest.outputs.response }}
|
||||||
|
```
|
||||||
|
|
||||||
|
### Additional Information
|
||||||
|
|
||||||
|
Additional information is available if debug logging is enabled:
|
||||||
|
- Instance Configuration (Url / Timeout / Headers)
|
||||||
|
- Request Data (Body / Auth / Method)
|
||||||
|
|
||||||
|
To [enable debug logging in GitHub Actions](https://docs.github.com/en/actions/managing-workflow-runs/enabling-debug-logging) create a secret `ACTIONS_RUNNER_DEBUG` with a value of `true`
|
||||||
17
action.yml
17
action.yml
@@ -11,11 +11,14 @@ inputs:
|
|||||||
contentType:
|
contentType:
|
||||||
description: 'Content Type'
|
description: 'Content Type'
|
||||||
required: false
|
required: false
|
||||||
default: 'application/json'
|
|
||||||
data:
|
data:
|
||||||
description: 'Request Body as JSON String'
|
description: 'Request Body as JSON String'
|
||||||
required: false
|
required: false
|
||||||
default: '{}'
|
default: '{}'
|
||||||
|
files:
|
||||||
|
description: 'Map of absolute file paths as JSON String'
|
||||||
|
required: false
|
||||||
|
default: '{}'
|
||||||
username:
|
username:
|
||||||
description: 'Auth Username'
|
description: 'Auth Username'
|
||||||
required: false
|
required: false
|
||||||
@@ -29,6 +32,18 @@ inputs:
|
|||||||
bearerToken:
|
bearerToken:
|
||||||
description: 'Bearer Authentication Token'
|
description: 'Bearer Authentication Token'
|
||||||
required: false
|
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
|
||||||
|
ignoreStatusCodes:
|
||||||
|
description: 'Prevent this Action to fail if the request respond with one of the configured StatusCodes'
|
||||||
|
required: false
|
||||||
|
escapeData:
|
||||||
|
description: 'Escape newlines in data string content'
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
response:
|
response:
|
||||||
description: 'HTTP Response Content'
|
description: 'HTTP Response Content'
|
||||||
|
|||||||
3385
dist/index.js
vendored
3385
dist/index.js
vendored
File diff suppressed because one or more lines are too long
187
package-lock.json
generated
187
package-lock.json
generated
@@ -1,48 +1,185 @@
|
|||||||
{
|
{
|
||||||
"name": "http-request-action",
|
"name": "http-request-action",
|
||||||
"version": "1.0.0",
|
"version": "1.8.0",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 2,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
|
"packages": {
|
||||||
|
"": {
|
||||||
|
"version": "1.8.0",
|
||||||
|
"license": "MIT",
|
||||||
|
"dependencies": {
|
||||||
|
"@zeit/ncc": "^0.22",
|
||||||
|
"axios": "^0.21.1",
|
||||||
|
"form-data": "^3.0.1"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@actions/core": "^1.2.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/@actions/core": {
|
||||||
|
"version": "1.2.6",
|
||||||
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
||||||
|
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==",
|
||||||
|
"dev": true
|
||||||
|
},
|
||||||
|
"node_modules/@zeit/ncc": {
|
||||||
|
"version": "0.22.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
|
||||||
|
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ==",
|
||||||
|
"deprecated": "@zeit/ncc is no longer maintained. Please use @vercel/ncc instead.",
|
||||||
|
"bin": {
|
||||||
|
"ncc": "dist/ncc/cli.js"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
|
},
|
||||||
|
"node_modules/axios": {
|
||||||
|
"version": "0.21.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||||
|
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||||
|
"dependencies": {
|
||||||
|
"follow-redirects": "^1.10.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/combined-stream": {
|
||||||
|
"version": "1.0.8",
|
||||||
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
|
"dependencies": {
|
||||||
|
"delayed-stream": "~1.0.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.8"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=",
|
||||||
|
"engines": {
|
||||||
|
"node": ">=0.4.0"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/follow-redirects": {
|
||||||
|
"version": "1.13.3",
|
||||||
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
|
||||||
|
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==",
|
||||||
|
"funding": [
|
||||||
|
{
|
||||||
|
"type": "individual",
|
||||||
|
"url": "https://github.com/sponsors/RubenVerborgh"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"engines": {
|
||||||
|
"node": ">=4.0"
|
||||||
|
},
|
||||||
|
"peerDependenciesMeta": {
|
||||||
|
"debug": {
|
||||||
|
"optional": true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/form-data": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
|
||||||
|
"dependencies": {
|
||||||
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-db": {
|
||||||
|
"version": "1.46.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz",
|
||||||
|
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ==",
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"node_modules/mime-types": {
|
||||||
|
"version": "2.1.29",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz",
|
||||||
|
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==",
|
||||||
|
"dependencies": {
|
||||||
|
"mime-db": "1.46.0"
|
||||||
|
},
|
||||||
|
"engines": {
|
||||||
|
"node": ">= 0.6"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/core": {
|
"@actions/core": {
|
||||||
"version": "1.2.2",
|
"version": "1.2.6",
|
||||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.2.tgz",
|
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz",
|
||||||
"integrity": "sha512-IbCx7oefq+Gi6FWbSs2Fnw8VkEI6Y4gvjrYprY3RV//ksq/KPMlClOerJ4jRosyal6zkUIc8R9fS/cpRMlGClg==",
|
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==",
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"@zeit/ncc": {
|
"@zeit/ncc": {
|
||||||
"version": "0.21.1",
|
"version": "0.22.3",
|
||||||
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz",
|
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
|
||||||
"integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw=="
|
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ=="
|
||||||
|
},
|
||||||
|
"asynckit": {
|
||||||
|
"version": "0.4.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||||
|
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||||
},
|
},
|
||||||
"axios": {
|
"axios": {
|
||||||
"version": "0.19.2",
|
"version": "0.21.1",
|
||||||
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
|
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz",
|
||||||
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
|
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"follow-redirects": "1.5.10"
|
"follow-redirects": "^1.10.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"debug": {
|
"combined-stream": {
|
||||||
"version": "3.1.0",
|
"version": "1.0.8",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
|
||||||
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
|
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"ms": "2.0.0"
|
"delayed-stream": "~1.0.0"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
"delayed-stream": {
|
||||||
|
"version": "1.0.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||||
|
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||||
|
},
|
||||||
"follow-redirects": {
|
"follow-redirects": {
|
||||||
"version": "1.5.10",
|
"version": "1.13.3",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz",
|
||||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA=="
|
||||||
|
},
|
||||||
|
"form-data": {
|
||||||
|
"version": "3.0.1",
|
||||||
|
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz",
|
||||||
|
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==",
|
||||||
"requires": {
|
"requires": {
|
||||||
"debug": "=3.1.0"
|
"asynckit": "^0.4.0",
|
||||||
|
"combined-stream": "^1.0.8",
|
||||||
|
"mime-types": "^2.1.12"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"ms": {
|
"mime-db": {
|
||||||
"version": "2.0.0",
|
"version": "1.46.0",
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz",
|
||||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ=="
|
||||||
|
},
|
||||||
|
"mime-types": {
|
||||||
|
"version": "2.1.29",
|
||||||
|
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz",
|
||||||
|
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==",
|
||||||
|
"requires": {
|
||||||
|
"mime-db": "1.46.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
11
package.json
11
package.json
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "http-request-action",
|
"name": "http-request-action",
|
||||||
"version": "1.0.0",
|
"version": "1.8.0",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"private": false,
|
"private": false,
|
||||||
@@ -13,16 +13,17 @@
|
|||||||
},
|
},
|
||||||
"keywords": [],
|
"keywords": [],
|
||||||
"author": "",
|
"author": "",
|
||||||
"license": "ISC",
|
"license": "MIT",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/fjogeleit/http-request-action/issues"
|
"url": "https://github.com/fjogeleit/http-request-action/issues"
|
||||||
},
|
},
|
||||||
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
|
"homepage": "https://github.com/fjogeleit/http-request-action#readme",
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@actions/core": "^1.2.2"
|
"@actions/core": "^1.2.6"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@zeit/ncc": "^0.21.1",
|
"@zeit/ncc": "^0.22",
|
||||||
"axios": "^0.19.2"
|
"axios": "^0.21.1",
|
||||||
|
"form-data": "^3.0.1"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/githubActions.js
Normal file
39
src/githubActions.js
Normal 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 }
|
||||||
166
src/httpClient.js
Normal file
166
src/httpClient.js
Normal file
@@ -0,0 +1,166 @@
|
|||||||
|
const axios = require("axios");
|
||||||
|
const FormData = require('form-data')
|
||||||
|
const fs = require('fs')
|
||||||
|
|
||||||
|
const METHOD_GET = 'GET'
|
||||||
|
const METHOD_POST = 'POST'
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} param0
|
||||||
|
* @param {string} param0.method HTTP Method
|
||||||
|
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} param0.instanceConfig
|
||||||
|
* @param {string} param0.data Request Body as string, default {}
|
||||||
|
* @param {string} param0.files Map of Request Files (name: absolute path) as JSON String, default: {}
|
||||||
|
* @param {{ username: string; password: string }|undefined} param0.auth Optional HTTP Basic Auth
|
||||||
|
* @param {*} param0.actions
|
||||||
|
* @param {number[]} param0.ignoredCodes Prevent Action to fail if the API response with one of this StatusCodes
|
||||||
|
* @param {boolean} param0.preventFailureOnNoResponse Prevent Action to fail if the API respond without Response
|
||||||
|
* @param {boolean} param0.escapeData Escape unescaped JSON content in data
|
||||||
|
*
|
||||||
|
* @returns {void}
|
||||||
|
*/
|
||||||
|
const request = async({ method, instanceConfig, data, files, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
|
||||||
|
try {
|
||||||
|
if (escapeData) {
|
||||||
|
data = data.replace(/"[^"]*"/g, (match) => {
|
||||||
|
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method === METHOD_GET) {
|
||||||
|
data = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (files && files !== '{}') {
|
||||||
|
filesJson = convertToJSON(files)
|
||||||
|
dataJson = convertToJSON(data)
|
||||||
|
|
||||||
|
if (Object.keys(filesJson).length > 0) {
|
||||||
|
try {
|
||||||
|
data = convertToFormData(dataJson, filesJson)
|
||||||
|
instanceConfig = await updateConfig(instanceConfig, data, actions)
|
||||||
|
} catch(error) {
|
||||||
|
actions.setFailed({ message: `Unable to convert Data and Files into FormData: ${error.message}`, data: dataJson, files: filesJson })
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const requestData = {
|
||||||
|
auth,
|
||||||
|
method,
|
||||||
|
data,
|
||||||
|
maxContentLength: Infinity,
|
||||||
|
maxBodyLength: Infinity
|
||||||
|
}
|
||||||
|
|
||||||
|
actions.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||||
|
|
||||||
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
|
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('requestError', JSON.stringify(error.toJSON()));
|
||||||
|
}
|
||||||
|
|
||||||
|
if (error.response && ignoredCodes.includes(error.response.status)) {
|
||||||
|
actions.warning(JSON.stringify({ code: error.response.status, message: error.response.data }))
|
||||||
|
} else if (error.response) {
|
||||||
|
actions.setFailed(JSON.stringify({ code: error.response.status, 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(JSON.stringify({ message: error.message, data }));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {string} value
|
||||||
|
*
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
const convertToJSON = (value) => {
|
||||||
|
try {
|
||||||
|
return JSON.parse(value)
|
||||||
|
} catch(e) {
|
||||||
|
return {}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {Object} data
|
||||||
|
* @param {Object} files
|
||||||
|
*
|
||||||
|
* @returns {FormData}
|
||||||
|
*/
|
||||||
|
const convertToFormData = (data, files) => {
|
||||||
|
formData = new FormData()
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(data)) {
|
||||||
|
formData.append(key, value)
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const [key, value] of Object.entries(files)) {
|
||||||
|
formData.append(key, fs.createReadStream(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
return formData
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} instanceConfig
|
||||||
|
* @param {FormData} formData
|
||||||
|
* @param {*} actions
|
||||||
|
*
|
||||||
|
* @returns {{ baseURL: string; timeout: number; headers: { [name: string]: string } }}
|
||||||
|
*/
|
||||||
|
const updateConfig = async (instanceConfig, formData, actions) => {
|
||||||
|
try {
|
||||||
|
const formHeaders = formData.getHeaders()
|
||||||
|
const contentType = formHeaders['content-type']
|
||||||
|
|
||||||
|
delete formHeaders['content-type']
|
||||||
|
|
||||||
|
return {
|
||||||
|
...instanceConfig,
|
||||||
|
headers: {
|
||||||
|
...instanceConfig.headers,
|
||||||
|
...formHeaders,
|
||||||
|
'Content-Length': await contentLength(formData),
|
||||||
|
'Content-Type': contentType
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch(error) {
|
||||||
|
actions.setFailed({ message: `Unable to read Content-Length: ${error.message}`, data, files })
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param {FormData} formData
|
||||||
|
*
|
||||||
|
* @returns {Promise<number>}
|
||||||
|
*/
|
||||||
|
const contentLength = (formData) => new Promise((resolve, reject) => {
|
||||||
|
formData.getLength((err, length) => {
|
||||||
|
if (err) {
|
||||||
|
reject (err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
resolve(length)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
request,
|
||||||
|
METHOD_POST,
|
||||||
|
METHOD_GET,
|
||||||
|
}
|
||||||
46
src/index.js
46
src/index.js
@@ -1,7 +1,8 @@
|
|||||||
const core = require("@actions/core");
|
const core = require("@actions/core");
|
||||||
const axios = require("axios");
|
const { request, METHOD_POST } = require('./httpClient');
|
||||||
|
const { GithubActions } = require('./githubActions');
|
||||||
|
|
||||||
const auth = {}
|
let auth = undefined
|
||||||
let customHeaders = {}
|
let customHeaders = {}
|
||||||
|
|
||||||
if (!!core.getInput('customHeaders')) {
|
if (!!core.getInput('customHeaders')) {
|
||||||
@@ -14,35 +15,36 @@ if (!!core.getInput('customHeaders')) {
|
|||||||
|
|
||||||
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
||||||
|
|
||||||
if (!!core.getInput('username')) {
|
if (!!core.getInput('username') || !!core.getInput('password')) {
|
||||||
auth.username = core.getInput('username');
|
core.debug('Add BasicHTTP Auth config')
|
||||||
}
|
|
||||||
|
|
||||||
if (!!core.getInput('password')) {
|
auth = {
|
||||||
auth.password = core.getInput('password');
|
username: core.getInput('username'),
|
||||||
|
password: core.getInput('password')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!!core.getInput('bearerToken')) {
|
if (!!core.getInput('bearerToken')) {
|
||||||
headers['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const instance = axios.create({
|
const instanceConfig = {
|
||||||
baseURL: core.getInput('url', { required: true }),
|
baseURL: core.getInput('url', { required: true }),
|
||||||
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||||
headers: { ...headers, ...customHeaders }
|
headers: { ...headers, ...customHeaders }
|
||||||
});
|
}
|
||||||
|
|
||||||
|
const data = core.getInput('data') || '{}';
|
||||||
|
const files = core.getInput('files') || '{}';
|
||||||
|
const method = core.getInput('method') || METHOD_POST;
|
||||||
|
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
|
||||||
|
const escapeData = core.getInput('escapeData') === 'true';
|
||||||
|
|
||||||
(async() => {
|
const ignoreStatusCodes = core.getInput('ignoreStatusCodes')
|
||||||
try {
|
let ignoredCodes = []
|
||||||
const response = await instance.request({
|
|
||||||
auth,
|
|
||||||
method: core.getInput('method') || 'POST',
|
|
||||||
data: JSON.parse(core.getInput('data') || '{}')
|
|
||||||
})
|
|
||||||
|
|
||||||
core.setOutput('response', JSON.stringify(response.data))
|
if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
|
||||||
} catch (error) {
|
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
|
||||||
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
|
}
|
||||||
}
|
|
||||||
})()
|
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, ignoredCodes, actions: new GithubActions() })
|
||||||
|
|||||||
Reference in New Issue
Block a user