A GitHub webhook handler to capture stars in PostHog

Readme
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
26
27
28
29
30
31
32
33
import { capturePostHogEvent } from "https://esm.town/v/ianvph/capturePostHogEvent";
export default async function(req: Request): Promise<Response> {
if (req.method !== "POST") {
return Response.json({ ok: "only post request" });
}
const webhookPayload = await req.json();
if (webhookPayload.action !== "created") {
return Response.json({ ok: "only stars" });
}
console.log(webhookPayload);
const eventProperties = {
repository: webhookPayload.repository.full_name,
starred_at: webhookPayload.starred_at,
user: webhookPayload.sender.login,
user_id: webhookPayload.sender.id,
user_url: webhookPayload.sender.url,
avatar: webhookPayload.sender.avatar_url,
};
capturePostHogEvent(
Deno.env.get("phProjectAPIKey"),
webhookPayload.sender.login,
"GitHub Star",
eventProperties,
);
return Response.json({
ok: true,
});
}
👆 This is a val. Vals are TypeScript snippets of code, written in the browser and run on our servers. Create scheduled functions, email yourself, and persist small pieces of data — all from the browser.
Comments
fuziontech avatar

This is perfect!