Allow optional headers & body

This commit is contained in:
Joel Male 2020-08-26 10:41:58 +10:00
parent 5be5ae3f9a
commit d3ff660fa9
12 changed files with 22 additions and 16 deletions

6
dist/http.js vendored
View File

@ -14,10 +14,12 @@ var Http = (function () {
}; };
Http.prototype.getOptions = function (method, headers, body) { Http.prototype.getOptions = function (method, headers, body) {
var options = { var options = {
headers: JSON.parse(headers), headers: headers ? JSON.parse(headers) : {},
method: method method: method
}; };
options.body = JSON.stringify(body); if (body) {
options.body = body;
}
options.headers['content-type'] = 'application/json'; options.headers['content-type'] = 'application/json';
return options; return options;
}; };

2
dist/http.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";;;AAAA,IAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEpC;IAAA;IAsBA,CAAC;IArBC,mBAAI,GAAJ,UAAK,GAAW,EAAE,OAAe,EAAE,IAAY;QAA/C,iBAKC;QAJC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YACjC,KAAK,CAAC,GAAG,EAAE,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;iBAC/C,IAAI,CAAC,UAAC,GAAa,IAAK,OAAA,OAAO,CAAC,GAAG,CAAC,EAAZ,CAAY,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAU,GAAV,UAAW,MAAc,EAAE,OAAe,EAAE,IAAY;QACtD,IAAM,OAAO,GAAQ;YACnB,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC;YAC5B,MAAM,QAAA;SACP,CAAC;QAGF,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;QAGpC,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAErD,OAAO,OAAO,CAAC;IACjB,CAAC;IACH,WAAC;AAAD,CAAC,AAtBD,IAsBC;AAEY,QAAA,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC"} {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":";;;AAAA,IAAM,KAAK,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AAEpC;IAAA;IAwBA,CAAC;IAvBC,mBAAI,GAAJ,UAAK,GAAW,EAAE,OAAe,EAAE,IAAY;QAA/C,iBAKC;QAJC,OAAO,IAAI,OAAO,CAAC,UAAC,OAAO,EAAE,MAAM;YACjC,KAAK,CAAC,GAAG,EAAE,KAAI,CAAC,UAAU,CAAC,MAAM,EAAE,OAAO,EAAE,IAAI,CAAC,CAAC;iBAC/C,IAAI,CAAC,UAAC,GAAa,IAAK,OAAA,OAAO,CAAC,GAAG,CAAC,EAAZ,CAAY,CAAC,CAAC;QAC3C,CAAC,CAAC,CAAC;IACL,CAAC;IAED,yBAAU,GAAV,UAAW,MAAc,EAAE,OAAe,EAAE,IAAY;QACtD,IAAM,OAAO,GAAQ;YACnB,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,EAAE;YAC3C,MAAM,QAAA;SACP,CAAC;QAEF,IAAI,IAAI,EAAE;YAER,OAAO,CAAC,IAAI,GAAG,IAAI,CAAC;SACrB;QAGD,OAAO,CAAC,OAAO,CAAC,cAAc,CAAC,GAAG,kBAAkB,CAAC;QAErD,OAAO,OAAO,CAAC;IACjB,CAAC;IACH,WAAC;AAAD,CAAC,AAxBD,IAwBC;AAEY,QAAA,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC"}

10
dist/index.js vendored
View File

@ -312,10 +312,12 @@ var Http = (function () {
}; };
Http.prototype.getOptions = function (method, headers, body) { Http.prototype.getOptions = function (method, headers, body) {
var options = { var options = {
headers: JSON.parse(headers), headers: headers ? JSON.parse(headers) : {},
method: method method: method
}; };
options.body = JSON.stringify(body); if (body) {
options.body = body;
}
options.headers['content-type'] = 'application/json'; options.headers['content-type'] = 'application/json';
return options; return options;
}; };
@ -2132,8 +2134,8 @@ function run() {
var url, headers, body; var url, headers, body;
return __generator(this, function (_c) { return __generator(this, function (_c) {
url = core.getInput('url'); url = core.getInput('url');
headers = (_a = core.getInput('headers')) !== null && _a !== void 0 ? _a : ''; headers = (_a = core.getInput('headers')) !== null && _a !== void 0 ? _a : null;
body = (_b = core.getInput('body')) !== null && _b !== void 0 ? _b : ''; body = (_b = core.getInput('body')) !== null && _b !== void 0 ? _b : null;
core.info("Sending webhook request to " + url); core.info("Sending webhook request to " + url);
core.debug((new Date()).toTimeString()); core.debug((new Date()).toTimeString());
http_1.http.make(url, headers, body) http_1.http.make(url, headers, body)

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

4
dist/main.js vendored
View File

@ -44,8 +44,8 @@ function run() {
var url, headers, body; var url, headers, body;
return __generator(this, function (_c) { return __generator(this, function (_c) {
url = core.getInput('url'); url = core.getInput('url');
headers = (_a = core.getInput('headers')) !== null && _a !== void 0 ? _a : ''; headers = (_a = core.getInput('headers')) !== null && _a !== void 0 ? _a : null;
body = (_b = core.getInput('body')) !== null && _b !== void 0 ? _b : ''; body = (_b = core.getInput('body')) !== null && _b !== void 0 ? _b : null;
core.info("Sending webhook request to " + url); core.info("Sending webhook request to " + url);
core.debug((new Date()).toTimeString()); core.debug((new Date()).toTimeString());
http_1.http.make(url, headers, body) http_1.http.make(url, headers, body)

2
dist/main.js.map vendored
View File

@ -1 +1 @@
{"version":3,"file":"main.js","sourceRoot":"","sources":["../src/main.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,oCAAsC;AACtC,+BAA8B;AAE9B,SAAe,GAAG;;;;;YACR,GAAG,GAAG,IAAI,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;YAC3B,OAAO,SAAG,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,mCAAI,E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AAC,YAAY,EAAE,CAAC,CAAC;YAGxC,WAAI,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;iBAC1B,IAAI,CAAC,UAAC,GAAG;gBAER,IAAI,CAAC,SAAS,CAAC,YAAY,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;gBAEzC,IAAI,CAAC,IAAI,CAAC,2BAAyB,GAAG,CAAC,MAAQ,CAAC,CAAC;gBAEjD,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;YACzC,CAAC,CAAC;iBACD,KAAK,CAAC,UAAC,GAAG;gBAET,IAAI,CAAC,SAAS,CAAC,2BAAyB,GAAG,CAAC,MAAQ,CAAC,CAAC;YACxD,CAAC,CAAC,CAAC;;;;CACR;AAED,GAAG,EAAE,CAAC"}

Binary file not shown.

Binary file not shown.

View File

@ -10,12 +10,14 @@ class Http {
getOptions(method: string, headers: string, body: string) { getOptions(method: string, headers: string, body: string) {
const options: any = { const options: any = {
headers: JSON.parse(headers), headers: headers ? JSON.parse(headers) : {},
method method
}; };
// stringify the body if (body) {
options.body = JSON.stringify(body); // parse the body
options.body = body;
}
// set these headers // set these headers
options.headers['content-type'] = 'application/json'; options.headers['content-type'] = 'application/json';

View File

@ -3,8 +3,8 @@ import { http } from './http';
async function run() { async function run() {
const url = core.getInput('url'); const url = core.getInput('url');
const headers = core.getInput('headers') ?? ''; const headers = core.getInput('headers') ?? null;
const body = core.getInput('body') ?? ''; const body = core.getInput('body') ?? null;
// initial info // initial info
core.info(`Sending webhook request to ${url}`); core.info(`Sending webhook request to ${url}`);