Skip to content

Commit

Permalink
Simplify sendWebhook function in github-filter worker
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ChrisLovering committed Dec 8, 2023
1 parent dc51ea8 commit 30c3648
Showing 1 changed file with 1 addition and 16 deletions.
17 changes: 1 addition & 16 deletions github-filter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 30c3648

Please sign in to comment.