import { branchChanges } from "../diff.ts"; import type { ChangeSet } from "../contract/views.ts"; export interface Deps { env: Env; ctx: ExecutionContext; origin: string; } /** * A change set depends only on its two commits, so it is cached by them in the colo's cache. Callers check * access before asking; the key is never reachable from outside the Worker. */ export async function cachedChanges(deps: Deps, repoId: string, handle: ArtifactsRepo, baseTip: string, headTip: string): Promise { const key = new Request(`${deps.origin}/__refs-cache/changes/v4/${repoId}/${baseTip}/${headTip}`); const cache = await caches.open("refs-changes").catch(() => null); const hit = await cache?.match(key).catch(() => undefined); if (hit) return hit.json(); const changes = await branchChanges(handle, baseTip, headTip); if (cache) deps.ctx.waitUntil(cache.put(key, new Response(JSON.stringify(changes), { headers: { "content-type": "application/json", "cache-control": "max-age=2592000" } })).catch(() => undefined)); return changes; } export function adminEmails(env: Env): Set { return new Set(env.ADMIN_EMAILS.split(",").map((email) => email.trim().toLowerCase()).filter(Boolean)); }