Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
import { email } from "https://esm.town/v/std/email?v=9";
import { githubPayloadStringToNormalizedJSON } from "https://esm.town/v/vtdocs/githubPayloadStringToNormalizedJSON";
import process from "node:process";
import { verifyGithubWebhookSignature } from "https://esm.town/v/vtdocs/verifyGithubWebhookSignature";
export const githubWebhookWithVerify = async (
req: express.Request,
res: express.Response,
) => {
const verified = await verifyGithubWebhookSignature(
process.env.githubWebhookToken,
githubPayloadStringToNormalizedJSON(req.body.payload),
req.get("X-Hub-Signature-256"),
);
if (!verified) {
return res.status(401);
}
const { action, sender, repository } = JSON.parse(req.body.payload);
if (action === "created") {
await email({
text: `Repository ${repository.full_name} starred by ${sender.login}`,
});
}
res.send(200);
};
October 23, 2023