mirror of
https://github.com/fjogeleit/http-request-action.git
synced 2026-02-05 00:55:52 +08:00
Compare commits
25 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
b63e908234 | ||
|
|
60ab747148 | ||
|
|
2ac119cf97 | ||
|
|
ff8539eb83 | ||
|
|
f90afba39a | ||
|
|
82c8e38c69 | ||
|
|
4e4ff2b320 | ||
|
|
348745cc31 | ||
|
|
d3ea5fce44 | ||
|
|
5d7e3ef283 | ||
|
|
089a11111a | ||
|
|
f7cd714b2c | ||
|
|
acd894b2e1 | ||
|
|
8ed097ea3f | ||
|
|
b9373e0ef3 | ||
|
|
65d4ab42a4 | ||
|
|
193a7dd98c | ||
|
|
3b9f5efa1c | ||
|
|
cfc342658b | ||
|
|
bd6ff9fa68 | ||
|
|
748170326f | ||
|
|
b52a6b1b8b | ||
|
|
8f0ce9cdaf | ||
|
|
88637cb5c4 | ||
|
|
0170dcbc31 |
32
.github/workflows/test.yml
vendored
Normal file
32
.github/workflows/test.yml
vendored
Normal file
@@ -0,0 +1,32 @@
|
||||
name: Test
|
||||
|
||||
on: [push, pull_request]
|
||||
|
||||
jobs:
|
||||
request:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
with:
|
||||
ref: ${{ github.ref }}
|
||||
|
||||
- name: Request Postment Echo GET
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/get'
|
||||
method: 'GET'
|
||||
|
||||
- name: Request Postment Echo POST
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/post'
|
||||
method: 'POST'
|
||||
data: '{ "key": "value" }'
|
||||
|
||||
- name: Request Postment Echo BasicAuth
|
||||
uses: ./
|
||||
with:
|
||||
url: 'https://postman-echo.com/basic-auth'
|
||||
method: 'GET'
|
||||
username: 'postman'
|
||||
password: 'password'
|
||||
12
README.md
12
README.md
@@ -2,7 +2,7 @@
|
||||
|
||||
Create any kind of HTTP Requests in your GitHub actions to trigger Tools like Ansible AWX
|
||||
|
||||
Exmaple Usage:
|
||||
Example Usage:
|
||||
```
|
||||
jobs:
|
||||
deployment
|
||||
@@ -27,7 +27,17 @@ jobs:
|
||||
|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 |'{}'|
|
||||
|preventFailureOnNoResponse| Prevent this Action to fail if the request respond without an response. Use 'true' (string) as value to enable it ||
|
||||
|
||||
### Output
|
||||
|
||||
- `response` Request Response as JSON String
|
||||
|
||||
|
||||
### Debug Informations
|
||||
|
||||
Enable Debug mode to get informations about
|
||||
|
||||
- Instance Configuration (Url / Timeout / Headers)
|
||||
- Request Data (Body / Auth / Method)
|
||||
|
||||
@@ -29,6 +29,9 @@ inputs:
|
||||
bearerToken:
|
||||
description: 'Bearer Authentication Token'
|
||||
required: false
|
||||
preventFailureOnNoResponse:
|
||||
description: 'Prevent this Action to fail if the request respond without an response'
|
||||
required: false
|
||||
outputs:
|
||||
response:
|
||||
description: 'HTTP Response Content'
|
||||
|
||||
150
dist/index.js
vendored
150
dist/index.js
vendored
@@ -1197,6 +1197,52 @@ module.exports = function xhrAdapter(config) {
|
||||
};
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 230:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
const core = __webpack_require__(470);
|
||||
|
||||
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 }
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 283:
|
||||
@@ -1318,6 +1364,57 @@ module.exports = axios;
|
||||
module.exports.default = axios;
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 354:
|
||||
/***/ (function(module, __unusedexports, __webpack_require__) {
|
||||
|
||||
const axios = __webpack_require__(53);
|
||||
|
||||
const METHOD_GET = 'GET'
|
||||
const METHOD_POST = 'POST'
|
||||
|
||||
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse }) => {
|
||||
try {
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
const jsonData = method === METHOD_GET ? undefined : JSON.parse(data)
|
||||
|
||||
const requestData = {
|
||||
auth,
|
||||
method,
|
||||
data: jsonData
|
||||
}
|
||||
|
||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||
|
||||
const response = await instance.request(requestData)
|
||||
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
} catch (error) {
|
||||
if (error.toJSON) {
|
||||
actions.setOutput(JSON.stringify(error.toJSON()));
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
actions.setFailed(JSON.stringify({ code: error.response.code, 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(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
request,
|
||||
METHOD_POST,
|
||||
METHOD_GET,
|
||||
}
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
/***/ 357:
|
||||
@@ -1330,7 +1427,7 @@ module.exports = require("assert");
|
||||
/***/ 361:
|
||||
/***/ (function(module) {
|
||||
|
||||
module.exports = {"_from":"axios","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"tag","registry":true,"raw":"axios","name":"axios","escapedName":"axios","rawSpec":"","saveSpec":null,"fetchSpec":"latest"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_shasum":"3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27","_spec":"axios","_where":"/Users/f.jogeleit/Workspace/Other/http-request-action","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundleDependencies":false,"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"1.5.10"},"deprecated":false,"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"homepage":"https://github.com/axios/axios","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test && bundlesize","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","version":"0.19.2"};
|
||||
module.exports = {"_args":[["axios@0.19.2","/Users/frankjogeleit/Workspace/http-request-action"]],"_from":"axios@0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"version","registry":true,"raw":"axios@0.19.2","name":"axios","escapedName":"axios","rawSpec":"0.19.2","saveSpec":null,"fetchSpec":"0.19.2"},"_requiredBy":["/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_spec":"0.19.2","_where":"/Users/frankjogeleit/Workspace/http-request-action","author":{"name":"Matt Zabriskie"},"browser":{"./lib/adapters/http.js":"./lib/adapters/xhr.js"},"bugs":{"url":"https://github.com/axios/axios/issues"},"bundlesize":[{"path":"./dist/axios.min.js","threshold":"5kB"}],"dependencies":{"follow-redirects":"1.5.10"},"description":"Promise based HTTP client for the browser and node.js","devDependencies":{"bundlesize":"^0.17.0","coveralls":"^3.0.0","es6-promise":"^4.2.4","grunt":"^1.0.2","grunt-banner":"^0.6.0","grunt-cli":"^1.2.0","grunt-contrib-clean":"^1.1.0","grunt-contrib-watch":"^1.0.0","grunt-eslint":"^20.1.0","grunt-karma":"^2.0.0","grunt-mocha-test":"^0.13.3","grunt-ts":"^6.0.0-beta.19","grunt-webpack":"^1.0.18","istanbul-instrumenter-loader":"^1.0.0","jasmine-core":"^2.4.1","karma":"^1.3.0","karma-chrome-launcher":"^2.2.0","karma-coverage":"^1.1.1","karma-firefox-launcher":"^1.1.0","karma-jasmine":"^1.1.1","karma-jasmine-ajax":"^0.1.13","karma-opera-launcher":"^1.0.0","karma-safari-launcher":"^1.0.0","karma-sauce-launcher":"^1.2.0","karma-sinon":"^1.0.5","karma-sourcemap-loader":"^0.3.7","karma-webpack":"^1.7.0","load-grunt-tasks":"^3.5.2","minimist":"^1.2.0","mocha":"^5.2.0","sinon":"^4.5.0","typescript":"^2.8.1","url-search-params":"^0.10.0","webpack":"^1.13.1","webpack-dev-server":"^1.14.1"},"homepage":"https://github.com/axios/axios","keywords":["xhr","http","ajax","promise","node"],"license":"MIT","main":"index.js","name":"axios","repository":{"type":"git","url":"git+https://github.com/axios/axios.git"},"scripts":{"build":"NODE_ENV=production grunt build","coveralls":"cat coverage/lcov.info | ./node_modules/coveralls/bin/coveralls.js","examples":"node ./examples/server.js","fix":"eslint --fix lib/**/*.js","postversion":"git push && git push --tags","preversion":"npm test","start":"node ./sandbox/server.js","test":"grunt test && bundlesize","version":"npm run build && grunt version && git add -A dist && git add CHANGELOG.md bower.json package.json"},"typings":"./index.d.ts","version":"0.19.2"};
|
||||
|
||||
/***/ }),
|
||||
|
||||
@@ -2595,43 +2692,48 @@ module.exports = function httpAdapter(config) {
|
||||
/***/ (function(__unusedmodule, __unusedexports, __webpack_require__) {
|
||||
|
||||
const core = __webpack_require__(470);
|
||||
const axios = __webpack_require__(53);
|
||||
const { request, METHOD_POST } = __webpack_require__(354);
|
||||
const { GithubActions } = __webpack_require__(230);
|
||||
|
||||
const auth = {}
|
||||
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
||||
let auth = undefined
|
||||
let customHeaders = {}
|
||||
|
||||
if (!!core.getInput('username')) {
|
||||
auth.username = core.getInput('username');
|
||||
if (!!core.getInput('customHeaders')) {
|
||||
try {
|
||||
customHeaders = JSON.parse(core.getInput('customHeaders'));
|
||||
} catch(error) {
|
||||
core.error('Could not parse customHeaders string value')
|
||||
}
|
||||
}
|
||||
|
||||
if (!!core.getInput('password')) {
|
||||
auth.password = core.getInput('password');
|
||||
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['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||
}
|
||||
|
||||
const instance = axios.create({
|
||||
const instanceConfig = {
|
||||
baseURL: core.getInput('url', { required: true }),
|
||||
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||
headers
|
||||
});
|
||||
headers: { ...headers, ...customHeaders }
|
||||
}
|
||||
|
||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
(async() => {
|
||||
try {
|
||||
const response = await instance.request({
|
||||
auth,
|
||||
method: core.getInput('method') || 'POST',
|
||||
data: JSON.parse(core.getInput('data') || '{}')
|
||||
})
|
||||
const data = core.getInput('data') || '{}';
|
||||
const method = core.getInput('method') || METHOD_POST;
|
||||
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
|
||||
|
||||
core.setOutput('response', JSON.stringify(response.data))
|
||||
} catch (error) {
|
||||
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
|
||||
}
|
||||
})()
|
||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, actions: new GithubActions() })
|
||||
|
||||
|
||||
/***/ }),
|
||||
|
||||
2
package-lock.json
generated
2
package-lock.json
generated
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "http-request-action",
|
||||
"version": "1.0.0",
|
||||
"version": "1.4.0",
|
||||
"lockfileVersion": 1,
|
||||
"requires": true,
|
||||
"dependencies": {
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "http-request-action",
|
||||
"version": "1.0.0",
|
||||
"version": "1.4.0",
|
||||
"description": "",
|
||||
"main": "src/index.js",
|
||||
"private": false,
|
||||
|
||||
39
src/githubActions.js
Normal file
39
src/githubActions.js
Normal 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 }
|
||||
44
src/httpClient.js
Normal file
44
src/httpClient.js
Normal file
@@ -0,0 +1,44 @@
|
||||
const axios = require("axios");
|
||||
|
||||
const METHOD_GET = 'GET'
|
||||
const METHOD_POST = 'POST'
|
||||
|
||||
const request = async({ method, instanceConfig, data, auth, actions, preventFailureOnNoResponse }) => {
|
||||
try {
|
||||
const instance = axios.create(instanceConfig);
|
||||
|
||||
const jsonData = method === METHOD_GET ? undefined : JSON.parse(data)
|
||||
|
||||
const requestData = {
|
||||
auth,
|
||||
method,
|
||||
data: jsonData
|
||||
}
|
||||
|
||||
actions.debug('Request Data: ' + JSON.stringify(requestData))
|
||||
|
||||
const response = await instance.request(requestData)
|
||||
|
||||
actions.setOutput('response', JSON.stringify(response.data))
|
||||
} catch (error) {
|
||||
if (error.toJSON) {
|
||||
actions.setOutput(JSON.stringify(error.toJSON()));
|
||||
}
|
||||
|
||||
if (error.response) {
|
||||
actions.setFailed(JSON.stringify({ code: error.response.code, 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(error.message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
request,
|
||||
METHOD_POST,
|
||||
METHOD_GET,
|
||||
}
|
||||
51
src/index.js
51
src/index.js
@@ -1,38 +1,43 @@
|
||||
const core = require("@actions/core");
|
||||
const axios = require("axios");
|
||||
const { request, METHOD_POST } = require('./httpClient');
|
||||
const { GithubActions } = require('./githubActions');
|
||||
|
||||
const auth = {}
|
||||
const headers = { 'Content-Type': core.getInput('contentType') || 'application/json' }
|
||||
let auth = undefined
|
||||
let customHeaders = {}
|
||||
|
||||
if (!!core.getInput('username')) {
|
||||
auth.username = core.getInput('username');
|
||||
if (!!core.getInput('customHeaders')) {
|
||||
try {
|
||||
customHeaders = JSON.parse(core.getInput('customHeaders'));
|
||||
} catch(error) {
|
||||
core.error('Could not parse customHeaders string value')
|
||||
}
|
||||
}
|
||||
|
||||
if (!!core.getInput('password')) {
|
||||
auth.password = core.getInput('password');
|
||||
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['Authentication'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||
headers['Authorization'] = `Bearer ${core.getInput('bearerToken')}`;
|
||||
}
|
||||
|
||||
const instance = axios.create({
|
||||
const instanceConfig = {
|
||||
baseURL: core.getInput('url', { required: true }),
|
||||
timeout: parseInt(core.getInput('timeout') || 5000, 10),
|
||||
headers
|
||||
});
|
||||
headers: { ...headers, ...customHeaders }
|
||||
}
|
||||
|
||||
core.debug('Instance Configuration: ' + JSON.stringify(instanceConfig))
|
||||
|
||||
(async() => {
|
||||
try {
|
||||
const response = await instance.request({
|
||||
auth,
|
||||
method: core.getInput('method') || 'POST',
|
||||
data: JSON.parse(core.getInput('data') || '{}')
|
||||
})
|
||||
const data = core.getInput('data') || '{}';
|
||||
const method = core.getInput('method') || METHOD_POST;
|
||||
const preventFailureOnNoResponse = core.getInput('preventFailureOnNoResponse') === 'true';
|
||||
|
||||
core.setOutput('response', JSON.stringify(response.data))
|
||||
} catch (error) {
|
||||
core.setFailed(JSON.stringify({ code: error.response.code, message: error.response.data }))
|
||||
}
|
||||
})()
|
||||
request({ data, method, instanceConfig, auth, preventFailureOnNoResponse, actions: new GithubActions() })
|
||||
|
||||
Reference in New Issue
Block a user