mirror of
https://github.com/sourcebot-dev/sourcebot.git
synced 2025-12-11 20:05:25 +00:00
improved types
This commit is contained in:
parent
d7f8af20b0
commit
276a802a1e
10 changed files with 38 additions and 57 deletions
|
|
@ -52,7 +52,7 @@ export const CodePreviewPanel = async ({ path, repoName, revisionName }: CodePre
|
|||
branchDisplayName={revisionName}
|
||||
/>
|
||||
|
||||
{(fileWebUrl && codeHostInfo) && (
|
||||
{fileWebUrl && (
|
||||
|
||||
<a
|
||||
href={fileWebUrl}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
|
|||
import { RepositoryQuery } from "@/lib/types";
|
||||
import { getCodeHostInfoForRepo, getShortenedNumberDisplayString } from "@/lib/utils";
|
||||
import clsx from "clsx";
|
||||
import { FileIcon, Loader2Icon, RefreshCwIcon } from "lucide-react";
|
||||
import { Loader2Icon, RefreshCwIcon } from "lucide-react";
|
||||
import Image from "next/image";
|
||||
import Link from "next/link";
|
||||
import { useRouter } from "next/navigation";
|
||||
|
|
@ -90,23 +90,14 @@ const RepoItem = ({ repo }: { repo: RepositoryQuery }) => {
|
|||
webUrl: repo.webUrl,
|
||||
});
|
||||
|
||||
if (info) {
|
||||
return {
|
||||
repoIcon: <Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>,
|
||||
displayName: info.displayName,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
repoIcon: <FileIcon className="w-4 h-4" />,
|
||||
displayName: repo.repoName,
|
||||
repoIcon: <Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>,
|
||||
displayName: info.displayName,
|
||||
}
|
||||
|
||||
|
||||
}, [repo.repoName, repo.codeHostType, repo.repoDisplayName, repo.webUrl]);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
'use client';
|
||||
|
||||
import { cn, getCodeHostInfoForRepo } from "@/lib/utils";
|
||||
import { LaptopIcon } from "@radix-ui/react-icons";
|
||||
import Image from "next/image";
|
||||
import { getBrowsePath } from "../browse/hooks/utils";
|
||||
import { ChevronRight, MoreHorizontal } from "lucide-react";
|
||||
|
|
@ -17,6 +16,7 @@ import { VscodeFileIcon } from "@/app/components/vscodeFileIcon";
|
|||
import { CopyIconButton } from "./copyIconButton";
|
||||
import Link from "next/link";
|
||||
import { useDomain } from "@/hooks/useDomain";
|
||||
import { CodeHostType } from "@sourcebot/db";
|
||||
|
||||
interface FileHeaderProps {
|
||||
path: string;
|
||||
|
|
@ -27,7 +27,7 @@ interface FileHeaderProps {
|
|||
pathType?: 'blob' | 'tree';
|
||||
repo: {
|
||||
name: string;
|
||||
codeHostType: string;
|
||||
codeHostType: CodeHostType;
|
||||
displayName?: string;
|
||||
webUrl?: string;
|
||||
},
|
||||
|
|
@ -202,17 +202,13 @@ export const PathHeader = ({
|
|||
<div className="flex flex-row gap-2 items-center w-full overflow-hidden">
|
||||
{isCodeHostIconVisible && (
|
||||
<>
|
||||
{info?.icon ? (
|
||||
<a href={info.repoLink} target="_blank" rel="noopener noreferrer">
|
||||
<Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>
|
||||
</a>
|
||||
) : (
|
||||
<LaptopIcon className="w-4 h-4" />
|
||||
)}
|
||||
<a href={info.repoLink} target="_blank" rel="noopener noreferrer">
|
||||
<Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>
|
||||
</a>
|
||||
</>
|
||||
)}
|
||||
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ import {
|
|||
import { captureEvent } from "@/hooks/useCaptureEvent";
|
||||
import { RepositoryQuery } from "@/lib/types";
|
||||
import { getCodeHostInfoForRepo } from "@/lib/utils";
|
||||
import { FileIcon } from "@radix-ui/react-icons";
|
||||
import clsx from "clsx";
|
||||
import Autoscroll from "embla-carousel-auto-scroll";
|
||||
import Image from "next/image";
|
||||
|
|
@ -121,20 +120,13 @@ const RepositoryBadge = ({
|
|||
webUrl: repo.webUrl,
|
||||
});
|
||||
|
||||
if (info) {
|
||||
return {
|
||||
repoIcon: <Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>,
|
||||
displayName: info.displayName,
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
repoIcon: <FileIcon className="w-4 h-4" />,
|
||||
displayName: repo.repoName,
|
||||
repoIcon: <Image
|
||||
src={info.icon}
|
||||
alt={info.codeHostName}
|
||||
className={`w-4 h-4 ${info.iconClassName}`}
|
||||
/>,
|
||||
displayName: info.displayName,
|
||||
}
|
||||
})();
|
||||
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ export default async function RepoDetailPage({ params }: { params: Promise<{ id:
|
|||
<h1 className="text-3xl font-semibold">{repo.displayName || repo.name}</h1>
|
||||
<p className="text-muted-foreground mt-2">{repo.name}</p>
|
||||
</div>
|
||||
{(codeHostInfo && codeHostInfo.repoLink) && (
|
||||
{codeHostInfo.repoLink && (
|
||||
<Button variant="outline" asChild>
|
||||
<Link href={codeHostInfo.repoLink} target="_blank" rel="noopener noreferrer" className="flex items-center">
|
||||
<Image
|
||||
|
|
|
|||
|
|
@ -253,7 +253,7 @@ export const columns: ColumnDef<Repo>[] = [
|
|||
<DropdownMenuItem asChild>
|
||||
<Link href={`/${SINGLE_TENANT_ORG_DOMAIN}/repos/${repo.id}`}>View details</Link>
|
||||
</DropdownMenuItem>
|
||||
{(repo.webUrl && codeHostInfo) && (
|
||||
{repo.webUrl && (
|
||||
<>
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem asChild>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { createCodeFoldingExtension } from "./codeFoldingExtension";
|
|||
import useCaptureEvent from "@/hooks/useCaptureEvent";
|
||||
import { createAuditAction } from "@/ee/features/audit/actions";
|
||||
import { useDomain } from "@/hooks/useDomain";
|
||||
import { CodeHostType } from "@sourcebot/db";
|
||||
|
||||
const lineDecoration = Decoration.line({
|
||||
attributes: { class: "cm-range-border-radius chat-lineHighlight" },
|
||||
|
|
@ -40,7 +41,7 @@ interface ReferencedFileSourceListItemProps {
|
|||
language: string;
|
||||
revision: string;
|
||||
repoName: string;
|
||||
repoCodeHostType: string;
|
||||
repoCodeHostType: CodeHostType;
|
||||
repoDisplayName?: string;
|
||||
repoWebUrl?: string;
|
||||
fileName: string;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
// @NOTE : Please keep this file in sync with @sourcebot/mcp/src/schemas.ts
|
||||
import { CodeHostType } from "@sourcebot/db";
|
||||
import { z } from "zod";
|
||||
|
||||
export const locationSchema = z.object({
|
||||
|
|
@ -33,7 +34,7 @@ export const searchRequestSchema = z.object({
|
|||
|
||||
export const repositoryInfoSchema = z.object({
|
||||
id: z.number(),
|
||||
codeHostType: z.string(),
|
||||
codeHostType: z.nativeEnum(CodeHostType),
|
||||
name: z.string(),
|
||||
displayName: z.string().optional(),
|
||||
webUrl: z.string().optional(),
|
||||
|
|
@ -153,7 +154,7 @@ export const fileSourceResponseSchema = z.object({
|
|||
language: z.string(),
|
||||
path: z.string(),
|
||||
repository: z.string(),
|
||||
repositoryCodeHostType: z.string(),
|
||||
repositoryCodeHostType: z.nativeEnum(CodeHostType),
|
||||
repositoryDisplayName: z.string().optional(),
|
||||
repositoryWebUrl: z.string().optional(),
|
||||
branch: z.string().optional(),
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ import { checkIfOrgDomainExists } from "@/actions";
|
|||
import { z } from "zod";
|
||||
import { isServiceError } from "./utils";
|
||||
import { serviceErrorSchema } from "./serviceError";
|
||||
import { CodeHostType } from "@sourcebot/db";
|
||||
|
||||
export const secretCreateRequestSchema = z.object({
|
||||
key: z.string(),
|
||||
|
|
@ -13,7 +14,7 @@ export const secreteDeleteRequestSchema = z.object({
|
|||
});
|
||||
|
||||
export const repositoryQuerySchema = z.object({
|
||||
codeHostType: z.string(),
|
||||
codeHostType: z.nativeEnum(CodeHostType),
|
||||
repoId: z.number(),
|
||||
repoName: z.string(),
|
||||
repoDisplayName: z.string().optional(),
|
||||
|
|
|
|||
|
|
@ -174,11 +174,11 @@ type CodeHostInfo = {
|
|||
}
|
||||
|
||||
export const getCodeHostInfoForRepo = (repo: {
|
||||
codeHostType: string,
|
||||
codeHostType: CodeHostType,
|
||||
name: string,
|
||||
displayName?: string,
|
||||
webUrl?: string,
|
||||
}): CodeHostInfo | undefined => {
|
||||
}): CodeHostInfo => {
|
||||
const { codeHostType, name, displayName, webUrl } = repo;
|
||||
|
||||
switch (codeHostType) {
|
||||
|
|
@ -226,8 +226,7 @@ export const getCodeHostInfoForRepo = (repo: {
|
|||
iconClassName: className,
|
||||
}
|
||||
}
|
||||
case 'gerrit':
|
||||
case 'gitiles': {
|
||||
case 'gerrit': {
|
||||
const { src, className } = getCodeHostIcon('gerrit')!;
|
||||
return {
|
||||
type: "gerrit",
|
||||
|
|
@ -238,7 +237,7 @@ export const getCodeHostInfoForRepo = (repo: {
|
|||
iconClassName: className,
|
||||
}
|
||||
}
|
||||
case "bitbucket-server": {
|
||||
case "bitbucketServer": {
|
||||
const { src, className } = getCodeHostIcon('bitbucketServer')!;
|
||||
return {
|
||||
type: "bitbucketServer",
|
||||
|
|
@ -249,7 +248,7 @@ export const getCodeHostInfoForRepo = (repo: {
|
|||
iconClassName: className,
|
||||
}
|
||||
}
|
||||
case "bitbucket-cloud": {
|
||||
case "bitbucketCloud": {
|
||||
const { src, className } = getCodeHostIcon('bitbucketCloud')!;
|
||||
return {
|
||||
type: "bitbucketCloud",
|
||||
|
|
@ -260,7 +259,7 @@ export const getCodeHostInfoForRepo = (repo: {
|
|||
iconClassName: className,
|
||||
}
|
||||
}
|
||||
case "generic-git-host": {
|
||||
case "genericGitHost": {
|
||||
const { src, className } = getCodeHostIcon('genericGitHost')!;
|
||||
return {
|
||||
type: "genericGitHost",
|
||||
|
|
|
|||
Loading…
Reference in a new issue