Select Git revision
webhookHandler.ts
Code owners
Assign users and groups as approvers for specific file changes. Learn more.
webhookHandler.ts 722 B
import { formatMessage } from "./formatter";
import type { HandlerReturnType, NotificationData, NotificationType, PossibleNotificationType } from "../../notifications/types";
export async function handleWebhook<T extends PossibleNotificationType>(recipient: string, type: NotificationType<T>, data: NotificationData<T>): Promise<HandlerReturnType> {
const body = JSON.stringify(Object.assign({}, data, {type: type.name, content: formatMessage(type, data)}));
const headers = {
"Content-Type": "application/json"
};
return fetch(recipient, {
method: "POST",
body,
headers
}).then(res => {
if(res.status >= 200 && res.status < 300){
return {
status: "success"
};
}else{
throw res;
}
});
};