Skip to content

Commit d7f8af2

Browse files
fix types
1 parent 94877de commit d7f8af2

15 files changed

Lines changed: 72 additions & 69 deletions

File tree

packages/backend/src/constants.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1+
import { CodeHostType } from "@sourcebot/db";
12
import { env } from "./env.js";
23
import path from "path";
34

45
export const SINGLE_TENANT_ORG_ID = 1;
56

67
export const PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES = [
7-
'github',
8-
'gitlab',
8+
CodeHostType.github,
9+
CodeHostType.gitlab,
910
];
1011

1112
export const REPOS_CACHE_DIR = path.join(env.DATA_CACHE_DIR, 'repos');

packages/backend/src/repoCompileUtils.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { BitbucketRepository, getBitbucketReposFromConfig } from "./bitbucket.js
77
import { getAzureDevOpsReposFromConfig } from "./azuredevops.js";
88
import { SchemaRestRepository as BitbucketServerRepository } from "@coderabbitai/bitbucket/server/openapi";
99
import { SchemaRepository as BitbucketCloudRepository } from "@coderabbitai/bitbucket/cloud/openapi";
10-
import { Prisma, PrismaClient } from '@sourcebot/db';
10+
import { CodeHostType, Prisma, PrismaClient } from '@sourcebot/db';
1111
import { WithRequired } from "./types.js"
1212
import { marshalBool } from "./utils.js";
1313
import { createLogger } from '@sourcebot/logger';
@@ -392,7 +392,7 @@ export const compileBitbucketConfig = async (
392392

393393
const repos = bitbucketRepos.map((repo) => {
394394
const isServer = config.deploymentType === 'server';
395-
const codeHostType = isServer ? 'bitbucket-server' : 'bitbucket-cloud'; // zoekt expects bitbucket-server
395+
const codeHostType: CodeHostType = isServer ? 'bitbucketServer' : 'bitbucketCloud';
396396
const displayName = isServer ? (repo as BitbucketServerRepository).name! : (repo as BitbucketCloudRepository).full_name!;
397397
const externalId = isServer ? (repo as BitbucketServerRepository).id!.toString() : (repo as BitbucketCloudRepository).uuid!;
398398
const isPublic = isServer ? (repo as BitbucketServerRepository).public : (repo as BitbucketCloudRepository).is_private === false;
@@ -425,7 +425,8 @@ export const compileBitbucketConfig = async (
425425
},
426426
metadata: {
427427
gitConfig: {
428-
'zoekt.web-url-type': codeHostType,
428+
// zoekt expects bitbucket-server and bitbucket-cloud
429+
'zoekt.web-url-type': codeHostType === 'bitbucketServer' ? 'bitbucket-server' : 'bitbucket-cloud',
429430
'zoekt.web-url': webUrl,
430431
'zoekt.name': repoName,
431432
'zoekt.archived': marshalBool(isArchived),
@@ -507,7 +508,7 @@ export const compileGenericGitHostConfig_file = async (
507508
const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, ''));
508509

509510
const repo: RepoData = {
510-
external_codeHostType: 'generic-git-host',
511+
external_codeHostType: 'genericGitHost',
511512
external_codeHostUrl: remoteUrl.resource,
512513
external_id: remoteUrl.toString(),
513514
cloneUrl: `file://${repoPath}`,
@@ -571,7 +572,7 @@ export const compileGenericGitHostConfig_url = async (
571572
const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, ''));
572573

573574
const repo: RepoData = {
574-
external_codeHostType: 'generic-git-host',
575+
external_codeHostType: 'genericGitHost',
575576
external_codeHostUrl: remoteUrl.origin,
576577
external_id: remoteUrl.toString(),
577578
cloneUrl: remoteUrl.toString(),

packages/backend/src/utils.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ export const getRepoPath = (repo: Repo): { path: string, isReadOnly: boolean } =
5959
// If we are dealing with a local repository, then use that as the path.
6060
// Mark as read-only since we aren't guaranteed to have write access to the local filesystem.
6161
const cloneUrl = new URL(repo.cloneUrl);
62-
if (repo.external_codeHostType === 'generic-git-host' && cloneUrl.protocol === 'file:') {
62+
if (repo.external_codeHostType === 'genericGitHost' && cloneUrl.protocol === 'file:') {
6363
return {
6464
path: cloneUrl.pathname,
6565
isReadOnly: true,

packages/web/src/app/[domain]/chat/components/demoCards.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ import { Badge } from "@/components/ui/badge";
77
import { Card } from "@/components/ui/card";
88
import { CardContent } from "@/components/ui/card";
99
import { DemoExamples, DemoSearchExample, DemoSearchScope } from "@/types";
10-
import { cn, CodeHostType, getCodeHostIcon } from "@/lib/utils";
10+
import { cn, getCodeHostIcon } from "@/lib/utils";
1111
import useCaptureEvent from "@/hooks/useCaptureEvent";
1212
import { SearchScopeInfoCard } from "@/features/chat/components/chatBox/searchScopeInfoCard";
13+
import { CodeHostType } from "@sourcebot/db";
1314

1415
interface DemoCards {
1516
demoExamples: DemoExamples;

packages/web/src/app/[domain]/components/configEditor.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@ import { Separator } from "@/components/ui/separator";
1212
import { Schema } from "ajv";
1313
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from "@/components/ui/tooltip";
1414
import useCaptureEvent from "@/hooks/useCaptureEvent";
15-
import { CodeHostType } from "@/lib/utils";
1615
import { useCodeMirrorTheme } from "@/hooks/useCodeMirrorTheme";
16+
import { CodeHostType } from "@sourcebot/db";
1717

1818
export type QuickActionFn<T> = (previous: T) => T;
1919
export type QuickAction<T> = {

packages/web/src/app/[domain]/components/importSecretDialog.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,11 @@ import { Input } from "@/components/ui/input";
99
import { Separator } from "@/components/ui/separator";
1010
import useCaptureEvent from "@/hooks/useCaptureEvent";
1111
import { useDomain } from "@/hooks/useDomain";
12-
import { CodeHostType, isServiceError } from "@/lib/utils";
12+
import { isServiceError } from "@/lib/utils";
1313
import githubPatCreation from "@/public/github_pat_creation.png";
1414
import gitlabPatCreation from "@/public/gitlab_pat_creation.png";
1515
import giteaPatCreation from "@/public/gitea_pat_creation.png";
16+
import { CodeHostType } from "@sourcebot/db";
1617
import { zodResolver } from "@hookform/resolvers/zod";
1718
import { Eye, EyeOff, Loader2 } from "lucide-react";
1819
import Image from "next/image";
@@ -88,9 +89,9 @@ export const ImportSecretDialog = ({ open, onOpenChange, onSecretCreated, codeHo
8889
return <GitHubPATCreationStep step={1} />;
8990
case 'gitlab':
9091
return <GitLabPATCreationStep step={1} />;
91-
case 'bitbucket-cloud':
92+
case 'bitbucketCloud':
9293
return <BitbucketCloudPATCreationStep step={1} />;
93-
case 'bitbucket-server':
94+
case 'bitbucketServer':
9495
return <BitbucketServerPATCreationStep step={1} />;
9596
case 'gitea':
9697
return <GiteaPATCreationStep step={1} />;

packages/web/src/app/[domain]/repos/components/repoBranchesTable.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,14 @@ import {
1515
import { Button } from "@/components/ui/button"
1616
import { Input } from "@/components/ui/input"
1717
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
18-
import { CodeHostType, getCodeHostBrowseAtBranchUrl } from "@/lib/utils"
18+
import { getCodeHostBrowseAtBranchUrl } from "@/lib/utils"
1919
import Link from "next/link"
20+
import { CodeHostType } from "@sourcebot/db";
2021

2122
type RepoBranchesTableProps = {
2223
indexRevisions: string[];
2324
repoWebUrl: string | null;
24-
repoCodeHostType: string;
25+
repoCodeHostType: CodeHostType;
2526
}
2627

2728
export const RepoBranchesTable = ({ indexRevisions, repoWebUrl, repoCodeHostType }: RepoBranchesTableProps) => {
@@ -39,7 +40,7 @@ export const RepoBranchesTable = ({ indexRevisions, repoWebUrl, repoCodeHostType
3940

4041
const branchUrl = getCodeHostBrowseAtBranchUrl({
4142
webUrl: repoWebUrl,
42-
codeHostType: repoCodeHostType as CodeHostType,
43+
codeHostType: repoCodeHostType,
4344
branchName: refName,
4445
});
4546

packages/web/src/app/[domain]/repos/components/reposTable.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import { Input } from "@/components/ui/input"
1414
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"
1515
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
1616
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
17-
import { cn, CodeHostType, getCodeHostCommitUrl, getCodeHostIcon, getCodeHostInfoForRepo, getRepoImageSrc } from "@/lib/utils"
17+
import { cn, getCodeHostCommitUrl, getCodeHostIcon, getCodeHostInfoForRepo, getRepoImageSrc } from "@/lib/utils"
1818
import {
1919
type ColumnDef,
2020
type ColumnFiltersState,
@@ -38,6 +38,7 @@ import { useToast } from "@/components/hooks/use-toast";
3838
import { DisplayDate } from "../../components/DisplayDate"
3939
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
4040
import { NotificationDot } from "../../components/notificationDot"
41+
import { CodeHostType } from "@sourcebot/db"
4142

4243
// @see: https://v0.app/chat/repo-indexing-status-uhjdDim8OUS
4344

@@ -50,7 +51,7 @@ export type Repo = {
5051
indexedAt: Date | null
5152
createdAt: Date
5253
webUrl: string | null
53-
codeHostType: string
54+
codeHostType: CodeHostType
5455
imageUrl: string | null
5556
indexedCommitHash: string | null
5657
latestJobStatus: "PENDING" | "IN_PROGRESS" | "COMPLETED" | "FAILED" | null
@@ -97,7 +98,7 @@ export const columns: ColumnDef<Repo>[] = [
9798
},
9899
cell: ({ row }) => {
99100
const repo = row.original;
100-
const codeHostIcon = getCodeHostIcon(repo.codeHostType as CodeHostType);
101+
const codeHostIcon = getCodeHostIcon(repo.codeHostType);
101102
const repoImageSrc = repo.imageUrl ? getRepoImageSrc(repo.imageUrl, repo.id) : undefined;
102103

103104
return (
@@ -192,7 +193,7 @@ export const columns: ColumnDef<Repo>[] = [
192193

193194
const smallHash = hash.slice(0, 7);
194195
const repo = row.original;
195-
const codeHostType = repo.codeHostType as CodeHostType;
196+
const codeHostType = repo.codeHostType;
196197
const webUrl = repo.webUrl;
197198

198199
const commitUrl = getCodeHostCommitUrl({

packages/web/src/app/[domain]/settings/connections/[id]/page.tsx

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip
77
import { env } from "@/env.mjs";
88
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants";
99
import { notFound, ServiceErrorException } from "@/lib/serviceError";
10-
import { CodeHostType, isServiceError } from "@/lib/utils";
10+
import { isServiceError } from "@/lib/utils";
1111
import { withAuthV2 } from "@/withAuthV2";
1212
import { AzureDevOpsConnectionConfig, BitbucketConnectionConfig, GenericGitHostConnectionConfig, GerritConnectionConfig, GiteaConnectionConfig, GithubConnectionConfig, GitlabConnectionConfig } from "@sourcebot/schemas/v3/index.type";
1313
import { getConfigSettings } from "@sourcebot/shared";
@@ -47,8 +47,9 @@ export default async function ConnectionDetailPage(props: ConnectionDetailPagePr
4747
return undefined;
4848
})();
4949

50-
const codeHostUrl = (() => {
51-
const connectionType = connection.connectionType as CodeHostType;
50+
// Extracts the code host URL from the connection config.
51+
const codeHostUrl: string = (() => {
52+
const connectionType = connection.connectionType;
5253
switch (connectionType) {
5354
case 'github': {
5455
const config = connection.config as unknown as GithubConnectionConfig;
@@ -66,19 +67,19 @@ export default async function ConnectionDetailPage(props: ConnectionDetailPagePr
6667
const config = connection.config as unknown as GerritConnectionConfig;
6768
return config.url;
6869
}
69-
case 'bitbucket-server': {
70+
case 'bitbucket': {
7071
const config = connection.config as unknown as BitbucketConnectionConfig;
71-
return config.url!;
72-
}
73-
case 'bitbucket-cloud': {
74-
const config = connection.config as unknown as BitbucketConnectionConfig;
75-
return config.url ?? 'https://bitbucket.org';
72+
if (config.deploymentType === 'cloud') {
73+
return config.url ?? 'https://bitbucket.org';
74+
} else {
75+
return config.url!;
76+
}
7677
}
7778
case 'azuredevops': {
7879
const config = connection.config as unknown as AzureDevOpsConnectionConfig;
7980
return config.url ?? 'https://dev.azure.com';
8081
}
81-
case 'generic-git-host': {
82+
case 'git': {
8283
const config = connection.config as unknown as GenericGitHostConnectionConfig;
8384
return config.url;
8485
}

packages/web/src/app/[domain]/settings/connections/components/connectionsTable.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@
1010
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"
1111
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip"
1212
import { SINGLE_TENANT_ORG_DOMAIN } from "@/lib/constants"
13-
import { CodeHostType, getCodeHostIcon } from "@/lib/utils"
13+
import { getCodeHostIcon } from "@/lib/utils"
14+
import { ConnectionType } from "@sourcebot/db"
1415
import {
1516
type ColumnDef,
1617
type ColumnFiltersState,
@@ -35,7 +36,7 @@ export type Connection = {
3536
id: number
3637
name: string
3738
syncedAt: Date | null
38-
codeHostType: CodeHostType
39+
connectionType: ConnectionType
3940
latestJobStatus: "PENDING" | "IN_PROGRESS" | "COMPLETED" | "FAILED" | null
4041
isFirstTimeSync: boolean
4142
}
@@ -80,13 +81,13 @@ export const columns: ColumnDef<Connection>[] = [
8081
},
8182
cell: ({ row }) => {
8283
const connection = row.original;
83-
const codeHostIcon = getCodeHostIcon(connection.codeHostType);
84+
const codeHostIcon = getCodeHostIcon(connection.connectionType);
8485

8586
return (
8687
<div className="flex flex-row gap-2 items-center">
8788
<Image
8889
src={codeHostIcon.src}
89-
alt={`${connection.codeHostType} logo`}
90+
alt={`${connection.connectionType} logo`}
9091
className={codeHostIcon.className}
9192
width={20}
9293
height={20}

0 commit comments

Comments
 (0)