import { useRouter } from 'next/router' import { CheckCircle2, Settings, AlertCircle } from 'lucide-react' import Image from 'next/image' import { useParams } from 'common' import { useBranchesQuery } from 'data/branches/branches-query' import { useGitHubConnectionsQuery } from 'data/integrations/github-connections-query' import { useSelectedOrganization } from 'hooks/misc/useSelectedOrganization' import { useSelectedProject } from 'hooks/misc/useSelectedProject' import { BASE_PATH } from 'lib/constants' import { Button, Card, CardContent } from 'ui' import Link from 'next/link' export const GitHubStatus = () => { const { ref: projectRef } = useParams() const selectedProject = useSelectedProject() const selectedOrganization = useSelectedOrganization() const parentProjectRef = selectedProject?.parent_project_ref || projectRef const { data: connections } = useGitHubConnectionsQuery( { organizationId: selectedOrganization?.id }, { enabled: !!selectedOrganization?.id } ) const { data: branches } = useBranchesQuery( { projectRef: parentProjectRef }, { enabled: !!parentProjectRef } ) const githubConnection = connections?.find( (connection) => connection.project.ref === parentProjectRef ) const mainBranch = branches?.find((branch) => branch.is_default) const isConnected = Boolean(githubConnection) const hasGitBranchSync = Boolean(mainBranch?.git_branch?.trim()) const hasAutomaticBranching = Boolean(githubConnection?.new_branch_per_pr) return (
GitHub

{isConnected ? `Connected to ${githubConnection?.repository.name}` : 'GitHub Integration'}

{isConnected ? ( <>
{hasGitBranchSync ? ( ) : ( )} {hasGitBranchSync ? `Syncing production (${mainBranch?.git_branch})` : 'Production sync disabled'}
{hasAutomaticBranching ? ( ) : ( )} {hasAutomaticBranching ? 'Automatically creating branches' : 'Automatic branching disabled'}
) : ( Not connected to any repository )}
) }