#!/bin/bash

# Push all 30 MCP repos to GitHub
# Creates repos via gh CLI and pushes code

set -e

REPOS_DIR="/Users/jakeshore/.clawdbot/workspace/mcp-github-repos"
GITHUB_USER="BusyBee3333"

cd "$REPOS_DIR"

# Find all repo directories (exclude scripts and template)
REPO_DIRS=$(find . -maxdepth 1 -type d -name "*-mcp-2026-complete" | sort)

echo "🚀 Pushing MCP repos to GitHub..."
echo ""

for repo_dir in $REPO_DIRS; do
  cd "$REPOS_DIR/$repo_dir"
  
  # Get repo name from directory
  repo_name=$(basename "$repo_dir")
  display_name=$(echo "$repo_name" | sed 's/-mcp-2026-complete//' | sed 's/-/ /g' | awk '{for(i=1;i<=NF;i++) $i=toupper(substr($i,1,1)) tolower(substr($i,2));}1')
  
  echo "📦 Processing: $display_name"
  echo "   Repo: $repo_name"
  
  # Skip if no source code
  if [ ! -d "src" ]; then
    echo "   ⏭️  Skipping (no source code)"
    echo ""
    continue
  fi
  
  # Initialize git if needed
  if [ ! -d ".git" ]; then
    echo "   🔧 Initializing git..."
    git init
    git branch -M main
  fi
  
  # Stage all files
  git add -A
  
  # Check if there are changes to commit
  if git diff --cached --quiet; then
    echo "   ⏭️  No changes to commit"
  else
    echo "   📝 Committing files..."
    git commit -m "Initial commit: ${display_name} MCP Server 2026 Complete Version

- ${tools:-100}+ API tools
- Full ${display_name} API coverage
- Claude Desktop integration
- Railway deployment support
- Docker containerization
- Comprehensive documentation"
  fi
  
  # Create GitHub repo if it doesn't exist
  if ! gh repo view "$GITHUB_USER/$repo_name" &>/dev/null; then
    echo "   🆕 Creating GitHub repo..."
    gh repo create "$GITHUB_USER/$repo_name" \
      --public \
      --description "MCP server for ${display_name} API - Complete 2026 version with ${tools:-100}+ tools" \
      --source=. \
      --remote=origin \
      --push
    echo "   ✅ Created and pushed"
  else
    echo "   📤 Pushing to existing repo..."
    if ! git remote | grep -q origin; then
      git remote add origin "https://github.com/$GITHUB_USER/$repo_name.git"
    fi
    git push -u origin main --force
    echo "   ✅ Pushed"
  fi
  
  echo ""
done

echo "✨ All repos pushed to GitHub!"
echo ""
echo "🔗 View your repos: https://github.com/$GITHUB_USER?tab=repositories"
