From b01610cfde9760085915318c127f17b016fec695 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Wed, 1 Apr 2020 21:07:30 -0400 Subject: [PATCH 01/13] started adding support for custom headers --- action.yml | 2 ++ dist/index.js | 25 +++++++++++++++---------- src/http.ts | 18 ++++++++++-------- src/main.ts | 7 ++++++- 4 files changed, 33 insertions(+), 19 deletions(-) diff --git a/action.yml b/action.yml index b35c4a9..4191515 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,8 @@ inputs: description: HTTP request payload graphql: description: GraphQL query or mutation to execute. If defined, the 'data' field is automatically populated with the this payload and the 'method' is set to POST + headers: + description: HTTP custom headers outputs: status: description: The status of the HTTP request diff --git a/dist/index.js b/dist/index.js index b1a9bb2..3401372 100644 --- a/dist/index.js +++ b/dist/index.js @@ -860,6 +860,10 @@ function run() { let method = core.getInput('method'); let data = core.getInput('data'); const graphql = core.getInput('graphql'); + let headers = core.getInput('headers'); + if (headers.length == 0) { + headers = "{'Content-Type': 'application/json'}"; + } if (graphql.length !== 0) { method = 'POST'; data = graphql_1.graphqlPayloadFor(graphql); @@ -870,7 +874,7 @@ function run() { if (data.length !== 0) { core.info(`data: ${data}`); } - const [status, rawResponse] = yield http_1.request(url, method, data); + const [status, rawResponse] = yield http_1.request(url, method, data, headers); const response = JSON.stringify(rawResponse); core.info(`response status: ${status}`); core.info(`response body:\n${response}`); @@ -1749,7 +1753,7 @@ module.exports = require("assert"); /***/ 361: /***/ (function(module) { -module.exports = {"_from":"axios@^0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.19.2","name":"axios","escapedName":"axios","rawSpec":"^0.19.2","saveSpec":null,"fetchSpec":"^0.19.2"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_shasum":"3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27","_spec":"axios@^0.19.2","_where":"/Users/camilogarcialarotta/playground/graphql-client-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","/home/titoine54/watermelon-http-client"]],"_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":"/home/titoine54/watermelon-http-client","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"}; /***/ }), @@ -2693,39 +2697,40 @@ const axios_1 = __importDefault(__webpack_require__(53)); * Send an HTTP request with JSON as content and response type. * * @param url - the endpoint to send the request to - * @param method - the HTTP method for the request. e.g `get, GET, post POST` + * @param method - the HTTP method for the request. e.g `get, GET, post, POST` * @param data - the JSON encoded payload if any + * @param headers - the JSON encoded custom headers * @returns `[status code, response body]` */ -function request(url, method, data = '{}') { +function request(url, method, data = '{}', headers) { return __awaiter(this, void 0, void 0, function* () { switch (method.toUpperCase()) { case 'POST': - return post(url, data); + return post(url, data, headers); case 'GET': - return get(url); + return get(url, headers); default: throw new Error(`unimplemented HTTP method: ${method}`); } }); } exports.request = request; -function get(url) { +function get(url, headers) { return __awaiter(this, void 0, void 0, function* () { const response = yield axios_1.default.get(url, { responseType: 'json', - headers: { 'Content-Type': 'application/json' } + headers: headers }); const status = response.status; const data = response.data; return [status, data]; }); } -function post(url, payload) { +function post(url, payload, headers) { return __awaiter(this, void 0, void 0, function* () { const response = yield axios_1.default.post(url, payload, { responseType: 'json', - headers: { 'Content-Type': 'application/json' } + headers: headers }); const status = response.status; const data = response.data; diff --git a/src/http.ts b/src/http.ts index e2eba22..e4e8fbf 100644 --- a/src/http.ts +++ b/src/http.ts @@ -4,30 +4,32 @@ import axios from 'axios' * Send an HTTP request with JSON as content and response type. * * @param url - the endpoint to send the request to - * @param method - the HTTP method for the request. e.g `get, GET, post POST` + * @param method - the HTTP method for the request. e.g `get, GET, post, POST` * @param data - the JSON encoded payload if any + * @param headers - the JSON encoded custom headers * @returns `[status code, response body]` */ export async function request( url: string, method: Method, - data = '{}' + data = '{}', + headers: string ): Promise<[number, Object]> { switch (method.toUpperCase()) { case 'POST': - return post(url, data) + return post(url, data, headers) case 'GET': - return get(url) + return get(url, headers) default: throw new Error(`unimplemented HTTP method: ${method}`) } } -async function get(url: string): Promise<[number, Object]> { +async function get(url: string, headers: string): Promise<[number, Object]> { const response = await axios.get(url, { responseType: 'json', - headers: {'Content-Type': 'application/json'} + headers: headers }) const status = response.status @@ -36,10 +38,10 @@ async function get(url: string): Promise<[number, Object]> { return [status, data] } -async function post(url: string, payload: string): Promise<[number, Object]> { +async function post(url: string, payload: string, headers: string): Promise<[number, Object]> { const response = await axios.post(url, payload, { responseType: 'json', - headers: {'Content-Type': 'application/json'} + headers: headers }) const status = response.status diff --git a/src/main.ts b/src/main.ts index d94b5aa..fe237e0 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,11 @@ export async function run(): Promise { let method: string = core.getInput('method') let data: string = core.getInput('data') const graphql: string = core.getInput('graphql') + let headers: string = core.getInput('headers') + + if (headers.length == 0) { + headers = "{'Content-Type': 'application/json'}" + } if (graphql.length !== 0) { method = 'POST' @@ -22,7 +27,7 @@ export async function run(): Promise { core.info(`data: ${data}`) } - const [status, rawResponse] = await request(url, method, data) + const [status, rawResponse] = await request(url, method, data, headers) const response = JSON.stringify(rawResponse) From 28ff34c7a46017dbb39113bc5ad455b84f79d5d7 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Wed, 1 Apr 2020 21:07:30 -0400 Subject: [PATCH 02/13] started adding support for custom headers --- action.yml | 2 ++ dist/index.js | 11 ++++++++--- src/http.ts | 3 ++- src/main.ts | 5 +++++ 4 files changed, 17 insertions(+), 4 deletions(-) diff --git a/action.yml b/action.yml index 56ba346..56838dc 100644 --- a/action.yml +++ b/action.yml @@ -12,6 +12,8 @@ inputs: description: HTTP request payload graphql: description: GraphQL query or mutation to execute. If defined, the 'data' field is automatically populated with the this payload and the 'method' is set to POST + headers: + description: HTTP custom headers outputs: status: description: The status of the HTTP request diff --git a/dist/index.js b/dist/index.js index acfa6bd..0d9c434 100644 --- a/dist/index.js +++ b/dist/index.js @@ -860,6 +860,10 @@ function run() { let method = core.getInput('method'); let data = core.getInput('data'); const graphql = core.getInput('graphql'); + let headers = core.getInput('headers'); + if (headers.length == 0) { + headers = "{'Content-Type': 'application/json'}"; + } if (graphql.length !== 0) { method = 'POST'; data = graphql_1.graphqlPayloadFor(graphql); @@ -1757,7 +1761,7 @@ module.exports = require("assert"); /***/ 361: /***/ (function(module) { -module.exports = {"_from":"axios@^0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.19.2","name":"axios","escapedName":"axios","rawSpec":"^0.19.2","saveSpec":null,"fetchSpec":"^0.19.2"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_shasum":"3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27","_spec":"axios@^0.19.2","_where":"/Users/camilogarcialarotta/playground/graphql-client-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","/home/titoine54/watermelon-http-client"]],"_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":"/home/titoine54/watermelon-http-client","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"}; /***/ }), @@ -2701,11 +2705,12 @@ const axios_1 = __importDefault(__webpack_require__(53)); * Send an HTTP request with JSON as content and response type. * * @param url - the endpoint to send the request to - * @param method - the HTTP method for the request. e.g `get, GET, post POST` + * @param method - the HTTP method for the request. e.g `get, GET, post, POST` * @param data - the JSON encoded payload if any + * @param headers - the JSON encoded custom headers * @returns `[status code, response body]` */ -function request(url, method, data = '{}') { +function request(url, method, data = '{}', headers) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios_1.default.request({ diff --git a/src/http.ts b/src/http.ts index ac00414..b996f3e 100644 --- a/src/http.ts +++ b/src/http.ts @@ -4,8 +4,9 @@ import axios from 'axios' * Send an HTTP request with JSON as content and response type. * * @param url - the endpoint to send the request to - * @param method - the HTTP method for the request. e.g `get, GET, post POST` + * @param method - the HTTP method for the request. e.g `get, GET, post, POST` * @param data - the JSON encoded payload if any + * @param headers - the JSON encoded custom headers * @returns `[status code, response body]` */ export async function request( diff --git a/src/main.ts b/src/main.ts index ab0f858..646767f 100644 --- a/src/main.ts +++ b/src/main.ts @@ -8,6 +8,11 @@ export async function run(): Promise { let method: string = core.getInput('method') let data: string = core.getInput('data') const graphql: string = core.getInput('graphql') + let headers: string = core.getInput('headers') + + if (headers.length == 0) { + headers = "{'Content-Type': 'application/json'}" + } if (graphql.length !== 0) { method = 'POST' From 78deb9a3f8ff89b6189b20a6b323899ee7d02966 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Thu, 2 Apr 2020 00:43:36 -0400 Subject: [PATCH 03/13] feat : start to add custom headers support --- __tests__/main.test.ts | 2 +- dist/index.js | 98 ++++++++++++++++++------------------------ src/http.ts | 90 +++++++++++++------------------------- src/main.ts | 22 +++++----- 4 files changed, 82 insertions(+), 130 deletions(-) diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index e750ca4..53cfac2 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -35,7 +35,7 @@ describe('when running the action with valid inputs', () => { ['method: POST'], ['data: { a: "payload" }'], ['response status: 200'], - ['response headers: "headers"'], + ['response headers: '], ['response body:\n{"some":"JSON"}'] ]) diff --git a/dist/index.js b/dist/index.js index fada3b6..760949e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -861,12 +861,12 @@ function run() { let data = core.getInput('data'); const graphql = core.getInput('graphql'); let headers = core.getInput('headers'); - if (headers.length == 0) { - headers = "{'Content-Type': 'application/json'}"; - } if (graphql.length !== 0) { method = 'POST'; data = graphql_1.graphqlPayloadFor(graphql); + if (headers.length == 0) { + headers = '{\'Content-Type\': \'application/graphql\'}'; + } core.info(`graphql:\n${graphql}`); } core.info(`url: ${url}`); @@ -874,12 +874,8 @@ function run() { if (data.length !== 0) { core.info(`data: ${data}`); } -<<<<<<< HEAD - const [status, rawHeaders, rawResponse] = yield http_1.request(url, method, data); - const headers = JSON.stringify(rawHeaders); -======= - const [status, rawResponse] = yield http_1.request(url, method, data, headers); ->>>>>>> b01610cfde9760085915318c127f17b016fec695 + const [status, rawHeaders, rawResponse] = yield http_1.request(url, method, data, headers); + const responseHeaders = JSON.stringify(rawHeaders); const response = JSON.stringify(rawResponse); if (status < 200 || status >= 300) { core.error(`response status: ${status}`); @@ -891,7 +887,7 @@ function run() { core.info(`response headers: ${headers}`); core.info(`response body:\n${response}`); core.setOutput('status', `${status}`); - core.setOutput('headers', `${headers}`); + core.setOutput('headers', `${responseHeaders}`); core.setOutput('response', `${response}`); } catch (error) { @@ -2714,73 +2710,61 @@ const axios_1 = __importDefault(__webpack_require__(53)); * @param headers - the JSON encoded custom headers * @returns `[status code, response body]` */ -function request(url, method, data = '{}', headers) { +function request(url, method, //using Method from axios +data = '{}', headers = '{\'Content-Type\': \'application/json\'}') { return __awaiter(this, void 0, void 0, function* () { -<<<<<<< HEAD try { const response = yield axios_1.default.request({ url, method, data, - headers: { 'Content-Type': 'application/json' } + headers }); const status = response.status; - const headers = response.headers; + const responseHeaders = response.headers; const payload = response.data; - return [status, headers, payload]; + return [status, responseHeaders, payload]; } catch (error) { if (error.response) { // The request was made and the server responded with a status code const status = error.response.status; - const headers = error.response.headers; + const responseHeaders = error.response.headers; const payload = error.response.data; - return [status, headers, payload]; + return [status, responseHeaders, payload]; + } + else { + // Something happened in setting up the request that triggered an error + return [ + 500, + '', + `request could not be generated: ${error.message}` + ]; } - // Something happened in setting up the request that triggered an error - return [ - 500, - '', - `request could not be generated: ${JSON.stringify(error.message)}` - ]; -======= - switch (method.toUpperCase()) { - case 'POST': - return post(url, data, headers); - case 'GET': - return get(url, headers); - default: - throw new Error(`unimplemented HTTP method: ${method}`); ->>>>>>> b01610cfde9760085915318c127f17b016fec695 } }); } exports.request = request; -<<<<<<< HEAD -======= -function get(url, headers) { - return __awaiter(this, void 0, void 0, function* () { - const response = yield axios_1.default.get(url, { - responseType: 'json', - headers: headers - }); - const status = response.status; - const data = response.data; - return [status, data]; - }); -} -function post(url, payload, headers) { - return __awaiter(this, void 0, void 0, function* () { - const response = yield axios_1.default.post(url, payload, { - responseType: 'json', - headers: headers - }); - const status = response.status; - const data = response.data; - return [status, data]; - }); -} ->>>>>>> b01610cfde9760085915318c127f17b016fec695 +// why not use Method from axios.AxiosRequestConfig ? +// export type Method = +// | 'get' +// | 'GET' +// | 'delete' +// | 'DELETE' +// | 'head' +// | 'HEAD' +// | 'options' +// | 'OPTIONS' +// | 'post' +// | 'POST' +// | 'put' +// | 'PUT' +// | 'patch' +// | 'PATCH' +// | 'link' +// | 'LINK' +// | 'unlink' +// | 'UNLINK' /***/ }), diff --git a/src/http.ts b/src/http.ts index caec2c8..faafe7f 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,4 +1,4 @@ -import axios from 'axios' +import axios, { Method } from 'axios' /** * Send an HTTP request with JSON as content and response type. @@ -11,52 +11,33 @@ import axios from 'axios' */ export async function request( url: string, - method: Method, -<<<<<<< HEAD - data = '{}' + method: Method, //using Method from axios + data = '{}', + headers = '{\'Content-Type\': \'application/json\'}' ): Promise<[number, Object, Object]> { try { const response = await axios.request({ url, method, data, - headers: {'Content-Type': 'application/json'} + headers }) -======= - data = '{}', - headers: string -): Promise<[number, Object]> { - switch (method.toUpperCase()) { - case 'POST': - return post(url, data, headers) - case 'GET': - return get(url, headers) ->>>>>>> b01610cfde9760085915318c127f17b016fec695 const status = response.status - const headers = response.headers - const payload = response.data as Object + const responseHeaders = response.headers + const payload = response.data -<<<<<<< HEAD - return [status, headers, payload] + return [status, responseHeaders, payload] } catch (error) { if (error.response) { // The request was made and the server responded with a status code const status = error.response.status - const headers = error.response.headers + const responseHeaders = error.response.headers const payload = error.response.data as Object -======= -async function get(url: string, headers: string): Promise<[number, Object]> { - const response = await axios.get(url, { - responseType: 'json', - headers: headers - }) ->>>>>>> b01610cfde9760085915318c127f17b016fec695 - return [status, headers, payload] + return [status, responseHeaders, payload] } -<<<<<<< HEAD // Something happened in setting up the request that triggered an error return [ 500, @@ -64,36 +45,25 @@ async function get(url: string, headers: string): Promise<[number, Object]> { `request could not be generated: ${JSON.stringify(error.message)}` ] } -======= -async function post(url: string, payload: string, headers: string): Promise<[number, Object]> { - const response = await axios.post(url, payload, { - responseType: 'json', - headers: headers - }) - - const status = response.status - const data = response.data as Object - - return [status, data] ->>>>>>> b01610cfde9760085915318c127f17b016fec695 } -export type Method = - | 'get' - | 'GET' - | 'delete' - | 'DELETE' - | 'head' - | 'HEAD' - | 'options' - | 'OPTIONS' - | 'post' - | 'POST' - | 'put' - | 'PUT' - | 'patch' - | 'PATCH' - | 'link' - | 'LINK' - | 'unlink' - | 'UNLINK' +// why not use Method from axios.AxiosRequestConfig ? +// export type Method = +// | 'get' +// | 'GET' +// | 'delete' +// | 'DELETE' +// | 'head' +// | 'HEAD' +// | 'options' +// | 'OPTIONS' +// | 'post' +// | 'POST' +// | 'put' +// | 'PUT' +// | 'patch' +// | 'PATCH' +// | 'link' +// | 'LINK' +// | 'unlink' +// | 'UNLINK' diff --git a/src/main.ts b/src/main.ts index 3659f63..4f758f2 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,6 @@ import * as core from '@actions/core' -import {request, Method} from './http' +import axios, { Method } from 'axios' +import {request} from './http' import {graphqlPayloadFor} from './graphql' export async function run(): Promise { @@ -10,13 +11,13 @@ export async function run(): Promise { const graphql: string = core.getInput('graphql') let headers: string = core.getInput('headers') - if (headers.length == 0) { - headers = "{'Content-Type': 'application/json'}" - } - if (graphql.length !== 0) { method = 'POST' data = graphqlPayloadFor(graphql) + + if (headers.length == 0) { + headers = '{\'Content-Type\': \'application/graphql\'}' + } core.info(`graphql:\n${graphql}`) } @@ -27,17 +28,14 @@ export async function run(): Promise { core.info(`data: ${data}`) } -<<<<<<< HEAD const [status, rawHeaders, rawResponse] = await request( url, method, - data + data, + headers ) -======= - const [status, rawResponse] = await request(url, method, data, headers) ->>>>>>> b01610cfde9760085915318c127f17b016fec695 - const headers = JSON.stringify(rawHeaders) + const responseHeaders = JSON.stringify(rawHeaders) const response = JSON.stringify(rawResponse) if (status < 200 || status >= 300) { @@ -53,7 +51,7 @@ export async function run(): Promise { core.info(`response body:\n${response}`) core.setOutput('status', `${status}`) - core.setOutput('headers', `${headers}`) + core.setOutput('headers', `${responseHeaders}`) core.setOutput('response', `${response}`) } catch (error) { core.setFailed(error.message) From f295f631c14715a6b9b419582e287b6a3bc070ae Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 15:06:59 -0400 Subject: [PATCH 04/13] test: add input/response headers to assertions --- __tests__/http.test.ts | 12 ++++++------ __tests__/integration.test.ts | 2 ++ __tests__/main.test.ts | 15 ++++++++++++--- 3 files changed, 20 insertions(+), 9 deletions(-) diff --git a/__tests__/http.test.ts b/__tests__/http.test.ts index 818214a..d22af45 100644 --- a/__tests__/http.test.ts +++ b/__tests__/http.test.ts @@ -12,17 +12,17 @@ describe('when calling get', () => { when(fakeRequest) .calledWith(expect.anything()) - .mockReturnValue(Promise.resolve({status: 200, data: {some: 'JSON'}})) + .mockReturnValue(Promise.resolve({status: 200, data: {}, headers: {}})) }) it('should call axios with the appropriate url and payload', async () => { - await request('url', 'get') + await request('url', 'get', '{"some": "JSON"}', {some: 'headers'}) expect(fakeRequest).toHaveBeenCalledWith({ url: 'url', method: 'get', - data: '{}', - headers: expect.anything() + data: '{"some": "JSON"}', + headers: {some: 'headers'} }) }) }) @@ -39,13 +39,13 @@ describe('when calling post', () => { }) it('should call axios with the appropriate url and payload', async () => { - await request('url', 'post', '{"a": "JSON"}') + await request('url', 'post', '{"a": "JSON"}', {}) expect(fakeRequest).toHaveBeenCalledWith({ url: 'url', method: 'post', data: '{"a": "JSON"}', - headers: expect.anything() + headers: {} }) }) }) diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts index e8fef9b..0da106a 100644 --- a/__tests__/integration.test.ts +++ b/__tests__/integration.test.ts @@ -60,11 +60,13 @@ describe('when called with a GraphQL query', () => { emoji } }` + process.env['INPUT_HEADERS'] = '{"content-type":"application/json"}' }) afterEach(() => { delete process.env['INPUT_URL'] delete process.env['INPUT_GRAPHQL'] + delete process.env['INPUT_HEADERS'] }) it('should output something if a query was supplied', async () => { diff --git a/__tests__/main.test.ts b/__tests__/main.test.ts index 53cfac2..d4c18ed 100644 --- a/__tests__/main.test.ts +++ b/__tests__/main.test.ts @@ -12,8 +12,12 @@ describe('when running the action with valid inputs', () => { jest.resetModules() when(fakeRequest) - .calledWith('url', expect.anything()) - .mockReturnValue(Promise.resolve([200, 'headers', {some: 'JSON'}])) + .calledWith('url', expect.anything(), expect.anything(), { + some: 'input-headers' + }) + .mockReturnValue( + Promise.resolve([200, {some: 'response-headers'}, {some: 'JSON'}]) + ) process.env['INPUT_URL'] = 'url' }) @@ -25,6 +29,7 @@ describe('when running the action with valid inputs', () => { it('should print as info level message the inputs and outputs', async () => { process.env['INPUT_METHOD'] = 'POST' process.env['INPUT_DATA'] = '{ a: "payload" }' + process.env['INPUT_HEADERS'] = '{"some": "input-headers"}' const infoMock = jest.spyOn(core, 'info') @@ -33,18 +38,21 @@ describe('when running the action with valid inputs', () => { expect(infoMock.mock.calls).toEqual([ ['url: url'], ['method: POST'], + ['headers: {"some":"input-headers"}'], ['data: { a: "payload" }'], ['response status: 200'], - ['response headers: '], + ['response headers: {"some":"response-headers"}'], ['response body:\n{"some":"JSON"}'] ]) delete process.env['INPUT_METHOD'] delete process.env['INPUT_DATA'] + delete process.env['INPUT_HEADERS'] }) it('should not blow with GET', async () => { process.env['INPUT_METHOD'] = 'GET' + process.env['INPUT_HEADERS'] = '{"some": "input-headers" }' const fakeSetOutput = jest.spyOn(core, 'setOutput') @@ -55,5 +63,6 @@ describe('when running the action with valid inputs', () => { expect(fakeSetOutput).toBeCalledWith('response', '{"some":"JSON"}') delete process.env['INPUT_METHOD'] + delete process.env['INPUT_HEADERS'] }) }) From 61f6a21102ceefb1e2351cdb31f8a71c4fbb7d0f Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 15:10:51 -0400 Subject: [PATCH 05/13] refactor: pass responsibility of setting headers to main.ts --- src/http.ts | 2 +- src/main.ts | 28 +++++++++++++++++++--------- 2 files changed, 20 insertions(+), 10 deletions(-) diff --git a/src/http.ts b/src/http.ts index faafe7f..caa07ab 100644 --- a/src/http.ts +++ b/src/http.ts @@ -13,7 +13,7 @@ export async function request( url: string, method: Method, //using Method from axios data = '{}', - headers = '{\'Content-Type\': \'application/json\'}' + headers: Object = {} ): Promise<[number, Object, Object]> { try { const response = await axios.request({ diff --git a/src/main.ts b/src/main.ts index 4f758f2..9dc1a05 100644 --- a/src/main.ts +++ b/src/main.ts @@ -9,14 +9,21 @@ export async function run(): Promise { let method: string = core.getInput('method') let data: string = core.getInput('data') const graphql: string = core.getInput('graphql') - let headers: string = core.getInput('headers') + const rawInputHeaders: string = core.getInput('headers') + + let inputHeaders: Object + if (rawInputHeaders.length > 0) { + inputHeaders = JSON.parse(rawInputHeaders) + } else { + inputHeaders = {} + } if (graphql.length !== 0) { method = 'POST' data = graphqlPayloadFor(graphql) - - if (headers.length == 0) { - headers = '{\'Content-Type\': \'application/graphql\'}' + + if (isEmpty(inputHeaders)) { + inputHeaders = {'Content-Type': 'application/graphql'} } core.info(`graphql:\n${graphql}`) @@ -24,30 +31,31 @@ export async function run(): Promise { core.info(`url: ${url}`) core.info(`method: ${method}`) + core.info(`headers: ${JSON.stringify(inputHeaders)}`) if (data.length !== 0) { core.info(`data: ${data}`) } - const [status, rawHeaders, rawResponse] = await request( + const [status, rawResponseHeaders, rawResponse] = await request( url, method, data, - headers + inputHeaders ) - const responseHeaders = JSON.stringify(rawHeaders) + const responseHeaders = JSON.stringify(rawResponseHeaders) const response = JSON.stringify(rawResponse) if (status < 200 || status >= 300) { core.error(`response status: ${status}`) - core.error(`response headers: ${headers}`) + core.error(`response headers: ${responseHeaders}`) core.error(`response body:\n${response}`) throw new Error(`request failed: ${response}`) } core.info(`response status: ${status}`) - core.info(`response headers: ${headers}`) + core.info(`response headers: ${responseHeaders}`) core.info(`response body:\n${response}`) core.setOutput('status', `${status}`) @@ -58,4 +66,6 @@ export async function run(): Promise { } } +const isEmpty = (o: Object): Boolean => Object.keys(o).length === 0 + run() From 0d06ba7c22cf3b6bdb70cb65acfdded90b4bcf01 Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 15:11:33 -0400 Subject: [PATCH 06/13] chore: fix linter complaints about unused vars & comments --- src/http.ts | 23 +---------------------- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/http.ts b/src/http.ts index caa07ab..4284d4a 100644 --- a/src/http.ts +++ b/src/http.ts @@ -1,4 +1,4 @@ -import axios, { Method } from 'axios' +import axios, {Method} from 'axios' /** * Send an HTTP request with JSON as content and response type. @@ -46,24 +46,3 @@ export async function request( ] } } - -// why not use Method from axios.AxiosRequestConfig ? -// export type Method = -// | 'get' -// | 'GET' -// | 'delete' -// | 'DELETE' -// | 'head' -// | 'HEAD' -// | 'options' -// | 'OPTIONS' -// | 'post' -// | 'POST' -// | 'put' -// | 'PUT' -// | 'patch' -// | 'PATCH' -// | 'link' -// | 'LINK' -// | 'unlink' -// | 'UNLINK' diff --git a/src/main.ts b/src/main.ts index 9dc1a05..a0576b7 100644 --- a/src/main.ts +++ b/src/main.ts @@ -1,5 +1,5 @@ import * as core from '@actions/core' -import axios, { Method } from 'axios' +import {Method} from 'axios' import {request} from './http' import {graphqlPayloadFor} from './graphql' From bb882547729b3ac1045ff59612d9385c1007eccb Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 15:11:58 -0400 Subject: [PATCH 07/13] chore: add compiled code --- dist/index.js | 107 +++++++++++++++++++++++++++++++++----------------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/dist/index.js b/dist/index.js index 760949e..04084e7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -860,31 +860,39 @@ function run() { let method = core.getInput('method'); let data = core.getInput('data'); const graphql = core.getInput('graphql'); - let headers = core.getInput('headers'); + const rawInputHeaders = core.getInput('headers'); + let inputHeaders; + if (rawInputHeaders.length > 0) { + inputHeaders = JSON.parse(rawInputHeaders); + } + else { + inputHeaders = {}; + } if (graphql.length !== 0) { method = 'POST'; data = graphql_1.graphqlPayloadFor(graphql); - if (headers.length == 0) { - headers = '{\'Content-Type\': \'application/graphql\'}'; + if (isEmpty(inputHeaders)) { + inputHeaders = { 'Content-Type': 'application/graphql' }; } core.info(`graphql:\n${graphql}`); } core.info(`url: ${url}`); core.info(`method: ${method}`); + core.info(`headers: ${JSON.stringify(inputHeaders)}`); if (data.length !== 0) { core.info(`data: ${data}`); } - const [status, rawHeaders, rawResponse] = yield http_1.request(url, method, data, headers); - const responseHeaders = JSON.stringify(rawHeaders); + const [status, rawResponseHeaders, rawResponse] = yield http_1.request(url, method, data, inputHeaders); + const responseHeaders = JSON.stringify(rawResponseHeaders); const response = JSON.stringify(rawResponse); if (status < 200 || status >= 300) { core.error(`response status: ${status}`); - core.error(`response headers: ${headers}`); + core.error(`response headers: ${responseHeaders}`); core.error(`response body:\n${response}`); throw new Error(`request failed: ${response}`); } core.info(`response status: ${status}`); - core.info(`response headers: ${headers}`); + core.info(`response headers: ${responseHeaders}`); core.info(`response body:\n${response}`); core.setOutput('status', `${status}`); core.setOutput('headers', `${responseHeaders}`); @@ -896,6 +904,7 @@ function run() { }); } exports.run = run; +const isEmpty = (o) => Object.keys(o).length === 0; run(); @@ -1761,7 +1770,7 @@ module.exports = require("assert"); /***/ 361: /***/ (function(module) { -module.exports = {"_args":[["axios@0.19.2","/home/titoine54/watermelon-http-client"]],"_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":"/home/titoine54/watermelon-http-client","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"}; +module.exports = {"_from":"axios@^0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.19.2","name":"axios","escapedName":"axios","rawSpec":"^0.19.2","saveSpec":null,"fetchSpec":"^0.19.2"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_shasum":"3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27","_spec":"axios@^0.19.2","_where":"/Users/camilogarcialarotta/playground/graphql-client-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"}; /***/ }), @@ -1863,17 +1872,24 @@ module.exports = require("stream"); "use strict"; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); -const os = __webpack_require__(87); +const os = __importStar(__webpack_require__(87)); /** * Commands * * Command Format: - * ##[name key=value;key=value]message + * ::name key=value,key=value::message * * Examples: - * ##[warning]This is the user warning message - * ##[set-secret name=mypassword]definitelyNotAPassword! + * ::warning::This is the message + * ::set-env name=MY_VAR::some value */ function issueCommand(command, properties, message) { const cmd = new Command(command, properties, message); @@ -1898,34 +1914,39 @@ class Command { let cmdStr = CMD_STRING + this.command; if (this.properties && Object.keys(this.properties).length > 0) { cmdStr += ' '; + let first = true; for (const key in this.properties) { if (this.properties.hasOwnProperty(key)) { const val = this.properties[key]; if (val) { - // safely append the val - avoid blowing up when attempting to - // call .replace() if message is not a string for some reason - cmdStr += `${key}=${escape(`${val || ''}`)},`; + if (first) { + first = false; + } + else { + cmdStr += ','; + } + cmdStr += `${key}=${escapeProperty(val)}`; } } } } - cmdStr += CMD_STRING; - // safely append the message - avoid blowing up when attempting to - // call .replace() if message is not a string for some reason - const message = `${this.message || ''}`; - cmdStr += escapeData(message); + cmdStr += `${CMD_STRING}${escapeData(this.message)}`; return cmdStr; } } function escapeData(s) { - return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); + return (s || '') + .replace(/%/g, '%25') + .replace(/\r/g, '%0D') + .replace(/\n/g, '%0A'); } -function escape(s) { - return s +function escapeProperty(s) { + return (s || '') + .replace(/%/g, '%25') .replace(/\r/g, '%0D') .replace(/\n/g, '%0A') - .replace(/]/g, '%5D') - .replace(/;/g, '%3B'); + .replace(/:/g, '%3A') + .replace(/,/g, '%2C'); } //# sourceMappingURL=command.js.map @@ -1945,10 +1966,17 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; + result["default"] = mod; + return result; +}; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = __webpack_require__(431); -const os = __webpack_require__(87); -const path = __webpack_require__(622); +const os = __importStar(__webpack_require__(87)); +const path = __importStar(__webpack_require__(622)); /** * The code to exit an action */ @@ -2034,6 +2062,13 @@ exports.setFailed = setFailed; //----------------------------------------------------------------------- // Logging Commands //----------------------------------------------------------------------- +/** + * Gets whether Actions Step Debug is on or not + */ +function isDebug() { + return process.env['RUNNER_DEBUG'] === '1'; +} +exports.isDebug = isDebug; /** * Writes debug message to user log * @param message debug message @@ -2711,7 +2746,7 @@ const axios_1 = __importDefault(__webpack_require__(53)); * @returns `[status code, response body]` */ function request(url, method, //using Method from axios -data = '{}', headers = '{\'Content-Type\': \'application/json\'}') { +data = '{}', headers = {}) { return __awaiter(this, void 0, void 0, function* () { try { const response = yield axios_1.default.request({ @@ -2733,19 +2768,17 @@ data = '{}', headers = '{\'Content-Type\': \'application/json\'}') { const payload = error.response.data; return [status, responseHeaders, payload]; } - else { - // Something happened in setting up the request that triggered an error - return [ - 500, - '', - `request could not be generated: ${error.message}` - ]; - } + // Something happened in setting up the request that triggered an error + return [ + 500, + '', + `request could not be generated: ${JSON.stringify(error.message)}` + ]; } }); } exports.request = request; -// why not use Method from axios.AxiosRequestConfig ? +// why not use Method from axios.AxiosRequestConfig ? // export type Method = // | 'get' // | 'GET' From 6c41b99b0389404ce34629ea942acd89fcd9d8c8 Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 15:20:16 -0400 Subject: [PATCH 08/13] fix: use JSON encoding for GraphQL queries by default --- dist/index.js | 22 +--------------------- src/main.ts | 2 +- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/dist/index.js b/dist/index.js index 04084e7..7bc9c3b 100644 --- a/dist/index.js +++ b/dist/index.js @@ -872,7 +872,7 @@ function run() { method = 'POST'; data = graphql_1.graphqlPayloadFor(graphql); if (isEmpty(inputHeaders)) { - inputHeaders = { 'Content-Type': 'application/graphql' }; + inputHeaders = { 'Content-Type': 'application/json' }; } core.info(`graphql:\n${graphql}`); } @@ -2778,26 +2778,6 @@ data = '{}', headers = {}) { }); } exports.request = request; -// why not use Method from axios.AxiosRequestConfig ? -// export type Method = -// | 'get' -// | 'GET' -// | 'delete' -// | 'DELETE' -// | 'head' -// | 'HEAD' -// | 'options' -// | 'OPTIONS' -// | 'post' -// | 'POST' -// | 'put' -// | 'PUT' -// | 'patch' -// | 'PATCH' -// | 'link' -// | 'LINK' -// | 'unlink' -// | 'UNLINK' /***/ }), diff --git a/src/main.ts b/src/main.ts index a0576b7..ce97c57 100644 --- a/src/main.ts +++ b/src/main.ts @@ -23,7 +23,7 @@ export async function run(): Promise { data = graphqlPayloadFor(graphql) if (isEmpty(inputHeaders)) { - inputHeaders = {'Content-Type': 'application/graphql'} + inputHeaders = {'Content-Type': 'application/json'} } core.info(`graphql:\n${graphql}`) From dfff280595c8b1014cee3e6b9167312c9deee77f Mon Sep 17 00:00:00 2001 From: titoine54 Date: Sun, 5 Apr 2020 16:15:33 -0400 Subject: [PATCH 09/13] test: added test for custom headers (not completed) --- __tests__/integration.test.ts | 35 +++++++++++++++++++ dist/index.js | 66 +++++++++++------------------------ 2 files changed, 55 insertions(+), 46 deletions(-) diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts index 0da106a..ad583e0 100644 --- a/__tests__/integration.test.ts +++ b/__tests__/integration.test.ts @@ -79,6 +79,41 @@ describe('when called with a GraphQL query', () => { }) }) +describe('when called GraphQL with a custom header', () => { + beforeEach(() => { + process.env['INPUT_URL'] = 'https://countries.trevorblades.com/' + process.env['INPUT_GRAPHQL'] = ` + { + country(code: "CA") { + name + capital + currency + } + }` + process.env['INPUT_HEADERS'] = + '{"content-type":"application/json", Cache-Control: max-age=3600, Accept-Charset: utf-8}' + }) + + afterEach(() => { + delete process.env['INPUT_URL'] + delete process.env['INPUT_GRAPHQL'] + delete process.env['INPUT_HEADERS'] + }) + + it('should reply with the corresponding headers', async () => { + const fakeSetOutput = jest.spyOn(core, 'setOutput') + + await run() + + expect(fakeSetOutput).toBeCalledWith('status', expect.anything()) + expect(fakeSetOutput).toBeCalledWith('response', expect.anything()) + expect(fakeSetOutput).toBeCalledWith( + 'headers', + expect.stringContaining('utf-8') + ) + }) +}) + describe('when action fails', () => { it('should handle missing input gracefully', async () => { const fakeSetOutput = jest.spyOn(core, 'setOutput') diff --git a/dist/index.js b/dist/index.js index 7bc9c3b..fc5b0e1 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1770,7 +1770,7 @@ module.exports = require("assert"); /***/ 361: /***/ (function(module) { -module.exports = {"_from":"axios@^0.19.2","_id":"axios@0.19.2","_inBundle":false,"_integrity":"sha512-fjgm5MvRHLhx+osE2xoekY70AhARk3a6hkN+3Io1jc00jtquGvxYlKlsFUhmUET0V5te6CcZI7lcv2Ym61mjHA==","_location":"/axios","_phantomChildren":{},"_requested":{"type":"range","registry":true,"raw":"axios@^0.19.2","name":"axios","escapedName":"axios","rawSpec":"^0.19.2","saveSpec":null,"fetchSpec":"^0.19.2"},"_requiredBy":["#USER","/"],"_resolved":"https://registry.npmjs.org/axios/-/axios-0.19.2.tgz","_shasum":"3ea36c5d8818d0d5f8a8a97a6d36b86cdc00cb27","_spec":"axios@^0.19.2","_where":"/Users/camilogarcialarotta/playground/graphql-client-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","/home/titoine54/watermelon-http-client"]],"_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":"/home/titoine54/watermelon-http-client","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"}; /***/ }), @@ -1872,24 +1872,17 @@ module.exports = require("stream"); "use strict"; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; Object.defineProperty(exports, "__esModule", { value: true }); -const os = __importStar(__webpack_require__(87)); +const os = __webpack_require__(87); /** * Commands * * Command Format: - * ::name key=value,key=value::message + * ##[name key=value;key=value]message * * Examples: - * ::warning::This is the message - * ::set-env name=MY_VAR::some value + * ##[warning]This is the user warning message + * ##[set-secret name=mypassword]definitelyNotAPassword! */ function issueCommand(command, properties, message) { const cmd = new Command(command, properties, message); @@ -1914,39 +1907,34 @@ class Command { let cmdStr = CMD_STRING + this.command; if (this.properties && Object.keys(this.properties).length > 0) { cmdStr += ' '; - let first = true; for (const key in this.properties) { if (this.properties.hasOwnProperty(key)) { const val = this.properties[key]; if (val) { - if (first) { - first = false; - } - else { - cmdStr += ','; - } - cmdStr += `${key}=${escapeProperty(val)}`; + // safely append the val - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + cmdStr += `${key}=${escape(`${val || ''}`)},`; } } } } - cmdStr += `${CMD_STRING}${escapeData(this.message)}`; + cmdStr += CMD_STRING; + // safely append the message - avoid blowing up when attempting to + // call .replace() if message is not a string for some reason + const message = `${this.message || ''}`; + cmdStr += escapeData(message); return cmdStr; } } function escapeData(s) { - return (s || '') - .replace(/%/g, '%25') - .replace(/\r/g, '%0D') - .replace(/\n/g, '%0A'); + return s.replace(/\r/g, '%0D').replace(/\n/g, '%0A'); } -function escapeProperty(s) { - return (s || '') - .replace(/%/g, '%25') +function escape(s) { + return s .replace(/\r/g, '%0D') .replace(/\n/g, '%0A') - .replace(/:/g, '%3A') - .replace(/,/g, '%2C'); + .replace(/]/g, '%5D') + .replace(/;/g, '%3B'); } //# sourceMappingURL=command.js.map @@ -1966,17 +1954,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; -var __importStar = (this && this.__importStar) || function (mod) { - if (mod && mod.__esModule) return mod; - var result = {}; - if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k]; - result["default"] = mod; - return result; -}; Object.defineProperty(exports, "__esModule", { value: true }); const command_1 = __webpack_require__(431); -const os = __importStar(__webpack_require__(87)); -const path = __importStar(__webpack_require__(622)); +const os = __webpack_require__(87); +const path = __webpack_require__(622); /** * The code to exit an action */ @@ -2062,13 +2043,6 @@ exports.setFailed = setFailed; //----------------------------------------------------------------------- // Logging Commands //----------------------------------------------------------------------- -/** - * Gets whether Actions Step Debug is on or not - */ -function isDebug() { - return process.env['RUNNER_DEBUG'] === '1'; -} -exports.isDebug = isDebug; /** * Writes debug message to user log * @param message debug message From 69fd4cd167adf781d6eb9974ab54a733ac5b9f17 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Sun, 5 Apr 2020 18:23:09 -0400 Subject: [PATCH 10/13] test: added test for custom headers --- __tests__/integration.test.ts | 27 ++++++++------------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts index ad583e0..2444b41 100644 --- a/__tests__/integration.test.ts +++ b/__tests__/integration.test.ts @@ -79,38 +79,27 @@ describe('when called with a GraphQL query', () => { }) }) -describe('when called GraphQL with a custom header', () => { +describe('when called with a custom header containing wrong auth', () => { beforeEach(() => { - process.env['INPUT_URL'] = 'https://countries.trevorblades.com/' - process.env['INPUT_GRAPHQL'] = ` - { - country(code: "CA") { - name - capital - currency - } - }` + process.env['INPUT_URL'] = 'https://api.github.com' process.env['INPUT_HEADERS'] = - '{"content-type":"application/json", Cache-Control: max-age=3600, Accept-Charset: utf-8}' + '{"content-type":"application/json", "Authorization": "Basic YWxhZGRpbjpvcGVuc2VzYW1l"}' }) afterEach(() => { delete process.env['INPUT_URL'] - delete process.env['INPUT_GRAPHQL'] delete process.env['INPUT_HEADERS'] }) - it('should reply with the corresponding headers', async () => { + it('should reply with a 401 Unauthorized', async () => { const fakeSetOutput = jest.spyOn(core, 'setOutput') + const fakeLogError = jest.spyOn(core, 'error') await run() - expect(fakeSetOutput).toBeCalledWith('status', expect.anything()) - expect(fakeSetOutput).toBeCalledWith('response', expect.anything()) - expect(fakeSetOutput).toBeCalledWith( - 'headers', - expect.stringContaining('utf-8') - ) + expect(fakeLogError).toHaveBeenCalledTimes(3) + expect(fakeSetOutput).not.toHaveBeenCalled() + expect(fakeLogError).toBeCalledWith('response status: 401') }) }) From f2870ebecac7918a018b83fa86c7e04ec3452047 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Sun, 5 Apr 2020 18:30:13 -0400 Subject: [PATCH 11/13] doc : updated README with info on headers --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index fff0dfe..b570c09 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,7 @@ A Typescript Action that performs HTTP requests within your workflow. It support | url | Endpoint to query | https://api.github.com/graphql | | method | HTTP method | `GET` | | data | HTTP request payload | | +| headers | HTTP headers | {'Content-Type': 'application/json'} | | graphql | GraphQL query to execute. If defined, the `data` field is automatically populated with this payload and the `method` is set to `POST` | @@ -31,6 +32,7 @@ A Typescript Action that performs HTTP requests within your workflow. It support uses: CamiloGarciaLaRotta/watermelon-http-client@v1 with: url: 'https://countries.trevorblades.com/' + headers: '{"Content-Type": "application/json"}' graphql: | { country(code: "CO") { @@ -43,6 +45,7 @@ A Typescript Action that performs HTTP requests within your workflow. It support - [`GET`](.github/workflows/get.yml) ```yaml uses: CamiloGarciaLaRotta/watermelon-http-client@v1 + headers: '{"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="}' with: url: 'https://jsonplaceholder.typicode.com/todos?id=1' ``` @@ -52,6 +55,7 @@ A Typescript Action that performs HTTP requests within your workflow. It support uses: CamiloGarciaLaRotta/watermelon-http-client@v1 with: url: 'https://jsonplaceholder.typicode.com/todos' + headers: '{ "Connection": "keep-alive"}' method: post data: '{ "title": "dummy-todo", "userId": 1, "completed": false }' ``` From 126508458a0eec44594027e03489238cf0e0cd4d Mon Sep 17 00:00:00 2001 From: Camilo Garcia La Rotta Date: Sun, 5 Apr 2020 19:11:59 -0400 Subject: [PATCH 12/13] chore: try secret vault --- .github/workflows/graphql_2.yml | 38 +++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 .github/workflows/graphql_2.yml diff --git a/.github/workflows/graphql_2.yml b/.github/workflows/graphql_2.yml new file mode 100644 index 0000000..2654346 --- /dev/null +++ b/.github/workflows/graphql_2.yml @@ -0,0 +1,38 @@ +name: Test GitHub GraphQL API +on: push + +jobs: + test: + name: Test + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [macos-latest, ubuntu-latest, windows-latest] + steps: + - name: Get the sources + uses: actions/checkout@v2 + - name: Execute a dummy query + id: query + uses: ./ + with: + headers: '{"Authorization": "bearer ${{ secrets.TOKEN }}" }' + graphql: | + query { + repository(name: "watermelon-http-client", owner:"camilogarcialarotta"){ + issues(first:1) { + nodes{ + title + state + } + } + } + } + - name: Print the response status + run: echo ${{ steps.query.outputs.status }} + shell: bash + - name: Print the response headers + run: echo ${{ steps.query.outputs.headers }} + shell: bash + - name: Print the response payload + run: echo ${{ steps.query.outputs.response }} + shell: bash From 129d67961ceabe2addc20f5fa09b8a4b02880445 Mon Sep 17 00:00:00 2001 From: titoine54 Date: Sun, 5 Apr 2020 21:05:36 -0400 Subject: [PATCH 13/13] docs: removed headers from example in readme. test:changed dummy token in integration test for invalid authorization token --- README.md | 5 +---- __tests__/integration.test.ts | 2 +- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index b570c09..90ed7b1 100644 --- a/README.md +++ b/README.md @@ -11,7 +11,7 @@ A Typescript Action that performs HTTP requests within your workflow. It support | url | Endpoint to query | https://api.github.com/graphql | | method | HTTP method | `GET` | | data | HTTP request payload | | -| headers | HTTP headers | {'Content-Type': 'application/json'} | +| headers | HTTP headers | Empty by default. If no headers are supplied, GraphQL queries will be sent with `{'Content-Type': 'application/json'}` | | graphql | GraphQL query to execute. If defined, the `data` field is automatically populated with this payload and the `method` is set to `POST` | @@ -32,7 +32,6 @@ A Typescript Action that performs HTTP requests within your workflow. It support uses: CamiloGarciaLaRotta/watermelon-http-client@v1 with: url: 'https://countries.trevorblades.com/' - headers: '{"Content-Type": "application/json"}' graphql: | { country(code: "CO") { @@ -45,7 +44,6 @@ A Typescript Action that performs HTTP requests within your workflow. It support - [`GET`](.github/workflows/get.yml) ```yaml uses: CamiloGarciaLaRotta/watermelon-http-client@v1 - headers: '{"Authorization": "Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ=="}' with: url: 'https://jsonplaceholder.typicode.com/todos?id=1' ``` @@ -55,7 +53,6 @@ A Typescript Action that performs HTTP requests within your workflow. It support uses: CamiloGarciaLaRotta/watermelon-http-client@v1 with: url: 'https://jsonplaceholder.typicode.com/todos' - headers: '{ "Connection": "keep-alive"}' method: post data: '{ "title": "dummy-todo", "userId": 1, "completed": false }' ``` diff --git a/__tests__/integration.test.ts b/__tests__/integration.test.ts index 2444b41..513bcae 100644 --- a/__tests__/integration.test.ts +++ b/__tests__/integration.test.ts @@ -83,7 +83,7 @@ describe('when called with a custom header containing wrong auth', () => { beforeEach(() => { process.env['INPUT_URL'] = 'https://api.github.com' process.env['INPUT_HEADERS'] = - '{"content-type":"application/json", "Authorization": "Basic YWxhZGRpbjpvcGVuc2VzYW1l"}' + '{"content-type":"application/json", "Authorization": "Basic DummyToken123"}' }) afterEach(() => {