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"),
"github-" + webhookPayload.sender.login,
"GitHub Star",
eventProperties,
"https://eu.i.posthog.com",
);
return Response.json({
ok: true,
});
}