fix(webhook): dedup duplicate deliveries, cache HMAC key, pass ExecutionContext

Skip re-processing when the same X-GitHub-Delivery id is seen (KV, 300s TTL)
to stop double pushes when both an org and an App webhook target the worker.
Pass ExecutionContext through so dispatch runs via waitUntil instead of a
fire-and-forget that gets frozen. Cache the imported HMAC key per secret.
This commit is contained in:
RhenCloud committed 2026-08-02 06:51:20 +08:00
1 parent c75cc058fc
commit befed0267a
3 files changed
+37 -13

No files matched your search

+13 -1
View File
@@ -45,9 +45,21 @@ export function createServer(): Hono<{ Bindings: Env }> {
return c.json({ error: "Invalid event" }, 400);
}
const delivery = headers["x-github-delivery"];
if (delivery) {
const seen = await c.env.KV.get(`delivery:${delivery}`);
if (seen) {
return c.json({ ok: true, duplicate: true });
}
await c.env.KV.put(`delivery:${delivery}`, "1", { expirationTtl: 300 });
}
const { loadConfig } = await import("./config");
const config = await loadConfig(c.env);
dispatchEvent(config, event, c.env).catch((err) => log.error(err, "Dispatch failed"));
const dispatch = dispatchEvent(config, event, c.env).catch((err) =>
log.error(err, "Dispatch failed"),
);
c.executionCtx.waitUntil(dispatch);
return c.json({ ok: true });
});