Skip to content

Commit aea39c6

Browse files
committed
misc cleanups and fix ui issues with bitbucket connections
1 parent 44ce5bc commit aea39c6

File tree

13 files changed

+96
-33
lines changed

13 files changed

+96
-33
lines changed

packages/backend/src/repoCompileUtils.ts

+9-4
Original file line numberDiff line numberDiff line change
@@ -337,15 +337,20 @@ export const compileBitbucketConfig = async (
337337
throw new Error(`No clone links found for server repo ${repo.name}`);
338338
}
339339

340+
// In the cloud case we simply fetch the html link and use that as the clone url. For server we
341+
// need to fetch the actual clone url
342+
if (config.deploymentType === 'cloud') {
343+
const htmlLink = repo.links.html as { href: string };
344+
return htmlLink.href;
345+
}
346+
340347
const cloneLinks = repo.links.clone as {
341348
href: string;
342349
name: string;
343350
}[];
344351

345-
// Annoying difference between server and cloud (happens even if server is hosted with https)
346-
const targetCloneType = config.deploymentType === 'cloud' ? 'https' : 'http';
347352
for (const link of cloneLinks) {
348-
if (link.name === targetCloneType) {
353+
if (link.name === 'http') {
349354
return link.href;
350355
}
351356
}
@@ -374,7 +379,7 @@ export const compileBitbucketConfig = async (
374379

375380
const repos = bitbucketRepos.map((repo) => {
376381
const isServer = config.deploymentType === 'server';
377-
const codeHostType = isServer ? 'bitbucket-server' : 'bitbucket-cloud';
382+
const codeHostType = isServer ? 'bitbucket-server' : 'bitbucket-cloud'; // zoekt expects bitbucket-server
378383
const displayName = isServer ? (repo as BitbucketServerRepository).name! : (repo as BitbucketCloudRepository).full_name!;
379384
const externalId = isServer ? (repo as BitbucketServerRepository).id!.toString() : (repo as BitbucketCloudRepository).uuid!;
380385
const isPublic = isServer ? (repo as BitbucketServerRepository).public : (repo as BitbucketCloudRepository).is_private === false;

packages/backend/src/repoManager.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -181,8 +181,8 @@ export class RepoManager implements IRepoManager {
181181
switch (repo.external_codeHostType) {
182182
case 'gitlab':
183183
return 'oauth2';
184-
case 'bitbucket-server':
185184
case 'bitbucket-cloud':
185+
case 'bitbucket-server':
186186
case 'github':
187187
case 'gitea':
188188
default:

packages/web/src/actions.ts

+7-6
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import { notAuthenticated, notFound, ServiceError, unexpectedError, orgInvalidSu
77
import { prisma } from "@/prisma";
88
import { StatusCodes } from "http-status-codes";
99
import { ErrorCode } from "@/lib/errorCodes";
10-
import { isServiceError } from "@/lib/utils";
10+
import { CodeHostType, isServiceError } from "@/lib/utils";
1111
import { githubSchema } from "@sourcebot/schemas/v3/github.schema";
1212
import { gitlabSchema } from "@sourcebot/schemas/v3/gitlab.schema";
1313
import { giteaSchema } from "@sourcebot/schemas/v3/gitea.schema";
@@ -444,10 +444,10 @@ export const getRepos = async (domain: string, filter: { status?: RepoIndexingSt
444444
}
445445
), /* allowSingleTenantUnauthedAccess = */ true));
446446

447-
export const createConnection = async (name: string, type: string, connectionConfig: string, domain: string): Promise<{ id: number } | ServiceError> => sew(() =>
447+
export const createConnection = async (name: string, type: CodeHostType, connectionConfig: string, domain: string): Promise<{ id: number } | ServiceError> => sew(() =>
448448
withAuth((session) =>
449449
withOrgMembership(session, domain, async ({ orgId }) => {
450-
const parsedConfig = parseConnectionConfig(type, connectionConfig);
450+
const parsedConfig = parseConnectionConfig(connectionConfig);
451451
if (isServiceError(parsedConfig)) {
452452
return parsedConfig;
453453
}
@@ -533,7 +533,7 @@ export const updateConnectionConfigAndScheduleSync = async (connectionId: number
533533
return notFound();
534534
}
535535

536-
const parsedConfig = parseConnectionConfig(connection.connectionType, config);
536+
const parsedConfig = parseConnectionConfig(config);
537537
if (isServiceError(parsedConfig)) {
538538
return parsedConfig;
539539
}
@@ -1476,7 +1476,7 @@ const _fetchSubscriptionForOrg = async (orgId: number, prisma: Prisma.Transactio
14761476
return subscriptions.data[0];
14771477
}
14781478

1479-
const parseConnectionConfig = (connectionType: string, config: string) => {
1479+
const parseConnectionConfig = (config: string) => {
14801480
let parsedConfig: ConnectionConfig;
14811481
try {
14821482
parsedConfig = JSON.parse(config);
@@ -1488,6 +1488,7 @@ const parseConnectionConfig = (connectionType: string, config: string) => {
14881488
} satisfies ServiceError;
14891489
}
14901490

1491+
const connectionType = parsedConfig.type;
14911492
const schema = (() => {
14921493
switch (connectionType) {
14931494
case "github":
@@ -1529,7 +1530,7 @@ const parseConnectionConfig = (connectionType: string, config: string) => {
15291530
}
15301531

15311532
const { numRepos, hasToken } = (() => {
1532-
switch (parsedConfig.type) {
1533+
switch (connectionType) {
15331534
case "gitea":
15341535
case "github":
15351536
case "bitbucket": {

packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketCloudConnectionCreationForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ export const BitbucketCloudConnectionCreationForm = ({ onCreated }: BitbucketClo
3535

3636
return (
3737
<SharedConnectionCreationForm<BitbucketConnectionConfig>
38-
type="bitbucket"
38+
type="bitbucket-cloud"
3939
title="Create a Bitbucket Cloud connection"
4040
defaultValues={{
4141
config: JSON.stringify(defaultConfig, null, 2),

packages/web/src/app/[domain]/components/connectionCreationForms/bitbucketDataCenterConnectionCreationForm.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export const BitbucketDataCenterConnectionCreationForm = ({ onCreated }: Bitbuck
3434

3535
return (
3636
<SharedConnectionCreationForm<BitbucketConnectionConfig>
37-
type="bitbucket"
37+
type="bitbucket-server"
3838
title="Create a Bitbucket Data Center connection"
3939
defaultValues={{
4040
config: JSON.stringify(defaultConfig, null, 2),

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

+28-2
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,10 @@ export const ImportSecretDialog = ({ open, onOpenChange, onSecretCreated, codeHo
8888
return <GitHubPATCreationStep step={1} />;
8989
case 'gitlab':
9090
return <GitLabPATCreationStep step={1} />;
91+
case 'bitbucket-cloud':
92+
return <BitbucketCloudPATCreationStep step={1} />;
93+
case 'bitbucket-server':
94+
return <BitbucketServerPATCreationStep step={1} />;
9195
case 'gitea':
9296
return <GiteaPATCreationStep step={1} />;
9397
case 'gerrit':
@@ -179,7 +183,7 @@ export const ImportSecretDialog = ({ open, onOpenChange, onSecretCreated, codeHo
179183
<FormLabel>Key</FormLabel>
180184
<FormControl>
181185
<Input
182-
placeholder="my-github-token"
186+
placeholder="my-access-token"
183187
{...field}
184188
/>
185189
</FormControl>
@@ -262,11 +266,33 @@ const GiteaPATCreationStep = ({ step }: { step: number }) => {
262266
)
263267
}
264268

269+
const BitbucketCloudPATCreationStep = ({ step }: { step: number }) => {
270+
return (
271+
<SecretCreationStep
272+
step={step}
273+
title="Create an Access Token"
274+
description=<span>Please check out our <Link href="https://docs.sourcebot.dev/docs/connections/bitbucket-cloud#authenticating-with-bitbucket-cloud" target="_blank" className="underline">docs</Link> for more information on how to create auth credentials for Bitbucket Cloud.</span>
275+
>
276+
</SecretCreationStep>
277+
)
278+
}
279+
280+
const BitbucketServerPATCreationStep = ({ step }: { step: number }) => {
281+
return (
282+
<SecretCreationStep
283+
step={step}
284+
title="Create an Access Token"
285+
description=<span>Please check out our <Link href="https://docs.sourcebot.dev/docs/connections/bitbucket-data-center#authenticating-with-bitbucket-data-center" target="_blank" className="underline">docs</Link> for more information on how to create auth credentials for Bitbucket Data Center.</span>
286+
>
287+
</SecretCreationStep>
288+
)
289+
}
290+
265291
interface SecretCreationStepProps {
266292
step: number;
267293
title: string;
268294
description: string | React.ReactNode;
269-
children: React.ReactNode;
295+
children?: React.ReactNode;
270296
}
271297

272298
const SecretCreationStep = ({ step, title, description, children }: SecretCreationStepProps) => {

packages/web/src/app/[domain]/connections/[id]/components/configSetting.tsx

+22-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import { createZodConnectionConfigValidator } from "../../utils";
1313
import { GithubConnectionConfig } from "@sourcebot/schemas/v3/github.type";
1414
import { GiteaConnectionConfig } from "@sourcebot/schemas/v3/gitea.type";
1515
import { GerritConnectionConfig } from "@sourcebot/schemas/v3/gerrit.type";
16-
import { githubQuickActions, gitlabQuickActions, giteaQuickActions, gerritQuickActions } from "../../quickActions";
16+
import { githubQuickActions, gitlabQuickActions, giteaQuickActions, gerritQuickActions, bitbucketCloudQuickActions, bitbucketDataCenterQuickActions } from "../../quickActions";
1717
import { Schema } from "ajv";
1818
import { GitlabConnectionConfig } from "@sourcebot/schemas/v3/gitlab.type";
1919
import { gitlabSchema } from "@sourcebot/schemas/v3/gitlab.schema";
@@ -27,11 +27,13 @@ import { useDomain } from "@/hooks/useDomain";
2727
import { SecretCombobox } from "@/app/[domain]/components/connectionCreationForms/secretCombobox";
2828
import { ReactCodeMirrorRef } from "@uiw/react-codemirror";
2929
import strings from "@/lib/strings";
30+
import { bitbucketSchema } from "@sourcebot/schemas/v3/bitbucket.schema";
31+
import { BitbucketConnectionConfig } from "@sourcebot/schemas/v3/bitbucket.type";
3032

3133
interface ConfigSettingProps {
3234
connectionId: number;
3335
config: string;
34-
type: string;
36+
type: CodeHostType;
3537
disabled?: boolean;
3638
}
3739

@@ -56,6 +58,24 @@ export const ConfigSetting = (props: ConfigSettingProps) => {
5658
/>;
5759
}
5860

61+
if (type === 'bitbucket-cloud') {
62+
return <ConfigSettingInternal<BitbucketConnectionConfig>
63+
{...props}
64+
type="bitbucket-cloud"
65+
quickActions={bitbucketCloudQuickActions}
66+
schema={bitbucketSchema}
67+
/>;
68+
}
69+
70+
if (type === 'bitbucket-server') {
71+
return <ConfigSettingInternal<BitbucketConnectionConfig>
72+
{...props}
73+
type="bitbucket-server"
74+
quickActions={bitbucketDataCenterQuickActions}
75+
schema={bitbucketSchema}
76+
/>;
77+
}
78+
5979
if (type === 'gitea') {
6080
return <ConfigSettingInternal<GiteaConnectionConfig>
6181
{...props}

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

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ import { getOrgMembership } from "@/actions"
2121
import { isServiceError } from "@/lib/utils"
2222
import { notFound } from "next/navigation"
2323
import { OrgRole } from "@sourcebot/db"
24+
import { CodeHostType } from "@/lib/utils"
25+
import { BitbucketConnectionConfig } from "@sourcebot/schemas/v3/bitbucket.type"
26+
2427
interface ConnectionManagementPageProps {
2528
params: {
2629
domain: string

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export const NewConnectionCard = ({ className, role }: NewConnectionCardProps) =
5656
disabled={!isOwner}
5757
/>
5858
<Card
59-
type="bitbucket-data-center"
59+
type="bitbucket-server"
6060
title="Bitbucket Data Center"
6161
subtitle="Fetch repos from a Bitbucket DC instance."
6262
disabled={!isOwner}

packages/web/src/app/[domain]/connections/new/[type]/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export default function NewConnectionPage({
4343
return <BitbucketCloudConnectionCreationForm onCreated={onCreated} />;
4444
}
4545

46-
if (type === 'bitbucket-data-center') {
46+
if (type === 'bitbucket-server') {
4747
return <BitbucketDataCenterConnectionCreationForm onCreated={onCreated} />;
4848
}
4949

packages/web/src/app/[domain]/onboard/components/connectCodeHost.tsx

+5-5
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export const ConnectCodeHost = ({ nextStep, securityCardEnabled }: ConnectCodeHo
9090
)
9191
}
9292

93-
if (selectedCodeHost === "bitbucket-data-center") {
93+
if (selectedCodeHost === "bitbucket-server") {
9494
return (
9595
<>
9696
<BackButton onClick={onBack} />
@@ -129,18 +129,18 @@ const CodeHostSelection = ({ onSelect }: CodeHostSelectionProps) => {
129129
/>
130130
<CodeHostIconButton
131131
name="Bitbucket Cloud"
132-
logo={getCodeHostIcon("bitbucket")!}
132+
logo={getCodeHostIcon("bitbucket-cloud")!}
133133
onClick={() => {
134134
onSelect("bitbucket-cloud");
135135
captureEvent("wa_onboard_bitbucket_cloud_selected", {});
136136
}}
137137
/>
138138
<CodeHostIconButton
139139
name="Bitbucket DC"
140-
logo={getCodeHostIcon("bitbucket")!}
140+
logo={getCodeHostIcon("bitbucket-server")!}
141141
onClick={() => {
142-
onSelect("bitbucket-data-center");
143-
captureEvent("wa_onboard_bitbucket_data_center_selected", {});
142+
onSelect("bitbucket-server");
143+
captureEvent("wa_onboard_bitbucket_server_selected", {});
144144
}}
145145
/>
146146
<CodeHostIconButton

packages/web/src/lib/posthogEvents.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -239,7 +239,7 @@ export type PosthogEventMap = {
239239
wa_onboard_gitea_selected: {},
240240
wa_onboard_gerrit_selected: {},
241241
wa_onboard_bitbucket_cloud_selected: {},
242-
wa_onboard_bitbucket_data_center_selected: {},
242+
wa_onboard_bitbucket_server_selected: {},
243243
//////////////////////////////////////////////////////////////////
244244
wa_security_page_click: {},
245245
//////////////////////////////////////////////////////////////////

packages/web/src/lib/utils.ts

+16-8
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export const createPathWithQueryParams = (path: string, ...queryParams: [string,
3232
return `${path}?${queryString}`;
3333
}
3434

35-
export type CodeHostType = "github" | "gitlab" | "gitea" | "gerrit" | "bitbucket" | "bitbucket-cloud" | "bitbucket-data-center";
35+
export type CodeHostType = "github" | "gitlab" | "gitea" | "gerrit" | "bitbucket-cloud" | "bitbucket-server";
3636

3737
type CodeHostInfo = {
3838
type: CodeHostType;
@@ -111,11 +111,21 @@ const _getCodeHostInfoInternal = (type: string, displayName: string, cloneUrl: s
111111
iconClassName: className,
112112
}
113113
}
114-
case "bitbucket-server":
114+
case "bitbucket-server": {
115+
const { src, className } = getCodeHostIcon('bitbucket-server')!;
116+
return {
117+
type: "bitbucket-server",
118+
displayName: displayName,
119+
codeHostName: "Bitbucket",
120+
repoLink: cloneUrl,
121+
icon: src,
122+
iconClassName: className,
123+
}
124+
}
115125
case "bitbucket-cloud": {
116-
const { src, className } = getCodeHostIcon('bitbucket')!;
126+
const { src, className } = getCodeHostIcon('bitbucket-cloud')!;
117127
return {
118-
type: "bitbucket",
128+
type: "bitbucket-cloud",
119129
displayName: displayName,
120130
codeHostName: "Bitbucket",
121131
repoLink: cloneUrl,
@@ -145,9 +155,8 @@ export const getCodeHostIcon = (codeHostType: CodeHostType): { src: string, clas
145155
return {
146156
src: gerritLogo,
147157
}
148-
case "bitbucket":
149158
case "bitbucket-cloud":
150-
case "bitbucket-data-center":
159+
case "bitbucket-server":
151160
return {
152161
src: bitbucketLogo,
153162
}
@@ -161,9 +170,8 @@ export const isAuthSupportedForCodeHost = (codeHostType: CodeHostType): boolean
161170
case "github":
162171
case "gitlab":
163172
case "gitea":
164-
case "bitbucket":
165173
case "bitbucket-cloud":
166-
case "bitbucket-data-center":
174+
case "bitbucket-server":
167175
return true;
168176
case "gerrit":
169177
return false;

0 commit comments

Comments
 (0)