webhook/src/main.ts

32 lines
996 B
TypeScript
Raw Normal View History

import * as core from '@actions/core';
import { http } from './http';
async function run() {
const url = core.getInput('url') ?? process.env.WEBHOOK_URL;
const headers = core.getInput('headers') ?? process.env.HEADERS ?? null;
const body = core.getInput('body') ?? process.env.data ?? null;
// initial info
2020-08-26 02:25:43 +02:00
core.info(`Sending webhook request to ${url}`);
// debug start
core.debug((new Date()).toTimeString()); // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
// make the request
http.make(url, headers, body)
2020-08-26 02:25:43 +02:00
.then((res) => {
// output the status
core.setOutput('statusCode', res.status);
// 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
});
}
run();