1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
import process from "node:process";
import { verifyGithubWebhookSignature } from "https://esm.town/v/vtdocs/verifyGithubWebhookSignature?v=2";
export const githubWebhookWithVerify = async (req: Request) => {
const payload = await req.json();
const verified = await verifyGithubWebhookSignature(
process.env.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") {
console.email(
`Repository ${repository.full_name} starred by ${sender.login}`,
);
}
return new Response("OK", { status: 200 });
};