{gitServer.name}
diff --git a/frontend/src/pages/NewSite/NewSite.tsx b/frontend/src/pages/NewSite/NewSite.tsx index 82cc02a..bd778bd 100644 --- a/frontend/src/pages/NewSite/NewSite.tsx +++ b/frontend/src/pages/NewSite/NewSite.tsx @@ -17,47 +17,32 @@ import { import { Plus, Zap, Copy, Check, AlertTriangle } from 'lucide-react'; import { cn } from '@/lib/utils'; import { useCreateSite } from '../../hooks/api/useCreateSite'; -import { useNavigate } from 'react-router'; +import { Link, useNavigate } from 'react-router'; +import GitServerTypeIcon from '../../components/GitServerTypeIcon'; +import { useGitServers } from '../../hooks/api/gitservers/useGitServers'; -const GIT_SERVERS = [ - { - value: 'github', - label: 'GitHub', - icon: ( - - ), - }, - { - value: 'gitlab', - label: 'GitLab', - icon: ( - - ), - }, -]; +interface ParsedRepo { + gitServer: string; + owner: string; + repository: string; +} -const parseRepoUrl = (url: string) => { +const parseRepoUrl = (url: string): ParsedRepo | null => { const cleaned = url .trim() .replace(/\.git$/, '') .replace(/\/$/, ''); - const patterns = [ - /^https?:\/\/(github\.com|gitlab\.com)\/([^/]+)\/([^/]+)/, - /^git@(github\.com|gitlab\.com):([^/]+)\/([^/]+)/, - ]; + // HTTPS: https://host/owner/repo + const httpsMatch = cleaned.match(/^https?:\/\/([^/]+)\/([^/]+)\/([^/]+)/); + if (httpsMatch) { + return { gitServer: httpsMatch[1], owner: httpsMatch[2], repository: httpsMatch[3] }; + } - for (const pattern of patterns) { - const match = cleaned.match(pattern); - if (match) { - const host = match[1]; - const server = host === 'github.com' ? 'github' : 'gitlab'; - return { gitServer: server, owner: match[2], repository: match[3] }; - } + // SSH: git@host:owner/repo + const sshMatch = cleaned.match(/^git@([^:]+):([^/]+)\/([^/]+)/); + if (sshMatch) { + return { gitServer: sshMatch[1], owner: sshMatch[2], repository: sshMatch[3] }; } return null; @@ -80,13 +65,28 @@ const NewSite = () => { const [copiedToken, setCopiedToken] = useState(false); const [copiedCurl, setCopiedCurl] = useState(false); const createNewSite = useCreateSite(); + const { + data: gitServers, + isLoading: isLoadingGitServers, + error: gitServersError, + } = useGitServers(); const handleQuickImport = () => { if (!repoUrl.trim()) return; const parsed = parseRepoUrl(repoUrl); if (parsed) { - setGitServer(parsed.gitServer); + const gitServerEntry = gitServers?.find((server) => + server.baseUrl.includes(parsed.gitServer) + ); + if (gitServerEntry) { + setGitServer(gitServerEntry.id); + } else { + setUrlError( + 'Git server not found. Please make sure the git server is added to the app.' + ); + return; + } setOwner(parsed.owner); setRepository(parsed.repository); setUrlError(''); @@ -209,15 +209,15 @@ const NewSite = () => {