import { dropCodeIndex } from "./code/search-index";
import { forgetRepoAttachmentBytes } from "./attachment-bytes";
import { retractScopeGauges } from "./metering/scope-gauges";
import { dropRepoState } from "./repo-state";
import { purgeDeletedRepoFromAccounts } from "./repo-account-cleanup";
import { waitUntil } from "cloudflare:workers";
import { clearWebhookLog } from "./webhook-log";
import { kickRepoInsights } from "./insights/repo-insights-do";
import { purgeRepoCaches } from "./git/cache-purge";
import { siteTeardownFor } from "./sites/sync";
import { assertPublicHttpsUrl } from "./git/relay";
import { assertResolvesPublic } from "./net/resolve-guard";
import { batch, first, run, stmt } from "./db";
import { randomId } from "./crypto";
import { artifactsNameFor, isArtifactsError, openArtifactsRepo, rememberInitialToken } from "./git/artifacts";
import { artifactsCall } from "./git/artifacts-call";
import { artifactsBinding, nameInShard, shardOfName } from "./git/artifacts-shards";
import { invalidateRefs, refreshRefs } from "./git/refs";
import { linkForkObjects, purgeRepoLfs } from "./lfs/objects";
import { withStore } from "./git/store";
import { commitChanges } from "./git/writer";
import { signatureNow } from "./git/objects";
import { assertOwnerNotDisabled, hasPrivateForkAncestor, loadRepoById } from "./repos";
import { badRequest, conflict } from "./errors";
import { encryptRepoSecret } from "./secrets";
import { describeProvisioningError, markProvisioningFailed, startProvisioning } from "./repo-provisioning";
import { emitWebhook, publicUrl, recordActivity } from "./events/emit";
import { repoDeletionStatements } from "./integrations/ownership";
import type { RepoRow, Viewer, Visibility } from "~/lib/types";
import { captureServerEvent } from "./analytics";
const DEFAULT_BRANCH = "main";
const PENDING_REPO_TIMEOUT_MS = 30 * 60 * 1000;
/** Artifacts still reports progress: allow very large imports and forks to keep going. */
const MAX_IN_PROGRESS_MS = 6 * 60 * 60 * 1000;
const encoder = new TextEncoder();
async function ensureNameFree(ownerId: string, name: string): Promise<void> {
const existing = await first<{ id: string }>("SELECT id FROM repos WHERE owner_id = ? AND name = ?", ownerId, name);
if (existing) throw conflict("A repository with that name already exists");