import { getRepoInfoByName } from "@/actions"; import { PathHeader } from "@/app/[domain]/components/pathHeader"; import { Separator } from "@/components/ui/separator"; import { getFileSource } from "@/features/search/fileSourceApi"; import { cn, getCodeHostInfoForRepo, isServiceError } from "@/lib/utils"; import Image from "next/image"; import { PureCodePreviewPanel } from "./pureCodePreviewPanel"; interface CodePreviewPanelProps { path: string; repoName: string; revisionName?: string; } export const CodePreviewPanel = async ({ path, repoName, revisionName }: CodePreviewPanelProps) => { const [fileSourceResponse, repoInfoResponse] = await Promise.all([ getFileSource({ fileName: path, repository: repoName, branch: revisionName, }), getRepoInfoByName(repoName), ]); if (isServiceError(fileSourceResponse) || isServiceError(repoInfoResponse)) { return
Error loading file source
} const codeHostInfo = getCodeHostInfoForRepo({ codeHostType: repoInfoResponse.codeHostType, name: repoInfoResponse.name, displayName: repoInfoResponse.displayName, webUrl: repoInfoResponse.webUrl, }); // @todo: this is a hack to support linking to files for ADO. ADO doesn't support web urls with HEAD so we replace it with main. THis // will break if the default branch is not main. const fileWebUrl = repoInfoResponse.codeHostType === "azuredevops" && fileSourceResponse.webUrl ? fileSourceResponse.webUrl.replace("version=GBHEAD", "version=GBmain") : fileSourceResponse.webUrl; return ( <>
{fileWebUrl && ( {codeHostInfo.codeHostName} Open in {codeHostInfo.codeHostName} )}
) }