Skip to content

Commit f49df78

Browse files
committed
merge main
2 parents 43662bc + 581a5a0 commit f49df78

File tree

25 files changed

+169
-123
lines changed

25 files changed

+169
-123
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1414
- [ask sb] Fixed issue where reasoning tokens would appear in `text` content for openai compatible models. [#582](https://github.com/sourcebot-dev/sourcebot/pull/582)
1515
- Fixed issue with GitHub app token tracking and refreshing. [#583](https://github.com/sourcebot-dev/sourcebot/pull/583)
1616
- Fixed "The account is already associated with another user" errors with GitLab oauth provider. [#584](https://github.com/sourcebot-dev/sourcebot/pull/584)
17+
- Fixed error when viewing a generic git connection in `/settings/connections`. [#588](https://github.com/sourcebot-dev/sourcebot/pull/588)
1718

1819
## Removed
1920
- Removed built-in secret manager. [#592](https://github.com/sourcebot-dev/sourcebot/pull/592)

packages/backend/src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
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

6-
export const PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES = [
7+
export const PERMISSION_SYNC_SUPPORTED_CODE_HOST_TYPES: CodeHostType[] = [
78
'github',
89
'gitlab',
910
];

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 } from '@sourcebot/db';
10+
import { CodeHostType, Prisma } from '@sourcebot/db';
1111
import { WithRequired } from "./types.js"
1212
import { marshalBool } from "./utils.js";
1313
import { createLogger } from '@sourcebot/logger';
@@ -384,7 +384,7 @@ export const compileBitbucketConfig = async (
384384

385385
const repos = bitbucketRepos.map((repo) => {
386386
const isServer = config.deploymentType === 'server';
387-
const codeHostType = isServer ? 'bitbucket-server' : 'bitbucket-cloud'; // zoekt expects bitbucket-server
387+
const codeHostType: CodeHostType = isServer ? 'bitbucketServer' : 'bitbucketCloud';
388388
const displayName = isServer ? (repo as BitbucketServerRepository).name! : (repo as BitbucketCloudRepository).full_name!;
389389
const externalId = isServer ? (repo as BitbucketServerRepository).id!.toString() : (repo as BitbucketCloudRepository).uuid!;
390390
const isPublic = isServer ? (repo as BitbucketServerRepository).public : (repo as BitbucketCloudRepository).is_private === false;
@@ -417,7 +417,8 @@ export const compileBitbucketConfig = async (
417417
},
418418
metadata: {
419419
gitConfig: {
420-
'zoekt.web-url-type': codeHostType,
420+
// zoekt expects bitbucket-server and bitbucket-cloud
421+
'zoekt.web-url-type': codeHostType === 'bitbucketServer' ? 'bitbucket-server' : 'bitbucket-cloud',
421422
'zoekt.web-url': webUrl,
422423
'zoekt.name': repoName,
423424
'zoekt.archived': marshalBool(isArchived),
@@ -497,7 +498,7 @@ export const compileGenericGitHostConfig_file = async (
497498
const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, ''));
498499

499500
const repo: RepoData = {
500-
external_codeHostType: 'generic-git-host',
501+
external_codeHostType: 'genericGitHost',
501502
external_codeHostUrl: remoteUrl.resource,
502503
external_id: remoteUrl.toString(),
503504
cloneUrl: `file://${repoPath}`,
@@ -560,7 +561,7 @@ export const compileGenericGitHostConfig_url = async (
560561
const repoName = path.join(remoteUrl.host, remoteUrl.pathname.replace(/\.git$/, ''));
561562

562563
const repo: RepoData = {
563-
external_codeHostType: 'generic-git-host',
564+
external_codeHostType: 'genericGitHost',
564565
external_codeHostUrl: remoteUrl.origin,
565566
external_id: remoteUrl.toString(),
566567
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,
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
Migrates the `connectionType` column from text to a enum. The values in this field are known to
3+
be one of the following: github, gitlab, gitea, gerrit, bitbucket, azuredevops, git.
4+
5+
This is occording to what we would expect to be in a valid config file for the schema version at commit 4899c9fbc755851af2ddcce99f4a4200f2faa4f6.
6+
See: https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/schemas/src/v3/connection.type.ts#L3
7+
*/
8+
-- CreateEnum
9+
CREATE TYPE "ConnectionType" AS ENUM ('github', 'gitlab', 'gitea', 'gerrit', 'bitbucket', 'azuredevops', 'git');
10+
11+
-- AlterTable - Convert existing column to enum type without dropping data
12+
ALTER TABLE "Connection"
13+
ALTER COLUMN "connectionType" TYPE "ConnectionType"
14+
USING "connectionType"::text::"ConnectionType";
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Migrates the `external_codeHostType` column from text to a enum. The values in this field are known to
3+
be one of the following: github, gitlab, gitea, gerrit, bitbucket-server, bitbucket-cloud, generic-git-host, azuredevops.
4+
5+
This is occording to what we would expect to be in the database written as of commit 4899c9fbc755851af2ddcce99f4a4200f2faa4f6.
6+
See:
7+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L57
8+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L135
9+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L208
10+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L291
11+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L407
12+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L510
13+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L574
14+
- https://github.com/sourcebot-dev/sourcebot/blob/4899c9fbc755851af2ddcce99f4a4200f2faa4f6/packages/backend/src/repoCompileUtils.ts#L642
15+
*/
16+
-- CreateEnum
17+
CREATE TYPE "CodeHostType" AS ENUM ('github', 'gitlab', 'gitea', 'gerrit', 'bitbucket-server', 'bitbucket-cloud', 'generic-git-host', 'azuredevops');
18+
19+
-- AlterTable - Convert existing column to enum type without dropping data
20+
ALTER TABLE "Repo"
21+
ALTER COLUMN "external_codeHostType" TYPE "CodeHostType"
22+
USING "external_codeHostType"::text::"CodeHostType";

packages/db/prisma/schema.prisma

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ enum ChatVisibility {
2929
PUBLIC
3030
}
3131

32+
/// @note: The @map annotation is required to maintain backwards compatibility
33+
/// with the existing database.
34+
/// @note: In the generated client, these mapped values will be in pascalCase.
35+
/// This behaviour will change in prisma v7. See: https://github.com/prisma/prisma/issues/8446#issuecomment-3356119713
36+
enum CodeHostType {
37+
github
38+
gitlab
39+
gitea
40+
gerrit
41+
bitbucketServer @map("bitbucket-server")
42+
bitbucketCloud @map("bitbucket-cloud")
43+
genericGitHost @map("generic-git-host")
44+
azuredevops
45+
}
46+
3247
model Repo {
3348
id Int @id @default(autoincrement())
3449
name String /// Full repo name, including the vcs hostname (ex. github.com/sourcebot-dev/sourcebot)
@@ -53,7 +68,7 @@ model Repo {
5368
indexedCommitHash String? /// The commit hash of the last indexed commit (on HEAD).
5469
5570
external_id String /// The id of the repo in the external service
56-
external_codeHostType String /// The type of the external service (e.g., github, gitlab, etc.)
71+
external_codeHostType CodeHostType /// The type of the external service (e.g., github, gitlab, etc.)
5772
external_codeHostUrl String /// The base url of the external service (e.g., https://github.com)
5873
5974
org Org @relation(fields: [orgId], references: [id], onDelete: Cascade)
@@ -125,6 +140,18 @@ model SearchContext {
125140
@@unique([name, orgId])
126141
}
127142

143+
/// Matches the union of `type` fields in the schema.
144+
/// @see: schemas/v3/connection.type.ts
145+
enum ConnectionType {
146+
github
147+
gitlab
148+
gitea
149+
gerrit
150+
bitbucket
151+
azuredevops
152+
git
153+
}
154+
128155
model Connection {
129156
id Int @id @default(autoincrement())
130157
name String
@@ -135,7 +162,7 @@ model Connection {
135162
repos RepoToConnection[]
136163
137164
// The type of connection (e.g., github, gitlab, etc.)
138-
connectionType String
165+
connectionType ConnectionType
139166
140167
syncJobs ConnectionSyncJob[]
141168
/// When the connection was last synced successfully.

packages/web/src/app/[domain]/browse/[...path]/components/codePreviewPanel.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export const CodePreviewPanel = async ({ path, repoName, revisionName }: CodePre
5252
branchDisplayName={revisionName}
5353
/>
5454

55-
{(fileWebUrl && codeHostInfo) && (
55+
{fileWebUrl && (
5656

5757
<a
5858
href={fileWebUrl}

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> = {

0 commit comments

Comments
 (0)