import { syncForkAction } from "@/app/actions/forks"; import type { ForkStatus } from "@/lib/forks"; import { ActionButton } from "./action-button"; import { ForkIcon, PullRequestIcon } from "./icons"; import { Box, ButtonLink, RefChip } from "./ui"; const commits = (n: number) => `${n} commit${n === 1 ? "" : "s"}`; /** On a fork's front page: how its default branch compares with the original's, with Sync and Contribute. */ export function ForkStatusBar({ fork, status, canWrite }: { fork: { owner: string; name: string }; status: ForkStatus; canWrite: boolean }) { const upstream = `${status.upstream.owner}/${status.upstream.name}`; const compare = `/${upstream}/compare?${new URLSearchParams({ base: status.upstreamBranch, head_repo: `${fork.owner}/${fork.name}`, head: status.branch })}`; const where = {`${upstream}:${status.upstreamBranch}`}; return ( {status.ahead === 0 && status.behind === 0 ? ( <>This branch is up to date with {where}.> ) : ( <> This branch is {status.ahead > 0 && {commits(status.ahead)} ahead of} {status.ahead > 0 && status.behind > 0 && "and"} {status.behind > 0 && {commits(status.behind)} behind} {where}. > )} {status.ahead > 0 && ( }> Contribute )} {canWrite && status.behind > 0 && ( }> Sync Fork )} ); }