import { useState, useEffect, useCallback } from 'react';
import { createLogger } from '@automaker/utils/logger';
import { Button } from '@/components/ui/button';
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';
import { useSetupStore } from '@/store/setup-store';
import { getElectronAPI } from '@/lib/electron';
import {
CheckCircle2,
ArrowRight,
ArrowLeft,
ExternalLink,
Copy,
RefreshCw,
AlertTriangle,
Github,
XCircle,
} from 'lucide-react';
import { Spinner } from '@/components/ui/spinner';
import { toast } from 'sonner';
import { StatusBadge } from '../components';
const logger = createLogger('GitHubSetupStep');
interface GitHubSetupStepProps {
onNext: () => void;
onBack: () => void;
onSkip: () => void;
}
export function GitHubSetupStep({ onNext, onBack, onSkip }: GitHubSetupStepProps) {
const { ghCliStatus, setGhCliStatus } = useSetupStore();
const [isChecking, setIsChecking] = useState(false);
const checkStatus = useCallback(async () => {
setIsChecking(true);
try {
const api = getElectronAPI();
if (!api.setup?.getGhStatus) {
return;
}
const result = await api.setup.getGhStatus();
if (result.success) {
setGhCliStatus({
installed: result.installed,
authenticated: result.authenticated,
version: result.version,
path: result.path,
user: result.user,
});
}
} catch (error) {
logger.error('Failed to check gh status:', error);
} finally {
setIsChecking(false);
}
}, [setGhCliStatus]);
useEffect(() => {
checkStatus();
}, [checkStatus]);
const copyCommand = (command: string) => {
navigator.clipboard.writeText(command);
toast.success('Command copied to clipboard');
};
const isReady = ghCliStatus?.installed && ghCliStatus?.authenticated;
const getStatusBadge = () => {
if (isChecking) {
return
Optional - Used for creating pull requests
This step is optional
The GitHub CLI allows you to create pull requests directly from the app. Without it, you can still create PRs manually in your browser.
GitHub CLI is ready!
You can create pull requests directly from the app. {ghCliStatus?.version && ( Version: {ghCliStatus.version} )}
GitHub CLI not found
Install the GitHub CLI to enable PR creation from the app.
Installation Commands:
macOS (Homebrew)
brew install gh
Windows (winget)
winget install GitHub.cli
Linux (apt)
sudo apt install gh
GitHub CLI not logged in
Run the login command to authenticate with GitHub.
Run this command in your terminal:
gh auth login
Checking GitHub CLI status...