1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
import { verify } from "https://esm.sh/@octokit/webhooks-methods@3.0.2?pin=v106";
import { email } from "https://esm.town/v/std/email?v=11";
export const githubWebhookWithVerify = async (req: Request) => {
const payload = await req.json();
const verified = await verify(
Deno.env.get("githubWebhookToken"),
JSON.stringify(payload),
req.headers.get("X-Hub-Signature-256"),
);
if (!verified) {
return new Response("Unauthorized", { status: 401 });
}
const { action, sender, repository } = payload;
if (action === "created") {
email({ text: `Repository ${repository.full_name} starred by ${sender.login}` });
}
return new Response("OK", { status: 200 });
};