From 30c36486ac139fe8c543dbc329a6acf0d84cc9bb Mon Sep 17 00:00:00 2001 From: Chris Lovering Date: Fri, 8 Dec 2023 11:25:12 +0000 Subject: [PATCH] Simplify sendWebhook function in github-filter worker This previously wasn't working correctly, as it was forwarded the response on failure correctly. However, we had no need to create a new Response object, as returning the Discord response is fine in all cases. This simplifies the worker quite a lot. --- github-filter/src/index.ts | 17 +---------------- 1 file changed, 1 insertion(+), 16 deletions(-) diff --git a/github-filter/src/index.ts b/github-filter/src/index.ts index 217108f..57d7ca9 100644 --- a/github-filter/src/index.ts +++ b/github-filter/src/index.ts @@ -128,23 +128,8 @@ async function sendLabelWebhook(label: string, data: Data, labelNamespace: KVNam } async function sendWebhook(id: string, token: string, data: Data) { - // Format for a webhook - let template = `https://discord.com/api/webhooks/${id}/${token}/github?wait=1`; - - let new_request = new Request(template, { - body: data.body, - headers: data.headers, - method: data.method, - }); - // Pass on data to Discord as usual - const response = await fetch(template, new_request); - if (!response.ok) { - return new Response(await response.json(), { - status: response.status, - }); - } - return response; + return await fetch(`https://discord.com/api/webhooks/${id}/${token}/github?wait=1`, data); } export default wrapModule(hcConfig, worker);