#!/bin/bash # OpenRabbit Setup Wizard # This script helps you set up OpenRabbit AI code review for your Gitea or GitHub repository set -e # Exit on error echo "🐰 OpenRabbit Setup Wizard" echo "===========================" echo "" # Get the directory where this script is located SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" TEMPLATE_DIR="$SCRIPT_DIR/templates/workflows" # Check if templates directory exists if [ ! -d "$TEMPLATE_DIR" ]; then echo "❌ Error: Template directory not found at $TEMPLATE_DIR" echo "Please run this script from the OpenRabbit repository root." exit 1 fi # 1. Detect platform echo "Step 1: Platform Configuration" echo "------------------------------" read -p "Platform? [gitea/github] (default: gitea): " PLATFORM PLATFORM=${PLATFORM:-gitea} # Validate platform if [ "$PLATFORM" != "gitea" ] && [ "$PLATFORM" != "github" ]; then echo "❌ Error: Invalid platform. Please choose 'gitea' or 'github'" exit 1 fi echo "✅ Platform: $PLATFORM" echo "" # 2. Bot configuration echo "Step 2: Bot Configuration" echo "-------------------------" read -p "Bot mention name (e.g., codebot): " BOT_NAME while [ -z "$BOT_NAME" ]; do echo "❌ Bot name cannot be empty" read -p "Bot mention name (e.g., codebot): " BOT_NAME done # Validate bot name (alphanumeric, dash, underscore only) if ! echo "$BOT_NAME" | grep -qE '^[a-zA-Z0-9_-]+$'; then echo "❌ Error: Bot name must contain only letters, numbers, dashes, and underscores" exit 1 fi read -p "Bot account username (default: same as mention name): " BOT_USERNAME BOT_USERNAME=${BOT_USERNAME:-$BOT_NAME} echo "✅ Bot: @$BOT_NAME (account: $BOT_USERNAME)" echo "" # 3. LLM Provider echo "Step 3: LLM Provider" echo "--------------------" echo "Available providers:" echo " 1) openai - OpenAI GPT models (default)" echo " 2) anthropic - Anthropic Claude models" echo " 3) azure - Azure OpenAI Service" echo " 4) gemini - Google Gemini API" echo " 5) ollama - Self-hosted Ollama" read -p "Choose provider [1-5] (default: 1): " PROVIDER_CHOICE PROVIDER_CHOICE=${PROVIDER_CHOICE:-1} case "$PROVIDER_CHOICE" in 1) PROVIDER="openai" ;; 2) PROVIDER="anthropic" ;; 3) PROVIDER="azure" ;; 4) PROVIDER="gemini" ;; 5) PROVIDER="ollama" ;; *) echo "❌ Invalid choice. Using openai." PROVIDER="openai" ;; esac echo "✅ Provider: $PROVIDER" echo "" # 4. Platform-specific settings if [ "$PLATFORM" = "gitea" ]; then echo "Step 4: Gitea Configuration" echo "---------------------------" read -p "Gitea API URL (e.g., https://gitea.example.com/api/v1): " API_URL while [ -z "$API_URL" ]; do echo "❌ API URL cannot be empty" read -p "Gitea API URL: " API_URL done # Validate URL format if ! echo "$API_URL" | grep -qE '^https?://'; then echo "❌ Error: API URL must start with http:// or https://" exit 1 fi echo "✅ API URL: $API_URL" else echo "Step 4: GitHub Configuration" echo "----------------------------" API_URL="https://api.github.com" echo "✅ Using GitHub API: $API_URL" fi echo "" # 5. OpenRabbit repository location echo "Step 5: OpenRabbit Repository" echo "-----------------------------" read -p "OpenRabbit repo location (e.g., YourOrg/openrabbit): " OPENRABBIT_REPO while [ -z "$OPENRABBIT_REPO" ]; do echo "❌ Repository cannot be empty" read -p "OpenRabbit repo location: " OPENRABBIT_REPO done # Validate repo format if ! echo "$OPENRABBIT_REPO" | grep -qE '^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$'; then echo "❌ Error: Repository must be in format 'owner/repo'" exit 1 fi echo "✅ OpenRabbit: $OPENRABBIT_REPO" echo "" # 6. Create workflow directory echo "Step 6: Creating Workflow Files" echo "--------------------------------" WORKFLOW_DIR=".${PLATFORM}/workflows" mkdir -p "$WORKFLOW_DIR" # Replace template variables in workflow files for template in "$TEMPLATE_DIR"/*.yml; do filename=$(basename "$template") output="$WORKFLOW_DIR/$filename" echo "Creating $output..." # Use sed to replace template variables sed -e "s|{{OPENRABBIT_REPO}}|$OPENRABBIT_REPO|g" \ -e "s|{{API_URL}}|$API_URL|g" \ -e "s|{{BOT_NAME}}|$BOT_NAME|g" \ -e "s|{{BOT_USERNAME}}|$BOT_USERNAME|g" \ -e "s|{{PLATFORM}}|$PLATFORM|g" \ "$template" > "$output" done echo "✅ Created 5 workflow files in $WORKFLOW_DIR/" echo "" # 7. Create basic config.yml if it doesn't exist CONFIG_FILE="tools/ai-review/config.yml" if [ ! -f "$CONFIG_FILE" ]; then echo "Step 7: Creating Configuration File" echo "------------------------------------" mkdir -p "$(dirname "$CONFIG_FILE")" cat > "$CONFIG_FILE" <" echo " â€ĸ OPENAI_API_KEY = " echo "" echo " Optional secrets:" echo " â€ĸ OPENROUTER_API_KEY = " echo " â€ĸ OLLAMA_HOST = " echo " â€ĸ SEARXNG_URL = " else echo " Required secrets:" echo " â€ĸ OPENAI_API_KEY = " echo "" echo " Optional secrets:" echo " â€ĸ AI_REVIEW_TOKEN = " echo " â€ĸ OPENROUTER_API_KEY = " echo " â€ĸ OLLAMA_HOST = " echo " â€ĸ SEARXNG_URL = " fi echo "" echo "3ī¸âƒŖ Commit and Push Workflow Files" echo " git add $WORKFLOW_DIR/" if [ ! -f "$CONFIG_FILE.orig" ]; then echo " git add $CONFIG_FILE" fi echo " git commit -m \"Add OpenRabbit AI code review workflows\"" echo " git push" echo "" echo "4ī¸âƒŖ Set Up Labels (Automatic)" echo " Create an issue in your repository and comment:" echo " @$BOT_NAME setup-labels" echo "" echo " The bot will automatically detect your label schema and create missing labels." echo "" echo "5ī¸âƒŖ Test the Setup" echo " â€ĸ Create a pull request to test PR review" echo " â€ĸ Comment '@$BOT_NAME help' on any issue to see available commands" echo " â€ĸ Comment '@$BOT_NAME How does authentication work?' for chat" echo "" echo "📚 Documentation:" echo " â€ĸ Installation Guide: INSTALL.md" echo " â€ĸ Configuration: docs/configuration.md" echo " â€ĸ Agent Reference: docs/agents.md" echo " â€ĸ Troubleshooting: docs/troubleshooting.md" echo "" echo "🎉 Happy reviewing with OpenRabbit!"