import { createHash } from "node:crypto"; // Tangled exposes the PR source branch, but no documented PR number environment variable. export function previewName(branch: string): string { if (!branch || branch === "main") { throw new Error("A preview needs a non-main source branch."); } const slug = branch .toLowerCase() .replaceAll(/[^a-z0-9]+/g, "-") .slice(0, 24) .replace(/-+$/, "") || "branch"; const hash = createHash("sha256").update(branch).digest("hex").slice(0, 12); return `pr-${slug}-${hash}`; }