This commit is contained in:
Joel Male 2020-08-29 11:10:10 +10:00
parent aff8b23be8
commit 144f9e1d68
9 changed files with 36 additions and 12 deletions

11
dist/index.js vendored
View File

@ -91,23 +91,30 @@ function run() {
body = core.getInput('body') ? core.getInput('body') : (process.env.data ? process.env.data : null);
if (!url) {
core.setFailed('A url is required to run this action.');
return [2];
throw new Error('A url is required to run this action.');
}
core.info("Sending webhook request to " + url);
core.debug((new Date()).toTimeString());
http_1.http.make(url, headers, body)
.then(function (res) {
if (res.status >= 400) {
error(res.status);
}
core.setOutput('statusCode', res.status);
core.info("Received status code: " + res.status);
core.info((new Date()).toTimeString());
})
.catch(function (err) {
core.setFailed("Received status code: " + err.status);
error(err.status);
});
return [2];
});
});
}
function error(statusCode) {
core.setFailed("Received status code: " + statusCode);
throw new Error("Request failed with status code: " + statusCode);
}
run();
//# sourceMappingURL=main.js.map

2
dist/index.js.map vendored

File diff suppressed because one or more lines are too long

11
dist/main.js vendored
View File

@ -47,22 +47,29 @@ function run() {
body = core.getInput('body') ? core.getInput('body') : (process.env.data ? process.env.data : null);
if (!url) {
core.setFailed('A url is required to run this action.');
return [2];
throw new Error('A url is required to run this action.');
}
core.info("Sending webhook request to " + url);
core.debug((new Date()).toTimeString());
http_1.http.make(url, headers, body)
.then(function (res) {
if (res.status >= 400) {
error(res.status);
}
core.setOutput('statusCode', res.status);
core.info("Received status code: " + res.status);
core.info((new Date()).toTimeString());
})
.catch(function (err) {
core.setFailed("Received status code: " + err.status);
error(err.status);
});
return [2];
});
});
}
function error(statusCode) {
core.setFailed("Received status code: " + statusCode);
throw new Error("Request failed with status code: " + statusCode);
}
run();
//# sourceMappingURL=main.js.map

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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AC,CAAC;gBAExD,MAAM,IAAI,KAAK,CAAC,uCAAuC,CAAC,CAAC;aAC1D;YAGD,IAAI,CAAC,IAAI,CAAC,gCAA8B,GAAK,CAAC,CAAC;YAG/C,IAAI,CAAC,KAAK,CAAC,CAAC,IAAI,IAAI,EAAE,CAAC,CAAC,YAAY,EAAE,CAAC,CAAC;YAGxC,WAAI,CAAC,IAAI,CAAC,GAAG,EAAE,OAAO,EAAE,IAAI,CAAC;iBAC1B,IAAI,CAAC,UAAC,GAAG;gBAER,IAAI,GAAG,CAAC,MAAM,IAAI,GAAG,EAAE;oBAErB,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;iBACnB;gBAGD,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;gBACT,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;YACpB,CAAC,CAAC,CAAC;;;;CACR;AAED,SAAS,KAAK,CAAC,UAAU;IAEvB,IAAI,CAAC,SAAS,CAAC,2BAAyB,UAAY,CAAC,CAAC;IAEtD,MAAM,IAAI,KAAK,CAAC,sCAAoC,UAAY,CAAC,CAAC;AACpE,CAAC;AAED,GAAG,EAAE,CAAC"}

Binary file not shown.

Binary file not shown.

View File

@ -9,7 +9,8 @@ async function run() {
if (!url) {
// validate a url
core.setFailed('A url is required to run this action.');
return;
// error
throw new Error('A url is required to run this action.');
}
// initial info
@ -21,20 +22,29 @@ async function run() {
// make the request
http.make(url, headers, body)
.then((res) => {
// if the status code is not 2xx
if (res.status >= 400) {
// throw an error
error(res.status);
}
// output the status
core.setOutput('statusCode', res.status);
// throw error on error status codes
if (res.status >= 400)
throw new Error(`Failing with code: ${res.status}`)
// report on the status code
core.info(`Received status code: ${res.status}`);
// debug end
core.info((new Date()).toTimeString());
})
.catch((err) => {
// set the action to failed
core.setFailed(`Received status code: ${err.status}`);
error(err.status);
});
}
function error(statusCode) {
// set the action to failed
core.setFailed(`Received status code: ${statusCode}`);
// throw an error
throw new Error(`Request failed with status code: ${statusCode}`);
}
run();