mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 00:55:52 +08:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f91c5933c4 | ||
|
|
3a9531bb34 | ||
|
|
0cc64a5579 | ||
|
|
81e44c2059 | ||
|
|
cc4fc855b5 | ||
|
|
c7cadd574f | ||
|
|
3634ea0063 |
12
.github/workflows/test.yml
vendored
12
.github/workflows/test.yml
vendored
@@ -23,6 +23,18 @@ jobs:
|
|||||||
method: 'POST'
|
method: 'POST'
|
||||||
data: '{ "key": "value" }'
|
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
|
- name: Request Postment Echo BasicAuth
|
||||||
uses: ./
|
uses: ./
|
||||||
with:
|
with:
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ jobs:
|
|||||||
|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 |'{}'|
|
||||||
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. 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 ||
|
||||||
|
|escapeData| Escape newlines in data string content. Use 'true' (string) as value to enable it ||
|
||||||
|
|
||||||
### Output
|
### Output
|
||||||
|
|
||||||
|
|||||||
@@ -29,9 +29,15 @@ inputs:
|
|||||||
bearerToken:
|
bearerToken:
|
||||||
description: 'Bearer Authentication Token'
|
description: 'Bearer Authentication Token'
|
||||||
required: false
|
required: false
|
||||||
|
customHeaders:
|
||||||
|
description: 'Custom HTTP Headers'
|
||||||
|
required: false
|
||||||
preventFailureOnNoResponse:
|
preventFailureOnNoResponse:
|
||||||
description: 'Prevent this Action to fail if the request respond without an response'
|
description: 'Prevent this Action to fail if the request respond without an response'
|
||||||
required: false
|
required: false
|
||||||
|
escapeData:
|
||||||
|
description: 'Escape newlines in data string content'
|
||||||
|
required: false
|
||||||
outputs:
|
outputs:
|
||||||
response:
|
response:
|
||||||
description: 'HTTP Response Content'
|
description: 'HTTP Response Content'
|
||||||
|
|||||||
1623
dist/index.js
vendored
1623
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
44
package-lock.json
generated
44
package-lock.json
generated
@@ -1,48 +1,32 @@
|
|||||||
{
|
{
|
||||||
"name": "http-request-action",
|
"name": "http-request-action",
|
||||||
"version": "1.4.0",
|
"version": "1.6.1",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"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=="
|
||||||
},
|
},
|
||||||
"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": {
|
|
||||||
"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": {
|
"follow-redirects": {
|
||||||
"version": "1.5.10",
|
"version": "1.13.1",
|
||||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.5.10.tgz",
|
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.13.1.tgz",
|
||||||
"integrity": "sha512-0V5l4Cizzvqt5D44aTXbFZz+FtyXV1vrDN6qrelxtfYQKW0KO0W2T/hkE8xvGa/540LkZlkaUjO4ailYTFtHVQ==",
|
"integrity": "sha512-SSG5xmZh1mkPGyKzjZP8zLjltIfpW32Y5QpdNJyjcfGxK3qo3NDDkZOZSFiGn1A6SclQxY9GzEwAHQ3dmYRWpg=="
|
||||||
"requires": {
|
|
||||||
"debug": "=3.1.0"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"ms": {
|
|
||||||
"version": "2.0.0",
|
|
||||||
"resolved": "https://registry.npmjs.org/ms/-/ms-2.0.0.tgz",
|
|
||||||
"integrity": "sha1-VgiurfwAvmwpAd9fmGF4jeDVl8g="
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "http-request-action",
|
"name": "http-request-action",
|
||||||
"version": "1.4.0",
|
"version": "1.6.1",
|
||||||
"description": "",
|
"description": "",
|
||||||
"main": "src/index.js",
|
"main": "src/index.js",
|
||||||
"private": false,
|
"private": false,
|
||||||
@@ -19,10 +19,10 @@
|
|||||||
},
|
},
|
||||||
"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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,16 +3,24 @@ const axios = require("axios");
|
|||||||
const METHOD_GET = 'GET'
|
const METHOD_GET = 'GET'
|
||||||
const METHOD_POST = 'POST'
|
const METHOD_POST = 'POST'
|
||||||
|
|
||||||
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse }) => {
|
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse, escapeData }) => {
|
||||||
try {
|
try {
|
||||||
const instance = axios.create(instanceConfig);
|
const instance = axios.create(instanceConfig);
|
||||||
|
|
||||||
const jsonData = method === METHOD_GET ? undefined : JSON.parse(data)
|
if (escapeData) {
|
||||||
|
data = data.replace(/"[^"]*"/g, (match) => {
|
||||||
|
return match.replace(/[\n\r]\s*/g, "\\n");
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (method === METHOD_GET) {
|
||||||
|
data = undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const requestData = {
|
const requestData = {
|
||||||
auth,
|
auth,
|
||||||
method,
|
method,
|
||||||
data: jsonData
|
data
|
||||||
}
|
}
|
||||||
|
|
||||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||||
@@ -32,7 +40,7 @@ const request = async({ method, instanceConfig, data, auth, actions, preventFail
|
|||||||
} else if (error.request && preventFailureOnNoResponse) {
|
} else if (error.request && preventFailureOnNoResponse) {
|
||||||
actions.warning(JSON.stringify(error));
|
actions.warning(JSON.stringify(error));
|
||||||
} else {
|
} else {
|
||||||
actions.setFailed(error.message);
|
actions.setFailed(JSON.stringify({ message: error.message, data }));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -39,5 +39,6 @@ core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
|||||||
const data = core.getInput('data') || '{}';
|
const data = core.getInput('data') || '{}';
|
||||||
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';
|
||||||
|
|
||||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, actions: new GithubActions() })
|
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, actions: new GithubActions() })
|
||||||
|
|||||||
Reference in New Issue
Block a user