2020-08-26 01:36:04 +02:00
|
|
|
import * as core from '@actions/core';
|
|
|
|
import { http } from './http';
|
|
|
|
|
|
|
|
async function run() {
|
2020-08-27 10:25:12 +02:00
|
|
|
const url = core.getInput('url') ? core.getInput('url') : (process.env.WEBHOOK_URL ? process.env.WEBHOOK_URL : '');
|
2020-08-27 10:23:33 +02:00
|
|
|
const headers = core.getInput('headers') ? core.getInput('headers') : (process.env.headers ? process.env.headers : null);
|
2020-08-27 10:25:12 +02:00
|
|
|
const body = core.getInput('body') ? core.getInput('body') : (process.env.data ? process.env.data : null);
|
2020-08-27 10:23:33 +02:00
|
|
|
|
|
|
|
if (!url) {
|
|
|
|
// validate a url
|
|
|
|
core.setFailed('A url is required to run this action.');
|
|
|
|
return;
|
|
|
|
}
|
2020-08-26 01:36:04 +02:00
|
|
|
|
|
|
|
// initial info
|
2020-08-26 02:25:43 +02:00
|
|
|
core.info(`Sending webhook request to ${url}`);
|
2020-08-26 01:36:04 +02:00
|
|
|
|
|
|
|
// debug start
|
|
|
|
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
|
|
|
|
|
|
|
|
// make the request
|
2020-08-26 01:50:21 +02:00
|
|
|
http.make(url, headers, body)
|
2020-08-26 02:25:43 +02:00
|
|
|
.then((res) => {
|
|
|
|
// output the status
|
|
|
|
core.setOutput('statusCode', res.status);
|
2020-08-29 03:06:49 +02:00
|
|
|
// throw error on error status codes
|
|
|
|
if (res.status >= 400)
|
|
|
|
throw new Error(`Failing with code: ${res.status}`)
|
2020-08-26 02:25:43 +02:00
|
|
|
// report on the status code
|
|
|
|
core.info(`Received status code: ${res.status}`);
|
2020-08-26 02:38:11 +02:00
|
|
|
// debug end
|
|
|
|
core.info((new Date()).toTimeString());
|
|
|
|
})
|
|
|
|
.catch((err) => {
|
|
|
|
// set the action to failed
|
|
|
|
core.setFailed(`Received status code: ${err.status}`);
|
2020-08-26 02:25:43 +02:00
|
|
|
});
|
2020-08-26 01:36:04 +02:00
|
|
|
}
|
|
|
|
|
2020-08-27 10:14:30 +02:00
|
|
|
run();
|