Compare commits

...

47 Commits

Author SHA1 Message Date
Frank Jogeleit
fd5cf60c69 Merge pull request #58 from fjogeleit/formdata-fix
Fix undefined data for files
2022-10-05 17:31:01 +02:00
Frank Jogeleit
2214f2de10 Fix undefined data for files
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-10-05 17:29:30 +02:00
Frank Jogeleit
9e07856983 Merge pull request #53 from fjogeleit/dependabot/npm_and_yarn/actions/core-1.9.1
Bump @actions/core from 1.9.0 to 1.9.1
2022-08-18 22:06:09 +02:00
dependabot[bot]
df4c18fdd5 Bump @actions/core from 1.9.0 to 1.9.1
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.9.0 to 1.9.1.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

---
updated-dependencies:
- dependency-name: "@actions/core"
  dependency-type: direct:development
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-18 19:59:33 +00:00
Nick Hills
4cbc7a46b2 Adding ability to return headers without setting debug mode (#51)
* Update httpClient.js
* Update README.md
* Update action.yml

Co-authored-by: Nick Hills <nick.hills@valtech.com>
2022-08-17 09:56:02 +02:00
Frank Jogeleit
cce3f3d779 Add new httpsCA input to README.md
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-07-23 15:18:23 +02:00
Frank Jogeleit
52ba495021 Merge pull request #49 from fjogeleit/custom-ca-support
Add input for custom CA
2022-07-19 10:29:59 +02:00
Frank Jogeleit
df00cdf429 Add input for custom CA
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-07-19 10:27:31 +02:00
Frank Jogeleit
e3313c1a5f Update Error Output
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-06-04 10:52:53 +02:00
Frank Jogeleit
d4c0bee13c Merge pull request #45 from yesjinu/docs/enhance-readme
docs: enhance README.md
2022-05-24 13:25:37 +02:00
Jinu Noh
435fe1dbc8 docs: enhance README.md 2022-05-24 19:22:08 +09:00
Frank Jogeleit
35336be18d Update README 2022-03-04 11:26:59 +01:00
Frank Jogeleit
f986377e36 Update Version 2022-03-04 11:22:31 +01:00
Frank Jogeleit
046e838b3a Dependency Update (#41)
Dependency Update
2022-03-04 11:20:10 +01:00
Frank Jogeleit
31fad16908 Merge pull request #39 from fjogeleit/dependabot/npm_and_yarn/follow-redirects-1.14.8
Bump follow-redirects from 1.14.7 to 1.14.8
2022-02-13 10:59:39 +01:00
dependabot[bot]
5c4179dc69 Bump follow-redirects from 1.14.7 to 1.14.8
Bumps [follow-redirects](https://github.com/follow-redirects/follow-redirects) from 1.14.7 to 1.14.8.
- [Release notes](https://github.com/follow-redirects/follow-redirects/releases)
- [Commits](https://github.com/follow-redirects/follow-redirects/compare/v1.14.7...v1.14.8)

---
updated-dependencies:
- dependency-name: follow-redirects
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-02-13 06:50:19 +00:00
Frank Jogeleit
d45f6649f6 Merge pull request #37 from Atlas-Authority/master
Support single file upload
2022-02-11 12:31:32 +01:00
Nhan Nguyen
f683177370 Support single file upload 2022-02-10 10:14:07 +07:00
Frank Jogeleit
a6980b2ca5 Merge pull request #36 from fjogeleit/dependency-update
Dependency Update
2022-01-16 17:29:35 +01:00
Frank Jogeleit
70ee000b97 Dependency Update
Signed-off-by: Frank Jogeleit <frank.jogeleit@lovoo.com>
2022-01-16 17:27:57 +01:00
Frank Jogeleit
5e30e204fc Update README.md 2021-12-10 17:44:42 +01:00
Frank Jogeleit
82d22dd60f Merge pull request #34 from understructure/docs-update
docs: clarification that data can be entered as key value pairs under appropriate conditions
2021-10-12 23:20:13 +02:00
Matthew Cloney
1ea54adf35 docs: clarification that data can be entered as key value pairs under appropriate conditions 2021-10-12 16:57:47 -04:00
Frank Jogeleit
8e939c608a dependency updates
Signed-off-by: Frank Jogeleit <fj@move-elevator.de>
2021-09-09 14:42:30 +02:00
Frank Jogeleit
7c5a3f2e70 Merge pull request #30 from fjogeleit/dependabot/npm_and_yarn/axios-0.21.2
Bump axios from 0.21.1 to 0.21.2
2021-09-09 14:30:28 +02:00
dependabot[bot]
78bba76cbe Bump axios from 0.21.1 to 0.21.2
Bumps [axios](https://github.com/axios/axios) from 0.21.1 to 0.21.2.
- [Release notes](https://github.com/axios/axios/releases)
- [Changelog](https://github.com/axios/axios/blob/master/CHANGELOG.md)
- [Commits](https://github.com/axios/axios/compare/v0.21.1...v0.21.2)

---
updated-dependencies:
- dependency-name: axios
  dependency-type: direct:production
...

Signed-off-by: dependabot[bot] <support@github.com>
2021-09-09 11:38:52 +00:00
Frank Jogeleit
3e3e6b3eec Update test.yml 2021-07-22 14:52:06 +02:00
Frank Jogeleit
0929a0c636 Ignored status codes (#26)
* Implement StatusCode ignore list
2021-03-19 17:28:53 +01:00
Frank Jogeleit
bd043fe286 Build new version 2021-02-19 12:51:47 +01:00
Frank Jogeleit
7626a13e42 Disable MaxContentLength and MaxBodyLength check (#23)
* Disable MaxContentLength and MaxBodyLength check
2021-02-19 11:36:10 +01:00
Scott W Harden
48dc3972df more documentation with code sample (#21)
* improve debug logging documentation
* document how to log response content
* add syntax highlighting
* improve description

This action can be used to do more than just interact with Ansible AWS. I rephrased the description to emphasize its general utility.
2021-01-26 17:49:24 +01:00
Frank Jogeleit
84e61f1a56 Update version 2021-01-24 14:09:17 +01:00
Frank Jogeleit
42677b964e Update FileUpload ContentType 2021-01-24 13:52:05 +01:00
Frank Jogeleit
b6bb4fa030 File upload (#20)
* Add Support for FileUpload
2021-01-24 13:14:13 +01:00
Frank Jogeleit
de202bb090 Merge pull request #18 from Hoopless/master
Changes to basic Example
2021-01-20 10:44:46 +01:00
Jasper
eff73a48f7 Update README.md 2021-01-20 00:21:04 +01:00
Frank Jogeleit
f91c5933c4 axios update 2021-01-05 18:57:45 +01:00
Frank Jogeleit
3a9531bb34 Dependency Update // Support none JSON Body (#17)
* Dependency Update // Support none JSON Body

* Specify action text case name
2020-12-16 21:37:11 +01:00
Frank Jogeleit
0cc64a5579 Support for unescaped newlines in data (#16)
* support newline escaping
2020-10-07 18:29:38 +02:00
Frank Jogeleit
81e44c2059 Update Dependencies 2020-10-01 22:20:08 +02:00
Frank Jogeleit
cc4fc855b5 Merge pull request #14 from fjogeleit/dependabot/npm_and_yarn/actions/core-1.2.6
Bump @actions/core from 1.2.2 to 1.2.6
2020-10-01 22:16:26 +02:00
dependabot[bot]
c7cadd574f Bump @actions/core from 1.2.2 to 1.2.6
Bumps [@actions/core](https://github.com/actions/toolkit/tree/HEAD/packages/core) from 1.2.2 to 1.2.6.
- [Release notes](https://github.com/actions/toolkit/releases)
- [Changelog](https://github.com/actions/toolkit/blob/main/packages/core/RELEASES.md)
- [Commits](https://github.com/actions/toolkit/commits/HEAD/packages/core)

Signed-off-by: dependabot[bot] <support@github.com>
2020-10-01 17:32:37 +00:00
Frank Jogeleit
3634ea0063 Fix removed config 2020-08-04 17:09:29 +02:00
Frank Jogeleit
b63e908234 Merge pull request #13 from fjogeleit/handle-empty-response
Add new input option "preventFailureOnNoResponse"
2020-07-30 18:31:32 +02:00
Frank Jogeleit
60ab747148 Split Action in multiple files to improve testing
Add a new InputOption to ignore a failure for no response receive
2020-07-30 18:27:27 +02:00
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
9 changed files with 6542 additions and 2012 deletions

View File

@@ -10,23 +10,68 @@ jobs:
with:
ref: ${{ github.ref }}
- name: Request Postment Echo GET
- name: Request Postman Echo GET
uses: ./
with:
url: 'https://postman-echo.com/get'
method: 'GET'
- name: Request Postment Echo POST
- name: Request Postman Echo POST
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
- name: Request Postment Echo BasicAuth
- name: Request Postman 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 Postman Echo BasicAuth
uses: ./
with:
url: 'https://postman-echo.com/basic-auth'
method: 'GET'
username: 'postman'
password: 'password'
- name: Request Postman 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
run: |
echo "test" > testfile.txt
- name: Request Postman Echo POST Multipart
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
data: '{ "key": "value" }'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
- name: Request Postman Echo POST Multipart without data
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }'
- name: Request Postman Echo POST single file
uses: ./
with:
url: 'https://postman-echo.com/post'
method: 'POST'
file: "${{ github.workspace }}/testfile.txt"

View File

@@ -1,42 +1,75 @@
# 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.
Example Usage:
```
### Example
```yaml
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 }}
deployment:
runs-on: ubuntu-latest
steps:
- name: Deploy Stage
uses: fjogeleit/http-request-action@v1
with:
url: 'https://ansible.io/api/v2/job_templates/84/launch/'
method: 'POST'
username: ${{ secrets.AWX_USER }}
password: ${{ secrets.AWX_PASSWORD }}
customHeaders: '{"Content-Type": "application/json"}'
data: '{"key_1": "value_1", "key_2": "value_2"}'
```
### Input Arguments
### Versioning
`master` branch is deprecated. Please use `main` or `v1` to get the latest version of this action. It is recommended to use a fixed version.
### Request Configuration
|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 | '{}' |
|data | Request Body Content:<br>- text content like JSON or XML<br>- key=value pairs separated by '&' and contentType: application/x-www-form-urlencoded<br><br>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** | '{}' |
|file | Single absolute file path send as `application/octet-stream` request to the API, if set the contentType is set to `application/octet-stream`. This input will be ignored if either `data` or `files` input is present. **Example provided in the _test_ Workflow of this Action** ||
|timeout| Request Timeout in ms | 5000 (5s) |
|username| Username for Basic Auth ||
|password| Password for Basic Auth ||
|bearerToken| Bearer Authentication Token (without Bearer Prefix) ||
|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' ||
|httpsCA| Certificate authority as string in PEM format ||
### Output
### Response
- `response` Request Response as JSON String
| Variable | Description |
|---|---|
`response` | Response as JSON String
`headers` | Headers
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`. You can also access specific field from the response data using [fromJson()](https://docs.github.com/en/actions/learn-github-actions/expressions#fromjson) expression.
### Debug Informations
```yaml
steps:
- name: Make Request
id: myRequest
uses: fjogeleit/http-request-action@v1
with:
url: "http://yoursite.com/api"
- name: Show Response
run: |
echo ${{ steps.myRequest.outputs.response }}
echo ${{ steps.myRequest.outputs.headers }}
echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }}
```
Enable Debug mode to get informations about
### 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`

View File

@@ -11,11 +11,17 @@ inputs:
contentType:
description: 'Content Type'
required: false
default: 'application/json'
data:
description: 'Request Body as JSON String'
required: false
default: '{}'
files:
description: 'Map of absolute file paths as JSON String'
required: false
default: '{}'
file:
description: 'A single absolute file path'
required: false
username:
description: 'Auth Username'
required: false
@@ -29,9 +35,26 @@ inputs:
bearerToken:
description: 'Bearer Authentication Token'
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
httpsCA:
description: 'Certificate authority as string in PEM format'
required: false
outputs:
response:
description: 'HTTP Response Content'
headers:
description: 'HTTP Response Headers'
runs:
using: 'node12'
using: 'node16'
main: 'dist/index.js'

7839
dist/index.js vendored

File diff suppressed because one or more lines are too long

246
package-lock.json generated
View File

@@ -1,48 +1,242 @@
{
"name": "http-request-action",
"version": "1.0.0",
"lockfileVersion": 1,
"version": "1.9.0",
"lockfileVersion": 2,
"requires": true,
"packages": {
"": {
"name": "http-request-action",
"version": "1.9.0",
"license": "MIT",
"dependencies": {
"@zeit/ncc": "^0.22",
"axios": "^0.21.4",
"form-data": "^4.0.0"
},
"devDependencies": {
"@actions/core": "^1.9.1"
}
},
"node_modules/@actions/core": {
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"dev": true,
"dependencies": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"node_modules/@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dev": true,
"dependencies": {
"tunnel": "^0.0.6"
}
},
"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": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"node_modules/axios": {
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dependencies": {
"follow-redirects": "^1.14.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": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
"engines": {
"node": ">=0.4.0"
}
},
"node_modules/follow-redirects": {
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA==",
"funding": [
{
"type": "individual",
"url": "https://github.com/sponsors/RubenVerborgh"
}
],
"engines": {
"node": ">=4.0"
},
"peerDependenciesMeta": {
"debug": {
"optional": true
}
}
},
"node_modules/form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": {
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
},
"engines": {
"node": ">= 6"
}
},
"node_modules/mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg==",
"engines": {
"node": ">= 0.6"
}
},
"node_modules/mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"dependencies": {
"mime-db": "1.52.0"
},
"engines": {
"node": ">= 0.6"
}
},
"node_modules/tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"dev": true,
"engines": {
"node": ">=0.6.11 <=0.7.0 || >=0.7.3"
}
},
"node_modules/uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"dev": true,
"bin": {
"uuid": "dist/bin/uuid"
}
}
},
"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
"version": "1.10.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.10.0.tgz",
"integrity": "sha512-2aZDDa3zrrZbP5ZYg159sNoLRb61nQ7awl5pSvIq5Qpj81vwDzdMRKzkWJGJuwVvWpvZKx7vspJALyvaaIQyug==",
"dev": true,
"requires": {
"@actions/http-client": "^2.0.1",
"uuid": "^8.3.2"
}
},
"@actions/http-client": {
"version": "2.0.1",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.0.1.tgz",
"integrity": "sha512-PIXiMVtz6VvyaRsGY268qvj57hXQEpsYogYOu2nrQhlf+XCGmZstmuZBbAybUl1nQGnvS1k1eEsQ69ZoD7xlSw==",
"dev": true,
"requires": {
"tunnel": "^0.0.6"
}
},
"@zeit/ncc": {
"version": "0.21.1",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.21.1.tgz",
"integrity": "sha512-M9WzgquSOt2nsjRkYM9LRylBLmmlwNCwYbm3Up3PDEshfvdmIfqpFNSK8EJvR18NwZjGHE5z2avlDtYQx2JQnw=="
"version": "0.22.3",
"resolved": "https://registry.npmjs.org/@zeit/ncc/-/ncc-0.22.3.tgz",
"integrity": "sha512-jnCLpLXWuw/PAiJiVbLjA8WBC0IJQbFeUwF4I9M+23MvIxTxk5pD4Q8byQBSPmHQjz5aBoA7AKAElQxMpjrCLQ=="
},
"asynckit": {
"version": "0.4.0",
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
},
"axios": {
"version": "0.19.2",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.19.2.tgz",
"integrity": "sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==",
"version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": {
"follow-redirects": "1.5.10"
"follow-redirects": "^1.14.0"
}
},
"debug": {
"version": "3.1.0",
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
"integrity": "sha512-OX8XqP7/1a9cqkxYw2yXss15f26NKWBpDXQd0/uK/KPqdQhxbPa994hnzjcE2VqQpDslf55723cKPUOGSmMY3g==",
"combined-stream": {
"version": "1.0.8",
"resolved": "https://registry.npmjs.org/combined-stream/-/combined-stream-1.0.8.tgz",
"integrity": "sha512-FQN4MRfuJeHf7cBbBMJFXhKSDq+2kAArBlmRBvcvFE5BB1HZKXtSFASDhdlz9zOYwxh8lDdnvmMOe/+5cdoEdg==",
"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": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
},
"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==",
"version": "1.15.2",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.2.tgz",
"integrity": "sha512-VQLG33o04KaQ8uYi2tVNbdrWp1QWxNNea+nmIB4EVM28v0hmP17z7aG1+wAkNzVq4KeXTq3221ye5qTJP91JwA=="
},
"form-data": {
"version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": {
"debug": "=3.1.0"
"asynckit": "^0.4.0",
"combined-stream": "^1.0.8",
"mime-types": "^2.1.12"
}
},
"ms": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
"mime-db": {
"version": "1.52.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.52.0.tgz",
"integrity": "sha512-sPU4uV7dYlvtWJxwwxHD0PuihVNiE7TyAbQ5SWxDCB9mUYvOgroQOwYQQOKPJ8CIbE+1ETVlOoK1UC2nU3gYvg=="
},
"mime-types": {
"version": "2.1.35",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.35.tgz",
"integrity": "sha512-ZDY+bPm5zTTF+YpCrAU9nK0UgICYPT0QtT1NZWFv4s++TNkcgVaT0g6+4R2uI4MjQjzysHB1zxuWL50hzaeXiw==",
"requires": {
"mime-db": "1.52.0"
}
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"dev": true
},
"uuid": {
"version": "8.3.2",
"resolved": "https://registry.npmjs.org/uuid/-/uuid-8.3.2.tgz",
"integrity": "sha512-+NYs2QeMWy+GWFOEm9xnn6HCDp0l7QBD7ml8zLUmJ+93Q5NF0NocErnwkTkXVFNiX3/fpC6afS8Dhb/gz7R7eg==",
"dev": true
}
}
}

View File

@@ -1,6 +1,6 @@
{
"name": "http-request-action",
"version": "1.3.2",
"version": "1.9.0",
"description": "",
"main": "src/index.js",
"private": false,
@@ -13,16 +13,17 @@
},
"keywords": [],
"author": "",
"license": "ISC",
"license": "MIT",
"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"
"@actions/core": "^1.9.1"
},
"dependencies": {
"@zeit/ncc": "^0.21.1",
"axios": "^0.19.2"
"@zeit/ncc": "^0.22",
"axios": "^0.21.4",
"form-data": "^4.0.0"
}
}

39
src/githubActions.js Normal file
View 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 }

198
src/httpClient.js Normal file
View File

@@ -0,0 +1,198 @@
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 {axios.AxiosRequestConfig} 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 {string} param0.file Single request file (absolute path)
* @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, file, 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 !== '{}') {
let filesJson = convertToJSON(files)
let 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
}
}
}
// Only consider file if neither data nor files provided
if ((!data || data === '{}') && (!files || files === '{}') && file) {
data = fs.createReadStream(file)
updateConfigForFile(instanceConfig, file, actions)
}
const requestData = {
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))
actions.setOutput('headers', response.headers)
} catch (error) {
if ((typeof error === 'object') && (error.isAxiosError === true)) {
const { name, message, code, response } = error
actions.setOutput('requestError', JSON.stringify({ name, message, code, status: response && response.status ? response.status : null }));
}
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 instanceConfig
* @param filePath
* @param {*} actions
*
* @returns {{ baseURL: string; timeout: number; headers: { [name: string]: string } }}
*/
const updateConfigForFile = (instanceConfig, filePath, actions) => {
try {
const { size } = fs.statSync(filePath)
return {
...instanceConfig,
headers: {
...instanceConfig.headers,
'Content-Length': size,
'Content-Type': 'application/octet-stream'
}
}
} 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,
}

View File

@@ -1,8 +1,8 @@
const core = require("@actions/core");
const axios = require("axios");
const METHOD_GET = 'GET'
const METHOD_POST = 'POST'
const core = require('@actions/core');
const axios = require('axios');
const https = require('https');
const { request, METHOD_POST } = require('./httpClient');
const { GithubActions } = require('./githubActions');
let auth = undefined
let customHeaders = {}
@@ -17,56 +17,42 @@ if (!!core.getInput('customHeaders')) {
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
}
if (!!core.getInput('bearerToken')) {
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
}
/** @type {axios.AxiosRequestConfig} */
const instanceConfig = {
baseURL: core.getInput('url', { required: true }),
timeout: parseInt(core.getInput('timeout') || 5000, 10),
headers: { ...headers, ...customHeaders }
}
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
if (!!core.getInput('httpsCA')) {
instanceConfig.httpsAgent = new https.Agent({ ca: core.getInput('httpsCA') })
}
const instance = axios.create(instanceConfig);
if (!!core.getInput('username') || !!core.getInput('password')) {
core.debug('Add BasicHTTP Auth config')
(async() => {
try {
const method = core.getInput('method') || METHOD_POST;
const data = method === METHOD_GET ? undefined : JSON.parse(core.getInput('data') || '{}')
const requestData = {
auth,
method,
data
}
core.debug('Request Data: ' + JSON.stringify(requestData))
const response = await instance.request(requestData)
core.setOutput('response', JSON.stringify(response.data))
} catch (error) {
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);
}
instanceConfig.auth = {
username: core.getInput('username'),
password: core.getInput('password')
}
})()
}
const data = core.getInput('data') || '{}';
const files = core.getInput('files') || '{}';
const file = core.getInput('file')
const method = core.getInput('method') || METHOD_POST;
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
const escapeData = core.getInput('escapeData') === 'true';
const ignoreStatusCodes = core.getInput('ignoreStatusCodes')
let ignoredCodes = []
if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
}
request({ data, method, instanceConfig, preventFailureOnNoResponse, escapeData, files, file, ignoredCodes, actions: new GithubActions() })