210 lines · 8.6 KB
import { env } from "cloudflare:workers";
import { all, batch, first, stmt } from "../db";
import { rebillRepoLfs } from "../lfs/objects";
import { randomId } from "../crypto";
import { siteDb } from "./store";
import { randomToken, sha256Hex, timingSafeEqualStrings } from "../crypto";
import { conflict } from "../errors";
import { createRepository, deleteRepository } from "../repo-ops";
import { repoMoveStatements } from "../redirects";
import { disableRepoConfigOnTransfer, repoOwnershipChangeStatements } from "../integrations/ownership";
import { loadRepoById } from "../repos";
import { isScratchRepo, publishMeta, SCRATCH_ACCOUNT_ID, SCRATCH_LIMITS } from "./config";
import { loadSiteById, loadSiteForRepo } from "./deploy";
import { assertScratchQuota, insertScratch, scratchResult } from "./scratch-core";
import { syncSiteForRepo } from "./sync";
import type { ScratchResult } from "./scratch-core";
import type { SiteRow } from "./config";
import type { Permission, RepoRow, Viewer } from "~/lib/types";

const PUSH_PREFIX = "gitfor_scratch";
/** createScratchRepo inserts the repo before linking it to its site; don't race that window. */
const ORPHAN_GRACE_MS = 10 * 60 * 1000;
const DEFAULT_BRANCH = "main";
const MIB = 1024 * 1024;

/** The reserved org that owns unclaimed scratch repositories; it has no members and no sessions. */
export const SCRATCH_ACTOR: Viewer = {
  id: SCRATCH_ACCOUNT_ID,
  name: "scratch",
  displayName: "Scratch sites",
  email: "scratch@invalid",
  isAdmin: false,
  emailVerified: true,
};

export type ScratchRepoResult = ScratchResult & { remote: string; pushToken: string };

export { isScratchRepo };

/**