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