import { Banner, Button, Input, InputArea, LayerCard } from "@refs/design-system"; import { ArrowLeftIcon, GitPullRequestIcon } from "@refs/design-system/icons"; import { MAX_BODY_LENGTH, MAX_TITLE_LENGTH, pullLink, refsErrorCode, refsErrorDescription } from "@refs/backend/contract"; import { Form, redirect, useSubmit } from "react-router"; import type { Route } from "./+types/repo-compare"; import { DiffView } from "../components/diff-view"; import { failed, formText, found, signedIn, fullName } from "../lib/session"; export const meta: Route.MetaFunction = ({ params }) => [{ title: `Open a pull request · ${fullName(params)} · refs` }]; export async function loader({ request, params, context }: Route.LoaderArgs) { const search = new URL(request.url).searchParams; const repo = await found(signedIn(context).repo(fullName(params))); const refs = await found(repo.refs()); const base = search.get("base") || refs.defaultRef || refs.branches[0] || ""; const head = search.get("head") || ""; let changes = null; let problem: string | null = null; if (base && head && base !== head) { changes = await repo.compare(base, head).catch((error: unknown) => { if (refsErrorCode(error) !== "not_found") throw error; problem = refsErrorDescription(error); return null; }); } return { repo: fullName(params), branches: refs.branches, base, head, changes, problem }; } export async function action({ request, params, context }: Route.ActionArgs) { const repo = await found(signedIn(context).repo(fullName(params))); const form = await request.formData(); const outcome = await repo.openPull({ title: formText(form, "title"), body: formText(form, "body"), base: formText(form, "base"), head: formText(form, "head") }); return outcome.ok ? redirect(`${pullLink(fullName(params), outcome.value.number)}/reasoning`) : failed(outcome.problem, {}); } function BranchSelect({ name, label, value, branches }: { name: string; label: string; value: string; branches: readonly string[] }) { return ( ); } export default function RepoCompare({ loaderData, actionData }: Route.ComponentProps) { const { branches, base, head, changes, problem } = loaderData; const submit = useSubmit(); const empty = changes !== null && changes.commits.length === 0; return (
Choose the branch to merge and the branch it merges into.
{changes.commits.length} {changes.commits.length === 1 ? "commit" : "commits"} · {changes.files.length} {changes.files.length === 1 ? "file" : "files"} changed ·{" "} +{changes.additions} −{changes.deletions}