Compare commits

...

15 Commits

Author SHA1 Message Date
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
8 changed files with 1902 additions and 308 deletions

View File

@@ -10,20 +10,20 @@ jobs:
with: with:
ref: ${{ github.ref }} ref: ${{ github.ref }}
- name: Request Postment Echo GET - name: Request Postman Echo GET
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/get' url: 'https://postman-echo.com/get'
method: 'GET' method: 'GET'
- name: Request Postment Echo POST - name: Request Postman Echo POST
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'
method: 'POST' method: 'POST'
data: '{ "key": "value" }' data: '{ "key": "value" }'
- name: Request Postment Echo POST with Unescaped Newline - name: Request Postman Echo POST with Unescaped Newline
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'
@@ -35,7 +35,7 @@ jobs:
text" text"
} }
- name: Request Postment Echo BasicAuth - name: Request Postman Echo BasicAuth
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/basic-auth' url: 'https://postman-echo.com/basic-auth'
@@ -43,7 +43,7 @@ jobs:
username: 'postman' username: 'postman'
password: 'password' password: 'password'
- name: Request Postment Echo with 404 Response and ignore failure code - name: Request Postman Echo with 404 Response and ignore failure code
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/status/404' url: 'https://postman-echo.com/status/404'
@@ -51,14 +51,20 @@ jobs:
ignoreStatusCodes: '404' ignoreStatusCodes: '404'
- name: Create Test File - name: Create Test File
id: image
run: | run: |
echo "test" > testfile.txt echo "test" > testfile.txt
- name: Request Postment Echo POST Multipart - name: Request Postman Echo POST Multipart
uses: ./ uses: ./
with: with:
url: 'https://postman-echo.com/post' url: 'https://postman-echo.com/post'
method: 'POST' method: 'POST'
data: '{ "key": "value" }' data: '{ "key": "value" }'
files: '{ "file": "${{ github.workspace }}/testfile.txt" }' 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

@@ -9,7 +9,7 @@ jobs:
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- name: Deploy Stage - name: Deploy Stage
uses: fjogeleit/http-request-action@master uses: fjogeleit/http-request-action@v1
with: with:
url: 'https://ansible.io/api/v2/job_templates/84/launch/' url: 'https://ansible.io/api/v2/job_templates/84/launch/'
method: 'POST' method: 'POST'
@@ -24,8 +24,9 @@ jobs:
|url | Request URL | _required_ Field | |url | Request URL | _required_ Field |
|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:<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** | '{}' | |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) | |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 ||
@@ -47,7 +48,7 @@ To display HTTP response data in the GitHub Actions log give the request an `id`
steps: steps:
- name: Make Request - name: Make Request
id: myRequest id: myRequest
uses: fjogeleit/http-request-action@master uses: fjogeleit/http-request-action@v1
with: with:
url: "http://yoursite.com/api" url: "http://yoursite.com/api"
- name: Show Response - name: Show Response
@@ -60,4 +61,4 @@ Additional information is available if debug logging is enabled:
- Instance Configuration (Url / Timeout / Headers) - Instance Configuration (Url / Timeout / Headers)
- Request Data (Body / Auth / Method) - 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` 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

@@ -19,6 +19,9 @@ inputs:
description: 'Map of absolute file paths as JSON String' description: 'Map of absolute file paths as JSON String'
required: false required: false
default: '{}' default: '{}'
file:
description: 'A single absolute file path'
required: false
username: username:
description: 'Auth Username' description: 'Auth Username'
required: false required: false
@@ -48,5 +51,5 @@ outputs:
response: response:
description: 'HTTP Response Content' description: 'HTTP Response Content'
runs: runs:
using: 'node12' using: 'node16'
main: 'dist/index.js' main: 'dist/index.js'

1998
dist/index.js vendored

File diff suppressed because one or more lines are too long

132
package-lock.json generated
View File

@@ -1,26 +1,39 @@
{ {
"name": "http-request-action", "name": "http-request-action",
"version": "1.8.0", "version": "1.9.0",
"lockfileVersion": 2, "lockfileVersion": 2,
"requires": true, "requires": true,
"packages": { "packages": {
"": { "": {
"version": "1.8.0", "name": "http-request-action",
"version": "1.9.0",
"license": "MIT", "license": "MIT",
"dependencies": { "dependencies": {
"@zeit/ncc": "^0.22", "@zeit/ncc": "^0.22",
"axios": "^0.21.1", "axios": "^0.21.4",
"form-data": "^3.0.1" "form-data": "^4.0.0"
}, },
"devDependencies": { "devDependencies": {
"@actions/core": "^1.2.6" "@actions/core": "^1.2.6"
} }
}, },
"node_modules/@actions/core": { "node_modules/@actions/core": {
"version": "1.2.6", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==", "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
"dev": true "dev": true,
"dependencies": {
"@actions/http-client": "^1.0.11"
}
},
"node_modules/@actions/http-client": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==",
"dev": true,
"dependencies": {
"tunnel": "0.0.6"
}
}, },
"node_modules/@zeit/ncc": { "node_modules/@zeit/ncc": {
"version": "0.22.3", "version": "0.22.3",
@@ -37,11 +50,11 @@
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"node_modules/axios": { "node_modules/axios": {
"version": "0.21.1", "version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"dependencies": { "dependencies": {
"follow-redirects": "^1.10.0" "follow-redirects": "^1.14.0"
} }
}, },
"node_modules/combined-stream": { "node_modules/combined-stream": {
@@ -64,9 +77,9 @@
} }
}, },
"node_modules/follow-redirects": { "node_modules/follow-redirects": {
"version": "1.13.3", "version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==", "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w==",
"funding": [ "funding": [
{ {
"type": "individual", "type": "individual",
@@ -83,9 +96,9 @@
} }
}, },
"node_modules/form-data": { "node_modules/form-data": {
"version": "3.0.1", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"dependencies": { "dependencies": {
"asynckit": "^0.4.0", "asynckit": "^0.4.0",
"combined-stream": "^1.0.8", "combined-stream": "^1.0.8",
@@ -96,31 +109,52 @@
} }
}, },
"node_modules/mime-db": { "node_modules/mime-db": {
"version": "1.46.0", "version": "1.51.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz",
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ==", "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==",
"engines": { "engines": {
"node": ">= 0.6" "node": ">= 0.6"
} }
}, },
"node_modules/mime-types": { "node_modules/mime-types": {
"version": "2.1.29", "version": "2.1.34",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz",
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==",
"dependencies": { "dependencies": {
"mime-db": "1.46.0" "mime-db": "1.51.0"
}, },
"engines": { "engines": {
"node": ">= 0.6" "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"
}
} }
}, },
"dependencies": { "dependencies": {
"@actions/core": { "@actions/core": {
"version": "1.2.6", "version": "1.6.0",
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.2.6.tgz", "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
"integrity": "sha512-ZQYitnqiyBc3D+k7LsgSBmMDVkOVidaagDG7j3fOym77jNunWRuYx7VSHa9GNfFZh+zh61xsCjRj4JxMZlDqTA==", "integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
"dev": true "dev": true,
"requires": {
"@actions/http-client": "^1.0.11"
}
},
"@actions/http-client": {
"version": "1.0.11",
"resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-1.0.11.tgz",
"integrity": "sha512-VRYHGQV1rqnROJqdMvGUbY/Kn8vriQe/F9HR2AlYHzmKuM/p3kjNuXhmdBfcVgsvRWTz5C5XW5xvndZrVBuAYg==",
"dev": true,
"requires": {
"tunnel": "0.0.6"
}
}, },
"@zeit/ncc": { "@zeit/ncc": {
"version": "0.22.3", "version": "0.22.3",
@@ -133,11 +167,11 @@
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k=" "integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
}, },
"axios": { "axios": {
"version": "0.21.1", "version": "0.21.4",
"resolved": "https://registry.npmjs.org/axios/-/axios-0.21.1.tgz", "resolved": "https://registry.npmjs.org/axios/-/axios-0.21.4.tgz",
"integrity": "sha512-dKQiRHxGD9PPRIUNIWvZhPTPpl1rf/OxTYKsqKUDjBwYylTvV7SjSHJb9ratfyzM6wCdLCOYLzs73qpg5c4iGA==", "integrity": "sha512-ut5vewkiu8jjGBdqpM44XxjuCjq9LAKeHVmoVfHVzy8eHgxxq8SbAVQNovDA8mVi05kP0Ea/n/UzcSHcTJQfNg==",
"requires": { "requires": {
"follow-redirects": "^1.10.0" "follow-redirects": "^1.14.0"
} }
}, },
"combined-stream": { "combined-stream": {
@@ -154,14 +188,14 @@
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk=" "integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
}, },
"follow-redirects": { "follow-redirects": {
"version": "1.13.3", "version": "1.14.9",
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.3.tgz", "resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.9.tgz",
"integrity": "sha512-DUgl6+HDzB0iEptNQEXLx/KhTmDb8tZUHSeLqpnjpknR70H0nC2t9N73BK6fN4hOvJ84pKlIQVQ4k5FFlBedKA==" "integrity": "sha512-MQDfihBQYMcyy5dhRDJUHcw7lb2Pv/TuE6xP1vyraLukNDHKbDxDNaOE3NbCAdKQApno+GPRyo1YAp89yCjK4w=="
}, },
"form-data": { "form-data": {
"version": "3.0.1", "version": "4.0.0",
"resolved": "https://registry.npmjs.org/form-data/-/form-data-3.0.1.tgz", "resolved": "https://registry.npmjs.org/form-data/-/form-data-4.0.0.tgz",
"integrity": "sha512-RHkBKtLWUVwd7SqRIvCZMEvAMoGUp0XU+seQiZejj0COz3RI3hWP4sCv3gZWWLjJTd7rGwcsF5eKZGii0r/hbg==", "integrity": "sha512-ETEklSGi5t0QMZuiXoA/Q6vcnxcLQP5vdugSpuAyi6SVGi2clPPp+xgEhuMaHC+zGgn31Kd235W35f7Hykkaww==",
"requires": { "requires": {
"asynckit": "^0.4.0", "asynckit": "^0.4.0",
"combined-stream": "^1.0.8", "combined-stream": "^1.0.8",
@@ -169,17 +203,23 @@
} }
}, },
"mime-db": { "mime-db": {
"version": "1.46.0", "version": "1.51.0",
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.46.0.tgz", "resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz",
"integrity": "sha512-svXaP8UQRZ5K7or+ZmfNhg2xX3yKDMUzqadsSqi4NCH/KomcH75MAMYAGVlvXn4+b/xOPhS3I2uHKRUzvjY7BQ==" "integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g=="
}, },
"mime-types": { "mime-types": {
"version": "2.1.29", "version": "2.1.34",
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.29.tgz", "resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz",
"integrity": "sha512-Y/jMt/S5sR9OaqteJtslsFZKWOIIqMACsJSiHghlCAyhf7jfVYjKBmLiX8OgpWeW+fjJ2b+Az69aPFPkUOY6xQ==", "integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==",
"requires": { "requires": {
"mime-db": "1.46.0" "mime-db": "1.51.0"
} }
},
"tunnel": {
"version": "0.0.6",
"resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz",
"integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==",
"dev": true
} }
} }
} }

View File

@@ -1,6 +1,6 @@
{ {
"name": "http-request-action", "name": "http-request-action",
"version": "1.8.0", "version": "1.9.0",
"description": "", "description": "",
"main": "src/index.js", "main": "src/index.js",
"private": false, "private": false,
@@ -23,7 +23,7 @@
}, },
"dependencies": { "dependencies": {
"@zeit/ncc": "^0.22", "@zeit/ncc": "^0.22",
"axios": "^0.21.1", "axios": "^0.21.4",
"form-data": "^3.0.1" "form-data": "^4.0.0"
} }
} }

View File

@@ -11,6 +11,7 @@ const METHOD_POST = 'POST'
* @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} param0.instanceConfig * @param {{ baseURL: string; timeout: number; headers: { [name: string]: string } }} param0.instanceConfig
* @param {string} param0.data Request Body as string, default {} * @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.files Map of Request Files (name: absolute path) as JSON String, default: {}
* @param {string} param0.file Single request file (absolute path)
* @param {{ username: string; password: string }|undefined} param0.auth Optional HTTP Basic Auth * @param {{ username: string; password: string }|undefined} param0.auth Optional HTTP Basic Auth
* @param {*} param0.actions * @param {*} param0.actions
* @param {number[]} param0.ignoredCodes Prevent Action to fail if the API response with one of this StatusCodes * @param {number[]} param0.ignoredCodes Prevent Action to fail if the API response with one of this StatusCodes
@@ -19,7 +20,7 @@ const METHOD_POST = 'POST'
* *
* @returns {void} * @returns {void}
*/ */
const request = async({ method, instanceConfig, data, files, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => { const request = async({ method, instanceConfig, data, files, file, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
try { try {
if (escapeData) { if (escapeData) {
data = data.replace(/"[^"]*"/g, (match) => { data = data.replace(/"[^"]*"/g, (match) => {
@@ -32,8 +33,8 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
} }
if (files && files !== '{}') { if (files && files !== '{}') {
filesJson = convertToJSON(files) let filesJson = convertToJSON(files)
dataJson = convertToJSON(data) let dataJson = convertToJSON(data)
if (Object.keys(filesJson).length > 0) { if (Object.keys(filesJson).length > 0) {
try { try {
@@ -46,6 +47,12 @@ const request = async({ method, instanceConfig, data, files, auth, actions, igno
} }
} }
// 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 = { const requestData = {
auth, auth,
method, method,
@@ -143,6 +150,30 @@ const updateConfig = async (instanceConfig, formData, actions) => {
} }
} }
/**
* @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 * @param {FormData} formData
* *

View File

@@ -36,6 +36,7 @@ const instanceConfig = {
const data = core.getInput('data') || '{}'; const data = core.getInput('data') || '{}';
const files = core.getInput('files') || '{}'; const files = core.getInput('files') || '{}';
const file = core.getInput('file')
const method = core.getInput('method') || METHOD_POST; const method = core.getInput('method') || METHOD_POST;
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true'; const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
const escapeData = core.getInput('escapeData') === 'true'; const escapeData = core.getInput('escapeData') === 'true';
@@ -47,4 +48,4 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim())) ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
} }
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, ignoredCodes, actions: new GithubActions() }) request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, file, ignoredCodes, actions: new GithubActions() })