Skip to content

Commit 44ce5bc

Browse files
committed
add bitbucket web ui support
1 parent 82c122c commit 44ce5bc

File tree

12 files changed

+372
-11
lines changed

12 files changed

+372
-11
lines changed

docs/docs/connections/bitbucket-cloud.mdx

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ import BitbucketAppPassword from '/snippets/bitbucket-app-password.mdx';
3737
"type": "bitbucket",
3838
"deploymentType": "cloud",
3939
"projects": [
40-
"myWorkspace/myRepo"
40+
"myProject"
4141
]
4242
}
4343
```

packages/web/src/actions.ts

+3
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ 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";
1414
import { gerritSchema } from "@sourcebot/schemas/v3/gerrit.schema";
15+
import { bitbucketSchema } from "@sourcebot/schemas/v3/bitbucket.schema";
1516
import { ConnectionConfig } from "@sourcebot/schemas/v3/connection.type";
1617
import { decrypt, encrypt } from "@sourcebot/crypto"
1718
import { getConnection } from "./data/connection";
@@ -1497,6 +1498,8 @@ const parseConnectionConfig = (connectionType: string, config: string) => {
14971498
return giteaSchema;
14981499
case 'gerrit':
14991500
return gerritSchema;
1501+
case 'bitbucket':
1502+
return bitbucketSchema;
15001503
}
15011504
})();
15021505

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const CodeHostIconButton = ({
1919
const captureEvent = useCaptureEvent();
2020
return (
2121
<Button
22-
className="flex flex-col items-center justify-center p-4 w-24 h-24 cursor-pointer gap-2"
22+
className="flex flex-col items-center justify-center p-4 w-36 h-36 cursor-pointer gap-2"
2323
variant="outline"
2424
onClick={() => {
2525
captureEvent('wa_connect_code_host_button_pressed', {
@@ -29,7 +29,7 @@ export const CodeHostIconButton = ({
2929
}}
3030
>
3131
<Image src={logo.src} alt={name} className={cn("w-8 h-8", logo.className)} />
32-
<p className="text-sm font-medium">{name}</p>
32+
<p className="text-sm font-medium text-center">{name}</p>
3333
</Button>
3434
)
3535
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
'use client';
2+
3+
import SharedConnectionCreationForm from "./sharedConnectionCreationForm";
4+
import { BitbucketConnectionConfig } from "@sourcebot/schemas/v3/connection.type";
5+
import { bitbucketSchema } from "@sourcebot/schemas/v3/bitbucket.schema";
6+
import { bitbucketCloudQuickActions } from "../../connections/quickActions";
7+
8+
interface BitbucketCloudConnectionCreationFormProps {
9+
onCreated?: (id: number) => void;
10+
}
11+
12+
const additionalConfigValidation = (config: BitbucketConnectionConfig): { message: string, isValid: boolean } => {
13+
const hasProjects = config.projects && config.projects.length > 0 && config.projects.some(p => p.trim().length > 0);
14+
const hasRepos = config.repos && config.repos.length > 0 && config.repos.some(r => r.trim().length > 0);
15+
const hasWorkspaces = config.workspaces && config.workspaces.length > 0 && config.workspaces.some(w => w.trim().length > 0);
16+
17+
if (!hasProjects && !hasRepos && !hasWorkspaces) {
18+
return {
19+
message: "At least one project, repository, or workspace must be specified",
20+
isValid: false,
21+
}
22+
}
23+
24+
return {
25+
message: "Valid",
26+
isValid: true,
27+
}
28+
};
29+
30+
export const BitbucketCloudConnectionCreationForm = ({ onCreated }: BitbucketCloudConnectionCreationFormProps) => {
31+
const defaultConfig: BitbucketConnectionConfig = {
32+
type: 'bitbucket',
33+
deploymentType: 'cloud',
34+
}
35+
36+
return (
37+
<SharedConnectionCreationForm<BitbucketConnectionConfig>
38+
type="bitbucket"
39+
title="Create a Bitbucket Cloud connection"
40+
defaultValues={{
41+
config: JSON.stringify(defaultConfig, null, 2),
42+
}}
43+
schema={bitbucketSchema}
44+
additionalConfigValidation={additionalConfigValidation}
45+
quickActions={bitbucketCloudQuickActions}
46+
onCreated={onCreated}
47+
/>
48+
)
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
'use client';
2+
3+
import SharedConnectionCreationForm from "./sharedConnectionCreationForm";
4+
import { BitbucketConnectionConfig } from "@sourcebot/schemas/v3/connection.type";
5+
import { bitbucketSchema } from "@sourcebot/schemas/v3/bitbucket.schema";
6+
import { bitbucketDataCenterQuickActions } from "../../connections/quickActions";
7+
8+
interface BitbucketDataCenterConnectionCreationFormProps {
9+
onCreated?: (id: number) => void;
10+
}
11+
12+
const additionalConfigValidation = (config: BitbucketConnectionConfig): { message: string, isValid: boolean } => {
13+
const hasProjects = config.projects && config.projects.length > 0 && config.projects.some(p => p.trim().length > 0);
14+
const hasRepos = config.repos && config.repos.length > 0 && config.repos.some(r => r.trim().length > 0);
15+
16+
if (!hasProjects && !hasRepos) {
17+
return {
18+
message: "At least one project or repository must be specified",
19+
isValid: false,
20+
}
21+
}
22+
23+
return {
24+
message: "Valid",
25+
isValid: true,
26+
}
27+
};
28+
29+
export const BitbucketDataCenterConnectionCreationForm = ({ onCreated }: BitbucketDataCenterConnectionCreationFormProps) => {
30+
const defaultConfig: BitbucketConnectionConfig = {
31+
type: 'bitbucket',
32+
deploymentType: 'server',
33+
}
34+
35+
return (
36+
<SharedConnectionCreationForm<BitbucketConnectionConfig>
37+
type="bitbucket"
38+
title="Create a Bitbucket Data Center connection"
39+
defaultValues={{
40+
config: JSON.stringify(defaultConfig, null, 2),
41+
}}
42+
schema={bitbucketSchema}
43+
additionalConfigValidation={additionalConfigValidation}
44+
quickActions={bitbucketDataCenterQuickActions}
45+
onCreated={onCreated}
46+
/>
47+
)
48+
}

packages/web/src/app/[domain]/components/connectionCreationForms/index.ts

+2
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,5 @@ export { GitHubConnectionCreationForm } from "./githubConnectionCreationForm";
22
export { GitLabConnectionCreationForm } from "./gitlabConnectionCreationForm";
33
export { GiteaConnectionCreationForm } from "./giteaConnectionCreationForm";
44
export { GerritConnectionCreationForm } from "./gerritConnectionCreationForm";
5+
export { BitbucketCloudConnectionCreationForm } from "./bitbucketCloudConnectionCreationForm";
6+
export { BitbucketDataCenterConnectionCreationForm } from "./bitBucketDataCenterConnectionCreationForm";

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

+12
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,18 @@ export const NewConnectionCard = ({ className, role }: NewConnectionCardProps) =
4949
subtitle="Cloud and Self-Hosted supported."
5050
disabled={!isOwner}
5151
/>
52+
<Card
53+
type="bitbucket-cloud"
54+
title="Bitbucket Cloud"
55+
subtitle="Fetch repos from Bitbucket Cloud."
56+
disabled={!isOwner}
57+
/>
58+
<Card
59+
type="bitbucket-data-center"
60+
title="Bitbucket Data Center"
61+
subtitle="Fetch repos from a Bitbucket DC instance."
62+
disabled={!isOwner}
63+
/>
5264
<Card
5365
type="gitea"
5466
title="Gitea"

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

+12-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ import {
55
GitHubConnectionCreationForm,
66
GitLabConnectionCreationForm,
77
GiteaConnectionCreationForm,
8-
GerritConnectionCreationForm
8+
GerritConnectionCreationForm,
9+
BitbucketCloudConnectionCreationForm,
10+
BitbucketDataCenterConnectionCreationForm
911
} from "@/app/[domain]/components/connectionCreationForms";
1012
import { useCallback } from "react";
1113
import { useDomain } from "@/hooks/useDomain";
@@ -37,5 +39,14 @@ export default function NewConnectionPage({
3739
return <GerritConnectionCreationForm onCreated={onCreated} />;
3840
}
3941

42+
if (type === 'bitbucket-cloud') {
43+
return <BitbucketCloudConnectionCreationForm onCreated={onCreated} />;
44+
}
45+
46+
if (type === 'bitbucket-data-center') {
47+
return <BitbucketDataCenterConnectionCreationForm onCreated={onCreated} />;
48+
}
49+
50+
4051
router.push(`/${domain}/connections`);
4152
}

0 commit comments

Comments
 (0)