Files
openrabbit/setup.sh
latte 95937c4738
All checks were successful
AI Codebase Quality Review / ai-codebase-review (push) Successful in 36s
Add automated setup system for easy installation
- Add setup.sh interactive wizard for 5-minute setup
- Add INSTALL.md comprehensive installation guide
- Add templates/workflows/ directory with parameterized workflow templates
- Update README.md with prominent Installation section
- Update docs/README.md with installation links

The setup wizard automates:
- Platform selection (Gitea/GitHub)
- Bot configuration
- LLM provider setup
- Workflow file generation
- Configuration file creation

Users can now add OpenRabbit to any repository in under 5 minutes.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
2026-01-16 11:33:05 +00:00

301 lines
8.3 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/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" <<EOF
# OpenRabbit Configuration
# This is a basic configuration - see docs/configuration.md for full options
provider: $PROVIDER
model:
openai: gpt-4.1-mini
anthropic: claude-3.5-sonnet
azure: gpt-4
gemini: gemini-1.5-pro
ollama: codellama:13b
interaction:
mention_prefix: "@$BOT_NAME"
commands:
- help
- explain
- suggest
- security
- summarize
- triage
- changelog
- explain-diff
- review-again
- setup-labels
review:
fail_on_severity: HIGH
max_diff_lines: 800
security_scan: true
agents:
issue:
enabled: true
pr:
enabled: true
security_scan: true
auto_summary:
enabled: true
post_as_comment: true
codebase:
enabled: true
chat:
enabled: true
max_iterations: 5
labels:
priority:
critical: "priority: critical"
high: "priority: high"
medium: "priority: medium"
low: "priority: low"
type:
bug: "type: bug"
feature: "type: feature"
question: "type: question"
documentation: "type: documentation"
security: "type: security"
status:
approved: "ai-approved"
changes_required: "ai-changes-required"
reviewed: "ai-reviewed"
EOF
echo "✅ Created $CONFIG_FILE"
echo ""
else
echo "Step 7: Configuration File"
echo "--------------------------"
echo " $CONFIG_FILE already exists (not overwriting)"
echo ""
fi
# 8. Display next steps
echo "✅ Setup Complete!"
echo "=================="
echo ""
echo "📋 Next Steps:"
echo ""
echo "1⃣ Create Bot Account"
echo " - Create a new $PLATFORM user account: '$BOT_USERNAME'"
if [ "$PLATFORM" = "gitea" ]; then
echo " - Generate an access token with 'repo' and 'issue' permissions"
else
echo " - The built-in GITHUB_TOKEN will be used automatically"
fi
echo ""
echo "2⃣ Add Repository/Organization Secrets"
if [ "$PLATFORM" = "gitea" ]; then
echo " Required secrets:"
echo " • AI_REVIEW_TOKEN = <bot access token>"
echo " • OPENAI_API_KEY = <your LLM API key>"
echo ""
echo " Optional secrets:"
echo " • OPENROUTER_API_KEY = <if using OpenRouter>"
echo " • OLLAMA_HOST = <if using Ollama>"
echo " • SEARXNG_URL = <if using web search>"
else
echo " Required secrets:"
echo " • OPENAI_API_KEY = <your LLM API key>"
echo ""
echo " Optional secrets:"
echo " • AI_REVIEW_TOKEN = <if using private OpenRabbit repo>"
echo " • OPENROUTER_API_KEY = <if using OpenRouter>"
echo " • OLLAMA_HOST = <if using Ollama>"
echo " • SEARXNG_URL = <if using web search>"
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!"