import clsx from 'clsx' import { useParams } from 'common' import Link from 'next/link' import { useRef, useState } from 'react' import { Badge, Button, CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, Command_Shadcn_, IconCheck, IconChevronDown, Modal, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, } from 'ui' import { EmptyIntegrationConnection, IntegrationConnection, } from 'components/interfaces/Integrations/IntegrationPanels' import AlertError from 'components/ui/AlertError' import ShimmeringLoader from 'components/ui/ShimmeringLoader' import { useGithubBranchesQuery } from 'data/integrations/integrations-github-branches-query' import { Integration } from 'data/integrations/integrations.types' import { useSidePanelsStateSnapshot } from 'state/side-panels' interface GithubRepositorySelectionProps { integration?: Integration selectedBranch?: string hasGithubIntegrationInstalled: boolean setSelectedBranch: (name: string) => void } const GithubRepositorySelection = ({ integration, selectedBranch, hasGithubIntegrationInstalled, setSelectedBranch, }: GithubRepositorySelectionProps) => { const { ref } = useParams() const [open, setOpen] = useState(false) const comboBoxRef = useRef(null) const githubConnection = integration?.connections.find( (connection) => connection.supabase_project_ref === ref ) const [repoOwner, repoName] = githubConnection?.metadata.name.split('/') ?? [] const sidePanels = useSidePanelsStateSnapshot() const githubIntegrationAppUrl = process.env.NEXT_PUBLIC_ENVIRONMENT === 'prod' ? ' https://github.com/apps/supabase' : process.env.NEXT_PUBLIC_ENVIRONMENT === 'staging' ? 'https://github.com/apps/supabase-staging' : 'https://github.com/apps/supabase-local-testing' const { data: githubBranches, error: githubBranchesError, isLoading: isLoadingBranches, isSuccess: isSuccessBranches, isError: isErrorBranches, } = useGithubBranchesQuery({ organizationIntegrationId: integration?.id, repoOwner, repoName, }) function onSelectConnectRepo() { if (integration) { sidePanels.setGithubConnectionsOpen(true) sidePanels.setGithubConnectionsIntegrationId(integration.id) } } return (

Git Connection

Required

{githubConnection !== undefined ? 'Your database preview branches will be based on the branches in the following repository that your project is connected with:' : 'Your database preview branches will be based on the branches in the Git repository that your project is connected with.'}

{!hasGithubIntegrationInstalled && ( )} {hasGithubIntegrationInstalled && !githubConnection && ( onSelectConnectRepo()} /> )} {integration && githubConnection && ( <>
    onSelectConnectRepo()}> Configure connection } orientation="vertical" />
{isLoadingBranches && } {isErrorBranches && ( )} {isSuccessBranches && ( No branches found {githubBranches?.map((branch) => ( { setOpen(false) setSelectedBranch(branch.name) }} onClick={() => { setOpen(false) setSelectedBranch(branch.name) }} > {branch.name} {branch.name === selectedBranch && } ))} )}
)}
) } export default GithubRepositorySelection