import { Link } from "@tanstack/react-router"; import { setAutoMerge, setMergeQueue, updatePullBranch } from "~/fns/pull-review"; import { useAction } from "~/hooks/use-action"; import { Badge } from "~/ui/Badge"; import { Button } from "~/ui/Button"; import { ErrorBanner } from "~/ui/Callout"; import type { usePull } from "~/hooks/use-pull"; type PullData = ReturnType; type Props = { owner: string; repo: string; data: PullData; method: "merge" | "squash" | "rebase"; }; /** Update-branch, conflict resolution, auto-merge and merge-queue controls that sit in the merge box. */ export function MergeAutomation({ owner, repo, data, method }: Props) { const { pull } = data; const number = pull.number; const update = useAction(updatePullBranch); const auto = useAction(setAutoMerge); const queue = useAction(setMergeQueue); const conflicted = pull.mergeable === "conflict"; return (
{data.canPushHead && (data.canUpdateBranch || conflicted) && (
{conflicted ? "Merging the base branch into this branch has conflicts." : `This branch is ${pull.behindBy} commit${pull.behindBy === 1 ? "" : "s"} behind ${pull.baseRef}.`} {conflicted && ( Resolve conflicts )} {!conflicted && ( )}
)} {data.canMerge && (
{data.autoMerge ? ( <> Auto-merge enabled by {data.autoMerge.enabledBy.name} ({data.autoMerge.method}); merges once requirements pass ) : ( !data.gate.allowed && ( ) )} {data.queue ? ( <> Queued #{data.queue.position} {data.queue.state === "testing" ? " ยท testing" : ""} ) : ( method !== "rebase" && !pull.draft && ( ) )}
)}
); }