mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-04 16:45:52 +08:00
Compare commits
10 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
52ba495021 | ||
|
|
df00cdf429 | ||
|
|
e3313c1a5f | ||
|
|
d4c0bee13c | ||
|
|
435fe1dbc8 | ||
|
|
35336be18d | ||
|
|
f986377e36 | ||
|
|
046e838b3a | ||
|
|
31fad16908 | ||
|
|
5c4179dc69 |
16
README.md
16
README.md
@@ -9,14 +9,20 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- name: Deploy Stage
|
||||
uses: fjogeleit/http-request-action@master
|
||||
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"}'
|
||||
```
|
||||
|
||||
### 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 |
|
||||
@@ -42,17 +48,19 @@ jobs:
|
||||
|---|---|
|
||||
`response` | Response as JSON String
|
||||
|
||||
To display HTTP response data in the GitHub Actions log give the request an `id` and access its `outputs`
|
||||
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.
|
||||
|
||||
```yaml
|
||||
steps:
|
||||
- name: Make Request
|
||||
id: myRequest
|
||||
uses: fjogeleit/http-request-action@master
|
||||
uses: fjogeleit/http-request-action@v1
|
||||
with:
|
||||
url: "http://yoursite.com/api"
|
||||
- name: Show Response
|
||||
run: echo ${{ steps.myRequest.outputs.response }}
|
||||
run: |
|
||||
echo ${{ steps.myRequest.outputs.response }}
|
||||
echo ${{ fromJson(steps.myRequest.outputs.response).field_you_want_to_access }}
|
||||
```
|
||||
|
||||
### Additional Information
|
||||
|
||||
@@ -47,6 +47,9 @@ inputs:
|
||||
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'
|
||||
|
||||
2078
dist/index.js
vendored
2078
dist/index.js
vendored
File diff suppressed because one or more lines are too long
81
package-lock.json
generated
81
package-lock.json
generated
@@ -5,6 +5,7 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "http-request-action",
|
||||
"version": "1.9.0",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
@@ -17,21 +18,21 @@
|
||||
}
|
||||
},
|
||||
"node_modules/@actions/core": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
|
||||
"integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.0.tgz",
|
||||
"integrity": "sha512-5pbM693Ih59ZdUhgk+fts+bUWTnIdHV3kwOSr+QIoFHMLg7Gzhwm0cifDY/AG68ekEJAkHnQVpcy4f6GjmzBCA==",
|
||||
"dev": true,
|
||||
"dependencies": {
|
||||
"@actions/http-client": "^1.0.11"
|
||||
"@actions/http-client": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"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==",
|
||||
"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"
|
||||
"tunnel": "^0.0.6"
|
||||
}
|
||||
},
|
||||
"node_modules/@zeit/ncc": {
|
||||
@@ -46,7 +47,7 @@
|
||||
"node_modules/asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"node_modules/axios": {
|
||||
"version": "0.21.4",
|
||||
@@ -70,15 +71,15 @@
|
||||
"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=",
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ==",
|
||||
"engines": {
|
||||
"node": ">=0.4.0"
|
||||
}
|
||||
},
|
||||
"node_modules/follow-redirects": {
|
||||
"version": "1.14.7",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
|
||||
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ==",
|
||||
"version": "1.15.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
|
||||
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA==",
|
||||
"funding": [
|
||||
{
|
||||
"type": "individual",
|
||||
@@ -108,19 +109,19 @@
|
||||
}
|
||||
},
|
||||
"node_modules/mime-db": {
|
||||
"version": "1.51.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz",
|
||||
"integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g==",
|
||||
"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.34",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz",
|
||||
"integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==",
|
||||
"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.51.0"
|
||||
"mime-db": "1.52.0"
|
||||
},
|
||||
"engines": {
|
||||
"node": ">= 0.6"
|
||||
@@ -138,21 +139,21 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/core": {
|
||||
"version": "1.6.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.6.0.tgz",
|
||||
"integrity": "sha512-NB1UAZomZlCV/LmJqkLhNTqtKfFXJZAUPcfl/zqG7EfsQdeUJtaWO98SGbuQ3pydJ3fHl2CvI/51OKYlCYYcaw==",
|
||||
"version": "1.9.0",
|
||||
"resolved": "https://registry.npmjs.org/@actions/core/-/core-1.9.0.tgz",
|
||||
"integrity": "sha512-5pbM693Ih59ZdUhgk+fts+bUWTnIdHV3kwOSr+QIoFHMLg7Gzhwm0cifDY/AG68ekEJAkHnQVpcy4f6GjmzBCA==",
|
||||
"dev": true,
|
||||
"requires": {
|
||||
"@actions/http-client": "^1.0.11"
|
||||
"@actions/http-client": "^2.0.1"
|
||||
}
|
||||
},
|
||||
"@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==",
|
||||
"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"
|
||||
"tunnel": "^0.0.6"
|
||||
}
|
||||
},
|
||||
"@zeit/ncc": {
|
||||
@@ -163,7 +164,7 @@
|
||||
"asynckit": {
|
||||
"version": "0.4.0",
|
||||
"resolved": "https://registry.npmjs.org/asynckit/-/asynckit-0.4.0.tgz",
|
||||
"integrity": "sha1-x57Zf380y48robyXkLzDZkdLS3k="
|
||||
"integrity": "sha512-Oei9OH4tRh0YqU3GxhX79dM/mwVgvbZJaSNaRk+bshkj0S5cfHcgYakreBjrHwatXKbz+IoIdYLxrKim2MjW0Q=="
|
||||
},
|
||||
"axios": {
|
||||
"version": "0.21.4",
|
||||
@@ -184,12 +185,12 @@
|
||||
"delayed-stream": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/delayed-stream/-/delayed-stream-1.0.0.tgz",
|
||||
"integrity": "sha1-3zrhmayt+31ECqrgsp4icrJOxhk="
|
||||
"integrity": "sha512-ZySD7Nf91aLB0RxL4KGrKHBXl7Eds1DAmEdcoVawXnLD7SDhpNgtuII2aAkg7a7QS41jxPSZ17p4VdGnMHk3MQ=="
|
||||
},
|
||||
"follow-redirects": {
|
||||
"version": "1.14.7",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.14.7.tgz",
|
||||
"integrity": "sha512-+hbxoLbFMbRKDwohX8GkTataGqO6Jb7jGwpAlwgy2bIz25XtRm7KEzJM76R1WiNT5SwZkX4Y75SwBolkpmE7iQ=="
|
||||
"version": "1.15.1",
|
||||
"resolved": "https://registry.npmjs.org/follow-redirects/-/follow-redirects-1.15.1.tgz",
|
||||
"integrity": "sha512-yLAMQs+k0b2m7cVxpS1VKJVvoz7SS9Td1zss3XRwXj+ZDH00RJgnuLx7E44wx02kQLrdM3aOOy+FpzS7+8OizA=="
|
||||
},
|
||||
"form-data": {
|
||||
"version": "4.0.0",
|
||||
@@ -202,16 +203,16 @@
|
||||
}
|
||||
},
|
||||
"mime-db": {
|
||||
"version": "1.51.0",
|
||||
"resolved": "https://registry.npmjs.org/mime-db/-/mime-db-1.51.0.tgz",
|
||||
"integrity": "sha512-5y8A56jg7XVQx2mbv1lu49NR4dokRnhZYTtL+KGfaa27uq4pSTXkwQkFJl4pkRMyNFz/EtYDSkiiEHx3F7UN6g=="
|
||||
"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.34",
|
||||
"resolved": "https://registry.npmjs.org/mime-types/-/mime-types-2.1.34.tgz",
|
||||
"integrity": "sha512-6cP692WwGIs9XXdOO4++N+7qjqv0rqxxVvJ3VHPh/Sc9mVZcQP+ZGhkKiTvWMQRr2tbHkJP/Yn7Y0npb3ZBs4A==",
|
||||
"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.51.0"
|
||||
"mime-db": "1.52.0"
|
||||
}
|
||||
},
|
||||
"tunnel": {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
const axios = require("axios");
|
||||
const axios = require('axios');
|
||||
const FormData = require('form-data')
|
||||
const fs = require('fs')
|
||||
|
||||
@@ -8,11 +8,10 @@ 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 {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 {{ 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
|
||||
@@ -20,7 +19,7 @@ const METHOD_POST = 'POST'
|
||||
*
|
||||
* @returns {void}
|
||||
*/
|
||||
const request = async({ method, instanceConfig, data, files, file, auth, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
|
||||
const request = async({ method, instanceConfig, data, files, file, actions, ignoredCodes, preventFailureOnNoResponse, escapeData }) => {
|
||||
try {
|
||||
if (escapeData) {
|
||||
data = data.replace(/"[^"]*"/g, (match) => {
|
||||
@@ -54,7 +53,6 @@ const request = async({ method, instanceConfig, data, files, file, auth, actions
|
||||
}
|
||||
|
||||
const requestData = {
|
||||
auth,
|
||||
method,
|
||||
data,
|
||||
maxContentLength: Infinity,
|
||||
@@ -71,8 +69,9 @@ const request = async({ method, instanceConfig, data, files, file, auth, actions
|
||||
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
} catch (error) {
|
||||
if (error.toJSON) {
|
||||
actions.setOutput('requestError', JSON.stringify(error.toJSON()));
|
||||
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)) {
|
||||
|
||||
29
src/index.js
29
src/index.js
@@ -1,4 +1,6 @@
|
||||
const core = require("@actions/core");
|
||||
const core = require('@actions/core');
|
||||
const axios = require('axios');
|
||||
const https = require('https');
|
||||
const { request, METHOD_POST } = require('./httpClient');
|
||||
const { GithubActions } = require('./githubActions');
|
||||
|
||||
@@ -15,25 +17,30 @@ 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 }
|
||||
}
|
||||
|
||||
if (!!core.getInput('httpsCA')) {
|
||||
instanceConfig.httpsAgent = new https.Agent({ ca: core.getInput('httpsCA') })
|
||||
}
|
||||
|
||||
if (!!core.getInput('username') || !!core.getInput('password')) {
|
||||
core.debug('Add BasicHTTP Auth config')
|
||||
|
||||
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')
|
||||
@@ -48,4 +55,4 @@ if (typeof ignoreStatusCodes === 'string' && ignoreStatusCodes.length > 0) {
|
||||
ignoredCodes = ignoreStatusCodes.split(',').map(statusCode => parseInt(statusCode.trim()))
|
||||
}
|
||||
|
||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, escapeData, files, file, ignoredCodes, actions: new GithubActions() })
|
||||
request({ data, method, instanceConfig, preventFailureOnNoResponse, escapeData, files, file, ignoredCodes, actions: new GithubActions() })
|
||||
|
||||
Reference in New Issue
Block a user