"use client"; import { Button } from "@/components/ui/button"; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from "@/components/ui/card"; import { Badge } from "@/components/ui/badge"; import { Separator } from "@/components/ui/separator"; import { RefreshCw, GitBranch, Lock, Globe, ExternalLink, Building2, User, Github, LogIn, Plus, } from "lucide-react"; import { useGitHubAppProvider } from "@/providers/GitHubApp"; import { InstallationSelector } from "@/components/github/installation-selector"; import { cn } from "@/lib/utils"; export function GitHubManager() { const { isInstalled, isLoading, error, installations, currentInstallation, installationsLoading, installationsError, switchInstallation, refreshInstallations, repositories, repositoriesLoadingMore, refreshRepositories, loadMoreRepositories, repositoriesHasMore, } = useGitHubAppProvider(); const handleRefresh = async () => { await Promise.all([refreshRepositories(), refreshInstallations()]); }; const handleInstallApp = () => { window.location.href = "/api/github/installation"; }; const handleManageOnGitHub = () => { const appId = process.env.NEXT_PUBLIC_GITHUB_APP_CLIENT_ID; const fallbackInstallationsUrl = "https://github.com/settings/installations"; const applicationUrl = appId ? `https://github.com/settings/connections/applications/${appId}` : fallbackInstallationsUrl; window.open(applicationUrl, "_blank"); }; const handleLogin = () => { window.location.href = "/api/auth/github/login"; }; const isAuthError = (errorMessage: string | null) => { return ( errorMessage?.includes("GitHub access token not found") || errorMessage?.includes("Please authenticate first") || errorMessage?.includes("authentication") || errorMessage?.includes("access token") ); }; if (isAuthError(installationsError) || isAuthError(error)) { return (
To manage your GitHub repositories and app installations, you need to authenticate with GitHub first. This will allow you to select repositories and work with your code.
To access your GitHub repositories, you need to install our GitHub App and grant it access to the repositories you want to use.
Select which GitHub organization or user account to work with
{repositories.length} repositories accessible
No repositories found. Make sure you've granted access to at least one repository for the selected organization.
{repo.description}
)}You can manage your GitHub App installation, including adding or removing repositories, through GitHub.