mirror of
https://github.com/joelwmale/webhook-action.git
synced 2026-08-24 00:49:00 +08:00
v2.0.1
This commit is contained in:
+2
-2
@@ -1,14 +1,14 @@
|
||||
const fetch = require('node-fetch');
|
||||
|
||||
class Http {
|
||||
make(url: string, headers: string, body: string): Promise<any> {
|
||||
make(url: string, headers: string|null, body: string|null): Promise<any> {
|
||||
return new Promise((resolve, reject) => {
|
||||
fetch(url, this.getOptions('post', headers, body))
|
||||
.then((res: Response) => resolve(res));
|
||||
});
|
||||
}
|
||||
|
||||
getOptions(method: string, headers: string, body: string) {
|
||||
getOptions(method: string, headers: string|null, body: string|null) {
|
||||
const options: any = {
|
||||
headers: headers ? JSON.parse(headers) : {},
|
||||
method
|
||||
|
||||
+9
-3
@@ -2,9 +2,15 @@ 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;
|
||||
const url = core.getInput('url') ? core.getInput('url') : (process.env.url ? process.env.url : '');
|
||||
const headers = core.getInput('headers') ? core.getInput('headers') : (process.env.headers ? process.env.headers : null);
|
||||
const body = core.getInput('body') ? core.getInput('body') : (process.env.body ? process.env.body : null);
|
||||
|
||||
if (!url) {
|
||||
// validate a url
|
||||
core.setFailed('A url is required to run this action.');
|
||||
return;
|
||||
}
|
||||
|
||||
// initial info
|
||||
core.info(`Sending webhook request to ${url}`);
|
||||
|
||||
Reference in New Issue
Block a user