179 lines · 7.0 KB
import { createFileRoute, useNavigate } from "@tanstack/react-router";
import { useState } from "react";
import { getPullConflicts, resolvePullConflicts } from "~/fns/pull-review";
import { useAction } from "~/hooks/use-action";
import { Badge } from "~/ui/Badge";
import { EmptyState } from "~/ui/EmptyState";
import { Panel } from "~/ui/Panel";
import { Button } from "~/ui/Button";
import { inputClass } from "~/ui/Field";
import { ErrorBanner } from "~/ui/Callout";
import { cn } from "~/utils/cn";
import { getPullMergeFix } from "~/fns/mergefix";
import { MergeFixPanel } from "~/components/MergeFixPanel";
import { applyChoices, parseConflictText } from "~/lib/conflict-blocks";
import { panelClass } from "~/ui/Panel";

export const Route = createFileRoute("/$owner/$repo/pull/$number/conflicts")({
  loader: async ({ params }) => {
    const data = { owner: params.owner, repo: params.repo, number: Number(params.number) };
    const [conflicts, mergeFix] = await Promise.all([getPullConflicts({ data }), getPullMergeFix({ data })]);
    return { ...conflicts, mergeFix };
  },
  component: ConflictEditor,
});

const MARKER = /^(<{7}|={7}|>{7})(?: |$)/m;

const KIND_COPY = {
  content: "content",
  add_add: "added on both sides",
  modify_delete: "modified and deleted",
  type: "file type changed",
  binary: "binary file",
} as const;

function LocalInstructions({ baseRef, headRef }: { baseRef: string; headRef: string }) {
  return (
    <pre className="overflow-x-auto rounded-md bg-kumo-base p-3 font-mono text-xs text-kumo-default">
      {`git fetch origin\ngit checkout ${headRef}\ngit merge origin/${baseRef}\n# resolve, then\ngit commit && git push`}
    </pre>