Readme
A GitHub webhook handler to capture stars in PostHog
Code
HTTP
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,
});
}
Val Town is a social website to write and deploy JavaScript.
Build APIs and schedule functions from your browser.
ianvph-posthoggithubstarcapture.web.val.run
Updated: June 11, 2024
This is perfect!