314 lines · 12.0 KB
import { pullInput, requirePull, requirePullMutation } from "~/server/pull-access";
import { withAuthorAccounts } from "~/server/commit-authors";
import { resolveMentions } from "~/server/mentions";
import { limitBrowse, limitHeavy, limitWrite } from "~/server/limits";
import { createServerFn } from "@tanstack/react-start";
import { z } from "zod";
import { requireViewer, viewerMiddleware } from "./middleware";
import { repoDb } from "~/server/scoped-db";
import { loadRepo, repoPermission, requireRepoMutation } from "~/server/repos";
import { branchSha, listRefs } from "~/server/git/refs";
import { withStore } from "~/server/git/store";
import { compareCommits } from "~/server/git/history";
import { checkMergeability, mergeGate } from "~/server/pulls";
import { findForkHead, mergePullRequest, openPull } from "~/server/pull-create";
import { updatePull as updatePullRequest } from "~/server/pull-automation";
import { pullDiff } from "~/server/pull-files";
import { parseSuggestion } from "~/server/suggestions";
import { pullAutomation } from "~/server/merge-queue";
import { listLinkedIssues } from "~/server/pull-links";
import { loadStack, stackParent } from "~/server/stacks";
import { listCommitStatuses, combinedState } from "~/server/statuses";
import { accountOrGhost, accountsById } from "~/server/people";
import { renderMarkdown } from "~/server/markdown";
import { reactionSummaries } from "~/server/reactions";
import { 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 }) => {