import { BitbucketIcon, GithubIcon, GitlabIcon, } from "@/components/icons/data-tools-icons"; import { AlertBlock } from "@/components/shared/alert-block"; import { Button } from "@/components/ui/button"; import { CardContent } from "@/components/ui/card"; import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger, } from "@/components/ui/dialog"; import { Form, FormControl, FormField, FormItem, FormLabel, FormMessage, } from "@/components/ui/form"; import { Input } from "@/components/ui/input"; import { api } from "@/utils/api"; import { useUrl } from "@/utils/hooks/use-url"; import { zodResolver } from "@hookform/resolvers/zod"; import { ExternalLink } from "lucide-react"; import Link from "next/link"; import { useRouter } from "next/router"; import { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { toast } from "sonner"; import { z } from "zod"; const Schema = z.object({ name: z.string().min(1, { message: "Name is required", }), username: z.string().min(1, { message: "Username is required", }), password: z.string().min(1, { message: "App Password is required", }), workspaceName: z.string().optional(), }); type Schema = z.infer; export const AddBitbucketProvider = () => { const utils = api.useUtils(); const [isOpen, setIsOpen] = useState(false); const url = useUrl(); const { mutateAsync, error, isError } = api.gitProvider.createBitbucket.useMutation(); const { data: auth } = api.auth.get.useQuery(); const router = useRouter(); const form = useForm({ defaultValues: { username: "", password: "", workspaceName: "", }, resolver: zodResolver(Schema), }); useEffect(() => { form.reset({ username: "", password: "", workspaceName: "", }); }, [form, isOpen]); const onSubmit = async (data: Schema) => { await mutateAsync({ bitbucketUsername: data.username, appPassword: data.password, bitbucketWorkspaceName: data.workspaceName || "", authId: auth?.id || "", name: data.name || "", }) .then(async () => { await utils.gitProvider.getAll.invalidate(); toast.success("Bitbucket configured successfully"); setIsOpen(false); }) .catch(() => { toast.error("Error configuring Bitbucket"); }); }; return ( Bitbucket Provider {isError && {error?.message}}

To integrate your Bitbucket account, you need to create a new App Password in your Bitbucket settings. Follow these steps:

  1. Create new App Password{" "}
  2. When creating the App Password, ensure you grant the following permissions:
    • Account: Read
    • Workspace membership: Read
    • Projects: Read
    • Repositories: Read
    • Pull requests: Read
    • Webhooks: Read and write
  3. After creating, you'll receive an App Password. Copy it and paste it below along with your Bitbucket username.
( Name )} /> ( Bitbucket Username )} /> ( App Password )} /> ( Workspace Name (Optional) )} />
); };