import { pullInput, pullUrl, requirePull } from "~/server/pull-access";
import { limitHeavy, limitWrite } from "~/server/limits";
import { createServerFn } from "@tanstack/react-start";
import { z } from "zod";
import { requireViewer, viewerMiddleware } from "./middleware";
import { all, batch, first, run, stmt } from "~/server/db";
import { randomId } from "~/server/crypto";
import { loadRepo, repoPermission, requireRepoAccess } from "~/server/repos";
import { branchSha, listRefs } from "~/server/git/refs";
import { withStore } from "~/server/git/store";
import { deleteRef } from "~/server/git/writer";
import { compareCommits } from "~/server/git/history";
import { allocateIssueNumber, indexIssue } from "~/server/issues";
import { addIssueEvent, checkMergeability, MergeError, mergeGate, performMerge } from "~/server/pulls";
import { afterPullChange } from "~/server/pull-events";
import { pullDiff } from "~/server/pull-files";
import { parseSuggestion } from "~/server/suggestions";
import { pullAutomation } from "~/server/merge-queue";
import { listLinkedIssues } from "~/server/pull-links";
import { listCommitStatuses, combinedState } from "~/server/statuses";
import { accountOrGhost, accountsById } from "~/server/people";
import { renderMarkdown } from "~/server/markdown";
import { reactionSummaries } from "~/server/reactions";
import { emitNotification, emitWebhook, recordActivity } from "~/server/events/emit";
import { badRequest, conflict, forbidden, notFoundError } from "~/server/errors";
import { markdownBody, repoRef, title } from "~/lib/validation";
import type { RepoRow } from "~/lib/types";
export const createPull = createServerFn({ method: "POST" })
.middleware([viewerMiddleware])
.validator(
repoRef.extend({
base: z.string().min(1),
head: z.string().min(1),
title,
body: markdownBody,
draft: z.boolean().default(false),
}),
)
.handler(async ({ data, context }) => {