mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 17:45:55 +08:00
Compare commits
26 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
74e0e96181 | ||
|
|
2bb8059d00 | ||
|
|
bfbe4dd6af | ||
|
|
7c708e96af | ||
|
|
f9dc1a8d4b | ||
|
|
33a4d079d7 | ||
|
|
0b6ec5eadd | ||
|
|
897b6a3c96 | ||
|
|
363da44e0a | ||
|
|
1a131d17cc | ||
|
|
72a0a5b93e | ||
|
|
606bb16fb9 | ||
|
|
517601f732 | ||
|
|
c9a231b621 | ||
|
|
2e6550f5bd | ||
|
|
caab55e3d8 | ||
|
|
997aeb8de8 | ||
|
|
0bd00a33db | ||
|
|
a665541d9c | ||
|
|
e23645bd9b | ||
|
|
897543ff26 | ||
|
|
3fee944184 | ||
|
|
c23f0d6631 | ||
|
|
6dd87961de | ||
|
|
d81c81a128 | ||
|
|
2d6a2f17dc |
@@ -45,6 +45,7 @@ jobs:
|
||||
|httpsCert| Client Certificate as string ||
|
||||
|httpsKey| Client Certificate Key as string ||
|
||||
|responseFile| Persist the response data to the specified file path ||
|
||||
|maskResponse| If set to true, the response will be masked in the logs of the action |'false'|
|
||||
|retry| optional amount of retries if the request is failing, does not retry if the status code is ignored ||
|
||||
|retryWait| time between each retry in millseconds | 3000 |
|
||||
|
||||
@@ -99,4 +100,4 @@ Optionen:
|
||||
--bearerToken bearer token without Bearer prefix, added as
|
||||
Authorization header [string]
|
||||
--timeout request timeout [number] [default: 5000]
|
||||
```
|
||||
```
|
||||
|
||||
@@ -29,7 +29,7 @@ inputs:
|
||||
description: 'Auth Password'
|
||||
required: false
|
||||
timeout:
|
||||
description: 'Request Timeout in Sec'
|
||||
description: 'Request Timeout in milliseconds'
|
||||
required: false
|
||||
default: '5000'
|
||||
bearerToken:
|
||||
@@ -59,6 +59,10 @@ inputs:
|
||||
responseFile:
|
||||
description: 'Persist the response data to the specified file path'
|
||||
required: false
|
||||
maskResponse:
|
||||
description: 'Allows to mark your response as secret and hide the output in the action logs'
|
||||
required: false
|
||||
default: 'false'
|
||||
retry:
|
||||
description: 'optional amount of retries if the request fails'
|
||||
required: false
|
||||
@@ -71,5 +75,5 @@ outputs:
|
||||
headers:
|
||||
description: 'HTTP Response Headers'
|
||||
runs:
|
||||
using: 'node16'
|
||||
using: 'node20'
|
||||
main: 'dist/index.js'
|
||||
|
||||
1516
dist/index.js
vendored
1516
dist/index.js
vendored
File diff suppressed because it is too large
Load Diff
24
package-lock.json
generated
24
package-lock.json
generated
@@ -1,12 +1,12 @@
|
||||
{
|
||||
"name": "http-request-action",
|
||||
"version": "1.14.1",
|
||||
"version": "1.14.2",
|
||||
"lockfileVersion": 3,
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "http-request-action",
|
||||
"version": "1.14.1",
|
||||
"version": "1.14.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
"@actions/core": "^1.10.1"
|
||||
@@ -87,12 +87,12 @@
|
||||
"dev": true
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "1.6.2",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.2.tgz",
|
||||
"integrity": "sha512-7i24Ri4pmDRfJTR7LDBhsOTtcm+9kjX5WiY1X3wIisx6G9So3pfMkEiU7emUBe46oceVImccTEM3k6C5dbVW8A==",
|
||||
"version": "1.6.8",
|
||||
"resolved": "https://registry.npmjs.org/axios/-/axios-1.6.8.tgz",
|
||||
"integrity": "sha512-v/ZHtJDU39mDpyBoFVkETcd/uNdxrWRrg3bKpOKzXFA6Bvqopts6ALSMU3y6ijYxbw2B+wPrIv46egTzJXCLGQ==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"follow-redirects": "^1.15.0",
|
||||
"follow-redirects": "^1.15.6",
|
||||
"form-data": "^4.0.0",
|
||||
"proxy-from-env": "^1.1.0"
|
||||
}
|
||||
@@ -166,9 +166,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.15.3",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.3.tgz",
|
||||
"integrity": "sha512-1VzOtuEM8pC9SFU1E+8KfTjZyMztRsgEfwQl44z8A25uy13jSzTj6dyK2Df52iV0vgHCfBwLhDWevLn95w5v6Q==",
|
||||
"version": "1.15.6",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.6.tgz",
|
||||
"integrity": "sha512-wWN62YITEaOpSK584EZXJafH1AGpO8RVgElfkuXbTOrPX4fIfOyEpW/CsiNd8JdYrAoOvafRTOEnvsO++qCqFA==",
|
||||
"dev": true,
|
||||
"funding": [
|
||||
{
|
||||
@@ -288,9 +288,9 @@
|
||||
}
|
||||
},
|
||||
"node_modules/undici": {
|
||||
"version": "5.27.2",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.27.2.tgz",
|
||||
"integrity": "sha512-iS857PdOEy/y3wlM3yRp+6SNQQ6xU0mmZcwRSriqk+et/cwWAtwmIGf6WkoDN2EK/AMdCO/dfXzIwi+rFMrjjQ==",
|
||||
"version": "5.28.4",
|
||||
"resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz",
|
||||
"integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==",
|
||||
"dependencies": {
|
||||
"@fastify/busboy": "^2.0.0"
|
||||
},
|
||||
|
||||
@@ -19,6 +19,10 @@ class GithubActions {
|
||||
core.setOutput(name, output)
|
||||
}
|
||||
|
||||
setSecret(value) {
|
||||
core.setSecret(value)
|
||||
}
|
||||
|
||||
setFailed(message) {
|
||||
core.setFailed(message)
|
||||
}
|
||||
|
||||
15
src/handler/mask.js
Normal file
15
src/handler/mask.js
Normal file
@@ -0,0 +1,15 @@
|
||||
'use strict'
|
||||
|
||||
const axios = require('axios');
|
||||
const { GithubActions } = require('../githubActions');
|
||||
|
||||
/**
|
||||
* @param {GithubActions} actions
|
||||
*
|
||||
* @returns {(response: axios.AxiosResponse) => void}
|
||||
*/
|
||||
const createMaskHandler = (actions) => (response) => {
|
||||
actions.setSecret(JSON.stringify(response.data))
|
||||
}
|
||||
|
||||
module.exports = { createMaskHandler }
|
||||
16
src/handler/output.js
Normal file
16
src/handler/output.js
Normal file
@@ -0,0 +1,16 @@
|
||||
'use strict'
|
||||
|
||||
const axios = require('axios');
|
||||
const { GithubActions } = require('../githubActions');
|
||||
|
||||
/**
|
||||
* @param {GithubActions} actions
|
||||
*
|
||||
* @returns {(response: axios.AxiosResponse) => void}
|
||||
*/
|
||||
const createOutputHandler = (actions) => (response) => {
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
actions.setOutput('headers', response.headers)
|
||||
}
|
||||
|
||||
module.exports = { createOutputHandler }
|
||||
@@ -55,7 +55,7 @@ const retry = async (callback, options) => {
|
||||
lastErr = err;
|
||||
}
|
||||
|
||||
if (i < options.retries) {
|
||||
if (i < options.retry) {
|
||||
options.actions.warning(`#${i + 1} request failed: ${err}`);
|
||||
await sleep(options.sleep);
|
||||
}
|
||||
|
||||
@@ -94,10 +94,10 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
} catch(error) {
|
||||
if (error.response && options.ignoredCodes.includes(error.response.status)) {
|
||||
actions.warning(`ignored status code: ${JSON.stringify({ code: error.response.status, message: error.response.data })}`)
|
||||
|
||||
return null
|
||||
|
||||
return error.response
|
||||
}
|
||||
|
||||
|
||||
if (!error.response && error.request && options.preventFailureOnNoResponse) {
|
||||
actions.warning(`no response received: ${JSON.stringify(error)}`);
|
||||
|
||||
@@ -119,9 +119,6 @@ const request = async({ method, instanceConfig, data, files, file, actions, opti
|
||||
return null
|
||||
}
|
||||
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
actions.setOutput('headers', response.headers)
|
||||
|
||||
return response
|
||||
} catch (error) {
|
||||
if ((typeof error === 'object') && (error.isAxiosError === true)) {
|
||||
|
||||
14
src/index.js
14
src/index.js
@@ -5,7 +5,10 @@ const axios = require('axios');
|
||||
const https = require('https');
|
||||
const { request, METHOD_POST } = require('./httpClient');
|
||||
const { GithubActions } = require('./githubActions');
|
||||
|
||||
const { createPersistHandler } = require('./handler/persist');
|
||||
const { createOutputHandler } = require('./handler/output');
|
||||
const { createMaskHandler } = require('./handler/mask');
|
||||
|
||||
let customHeaders = {}
|
||||
|
||||
@@ -73,9 +76,16 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
|
||||
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
|
||||
}
|
||||
|
||||
const handler = [];
|
||||
const actions = new GithubActions();
|
||||
|
||||
const handler = [];
|
||||
|
||||
if (core.getBooleanInput('maskResponse')) {
|
||||
handler.push(createMaskHandler(actions))
|
||||
}
|
||||
|
||||
handler.push(createOutputHandler(actions))
|
||||
|
||||
if (!!responseFile) {
|
||||
handler.push(createPersistHandler(responseFile, actions))
|
||||
}
|
||||
@@ -89,7 +99,7 @@ const options = {
|
||||
}
|
||||
|
||||
request({ data, method, instanceConfig, files, file, actions, options }).then(response => {
|
||||
if (typeof response == 'object') {
|
||||
if (response && typeof response == 'object') {
|
||||
handler.forEach(h => h(response))
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user