import { zodResolver } from '@hookform/resolvers/zod' import { GitBranch, RotateCcw, Shield } from 'lucide-react' import { useRef, useState } from 'react' import { useForm } from 'react-hook-form' import { AlertDescription_Shadcn_, AlertTitle_Shadcn_, Alert_Shadcn_, Button, cn, CommandEmpty_Shadcn_, CommandGroup_Shadcn_, CommandInput_Shadcn_, CommandItem_Shadcn_, CommandList_Shadcn_, Command_Shadcn_, FormControl_Shadcn_, FormDescription_Shadcn_, FormField_Shadcn_, FormItem_Shadcn_, FormLabel_Shadcn_, Form_Shadcn_, IconCheck, IconChevronDown, Input_Shadcn_, Label_Shadcn_, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_, } from 'ui' import * as z from 'zod' import { useBranchUpdateMutation } from 'data/branches/branch-update-mutation' import { useBranchesQuery } from 'data/branches/branches-query' import { useGithubConnectionUpdateMutation } from 'data/integrations/github-connection-update-mutate' import { useGithubBranchesQuery } from 'data/integrations/integrations-github-branches-query' import { Integration, IntegrationProjectConnection } from 'data/integrations/integrations.types' import { useSelectedProject, useStore } from 'hooks' const GitHubIntegrationConnectionForm = ({ connection, integration, }: { connection: IntegrationProjectConnection integration: Integration }) => { const { ui } = useStore() const project = useSelectedProject() const [open, setOpen] = useState(false) const comboBoxRef = useRef(null) const githubProjectIntegration = integration?.connections.find( (connection) => connection.supabase_project_ref === project?.parentRef ) const [repoOwner, repoName] = githubProjectIntegration?.metadata.name.split('/') ?? [] const { data: githubBranches, error: githubBranchesError, isLoading: isLoadingBranches, isSuccess: isSuccessBranches, } = useGithubBranchesQuery({ organizationIntegrationId: integration?.id, repoOwner, repoName, }) const { mutate: updateBranch, isLoading: isUpdatingProdBranch } = useBranchUpdateMutation({ onSuccess: (data) => { ui.setNotification({ category: 'success', message: `Changed Production Branch to ${data.git_branch}`, }) setOpen(false) }, }) const { data: previewBranches, isLoading: isLoadingPreviewBranches } = useBranchesQuery( { projectRef: project?.parentRef }, { enabled: project !== undefined } ) const productionPreviewBranch = previewBranches?.find((branch) => branch.is_default) function onUpdateProductionBranch(branchName: string) { if (!project?.parentRef) return if (!productionPreviewBranch) return updateBranch({ id: productionPreviewBranch.id, projectRef: project.parentRef, branchName: branchName, gitBranch: branchName, }) } const FormSchema = z.object({ supabaseDirectory: z .string() .default(connection.metadata?.supabaseConfig?.supabaseDirectory ?? ''), }) const form = useForm>({ resolver: zodResolver(FormSchema), defaultValues: { supabaseDirectory: connection?.metadata?.supabaseConfig?.supabaseDirectory, }, }) const { mutate: updateGithubConnection, isLoading: isUpdatingGithubConnection } = useGithubConnectionUpdateMutation({ onSuccess: () => { ui.setNotification({ category: 'success', message: `Updated Supabase directory` }) setOpen(false) }, }) function onSubmit(data: z.infer) { const metadata = { ...connection.metadata, supabaseConfig: { ...connection.metadata?.supabaseConfig, supabaseDirectory: data.supabaseDirectory, }, } updateGithubConnection({ id: connection.id, metadata, organizationIntegrationId: integration.id, }) } return (
Production branch

All other branches will be treated as Preview branches

Changing Git branch for Production Branch coming soon If you wish to change the Git branch that is used for the Production Branch you will need to disable Branching and opt back in. {/*
! This should only work if branching is turned on !
*/} No branches found {githubBranches?.map((branch) => { const active = branch.name === productionPreviewBranch?.git_branch return ( { setOpen(false) onUpdateProductionBranch(branch.name) }} >
{active ? ( ) : ( )} {branch.name}
{branch.name === productionPreviewBranch?.git_branch && }
) })}
Supabase directory Migration and seed SQL files will be run from this directory. Changing Supabase directory is currently not supported You will need to disable Branching and opt back into Branching to change the Production Branch. your Git repository. (
{ if (event.key === 'Escape') { form.reset() } }} /> form.reset()} />
)} />
) } export default GitHubIntegrationConnectionForm