diff --git a/INSTALL.md b/INSTALL.md new file mode 100644 index 0000000..c30202e --- /dev/null +++ b/INSTALL.md @@ -0,0 +1,318 @@ +# Installation + +Add OpenRabbit AI code review to your Gitea or GitHub repository in under 5 minutes. + +--- + +## Quick Start (Recommended) + +### Automated Setup + +Run the interactive setup wizard: + +```bash +# Clone OpenRabbit (or download setup.sh) +git clone https://github.com/YourOrg/openrabbit.git +cd openrabbit + +# Run setup wizard +./setup.sh +``` + +The wizard will: +- ✅ Ask for your platform (Gitea/GitHub) +- ✅ Configure bot name and LLM provider +- ✅ Generate workflow files for your platform +- ✅ Create basic configuration file +- ✅ Provide step-by-step next actions + +**That's it!** Follow the wizard's output to complete setup. + +--- + +## Prerequisites + +Before you start, ensure you have: + +- [ ] **Gitea or GitHub repository** with Actions enabled +- [ ] **Python 3.11+** (for the AI review tools) +- [ ] **LLM API access** - Choose one: + - OpenAI API key (recommended for getting started) + - Anthropic Claude API key + - Azure OpenAI Service access + - Google Gemini API key + - Self-hosted Ollama instance +- [ ] **Bot account** (for Gitea) or use built-in GITHUB_TOKEN (for GitHub) + +--- + +## Manual Setup + +Prefer to set up manually? Follow these platform-specific instructions. + +### For Gitea + +#### 1. Create Bot Account + +1. Create a new Gitea user (e.g., `codebot`, `ai-reviewer`) +2. Generate an access token: + - Go to User Settings → Applications → Generate New Token + - Enable scopes: `repo` (Full repository access), `issue` (Issue read/write) +3. Save the token securely + +#### 2. Add Organization/Repository Secrets + +Go to Settings → Secrets and add: + +| Secret Name | Description | Required | +|-------------|-------------|----------| +| `AI_REVIEW_TOKEN` | Bot's Gitea access token | ✅ Yes | +| `OPENAI_API_KEY` | OpenAI API key (or your LLM provider's key) | ✅ Yes | +| `OPENROUTER_API_KEY` | OpenRouter API key | Only if using OpenRouter | +| `OLLAMA_HOST` | Ollama server URL (e.g., `http://localhost:11434`) | Only if using Ollama | +| `SEARXNG_URL` | SearXNG instance URL for web search | Optional | + +#### 3. Add Workflow Files + +Copy workflow files to your repository: + +```bash +# In your project repository +mkdir -p .gitea/workflows + +# Copy from OpenRabbit (adjust path as needed) +cp /path/to/openrabbit/templates/workflows/*.yml .gitea/workflows/ + +# Edit each workflow file and replace: +# - {{OPENRABBIT_REPO}} → Your OpenRabbit fork (e.g., YourOrg/openrabbit) +# - {{API_URL}} → Your Gitea API URL (e.g., https://gitea.example.com/api/v1) +# - {{BOT_NAME}} → Your bot mention name (e.g., codebot) +# - {{BOT_USERNAME}} → Your bot account username +# - {{PLATFORM}} → gitea +``` + +Or use the setup wizard to generate them automatically: `./setup.sh` + +#### 4. Commit and Push + +```bash +git add .gitea/workflows/ +git commit -m "Add OpenRabbit AI code review" +git push +``` + +#### 5. Set Up Labels + +Create an issue and comment: + +``` +@codebot setup-labels +``` + +The bot will automatically create required labels. + +--- + +### For GitHub + +#### 1. Add Repository/Organization Secrets + +Go to Settings → Secrets and variables → Actions: + +| Secret Name | Description | Required | +|-------------|-------------|----------| +| `OPENAI_API_KEY` | OpenAI API key (or your LLM provider's key) | ✅ Yes | +| `AI_REVIEW_TOKEN` | Only if OpenRabbit repo is private | Optional | +| `OPENROUTER_API_KEY` | OpenRouter API key | Only if using OpenRouter | +| `OLLAMA_HOST` | Ollama server URL | Only if using Ollama | +| `SEARXNG_URL` | SearXNG instance URL | Optional | + +**Note:** GitHub's built-in `GITHUB_TOKEN` is used automatically for API access. + +#### 2. Add Workflow Files + +Copy workflow files to your repository: + +```bash +# In your project repository +mkdir -p .github/workflows + +# Copy from OpenRabbit +cp /path/to/openrabbit/templates/workflows/*.yml .github/workflows/ + +# Edit each workflow file and replace: +# - {{OPENRABBIT_REPO}} → OpenRabbit repository (e.g., anthropics/openrabbit) +# - {{API_URL}} → https://api.github.com +# - {{BOT_NAME}} → Your bot mention name (e.g., codebot) +# - {{BOT_USERNAME}} → Your bot username (or 'github-actions[bot]') +# - {{PLATFORM}} → github +``` + +Or use the setup wizard: `./setup.sh` + +#### 3. Commit and Push + +```bash +git add .github/workflows/ +git commit -m "Add OpenRabbit AI code review" +git push +``` + +#### 4. Set Up Labels + +Create an issue and comment: + +``` +@codebot setup-labels +``` + +--- + +## Configuration + +### Basic Configuration + +If you used the setup wizard, a basic `tools/ai-review/config.yml` was created. + +### Advanced Configuration + +For advanced settings, see: +- **[Configuration Reference](docs/configuration.md)** - All config options +- **[Agent Documentation](docs/agents.md)** - Agent-specific settings +- **[LLM Providers](docs/configuration.md#llm-providers)** - Provider setup + +### Per-Repository Overrides + +Create `.ai-review.yml` in your project root to override settings: + +```yaml +# .ai-review.yml +review: + fail_on_severity: MEDIUM # Override: fail on MEDIUM instead of HIGH + +agents: + pr: + auto_summary: + enabled: false # Disable auto-summary for this repo +``` + +--- + +## Testing Your Setup + +### Test PR Review + +1. Create a new pull request +2. Wait 30-60 seconds for the workflow to run +3. Check for the AI review comment with inline suggestions + +### Test Issue Triage + +1. Create a new issue +2. Comment: `@codebot triage` +3. The bot should analyze and label the issue + +### Test Chat + +1. On any issue, comment: `@codebot How does authentication work?` +2. The bot should search the codebase and respond + +### Test Commands + +Try these commands in issue comments: +- `@codebot help` - Show all available commands +- `@codebot explain` - Explain the issue in detail +- `@codebot summarize` - Generate a summary +- `@codebot suggest` - Get solution suggestions + +--- + +## Troubleshooting + +### Workflow Not Triggering + +**Problem:** No AI review appears after creating a PR. + +**Solutions:** +- ✅ Verify Actions/Workflows are enabled in repository settings +- ✅ Check workflow files are in correct directory (`.gitea/workflows/` or `.github/workflows/`) +- ✅ Review workflow syntax: `cat .gitea/workflows/enterprise-ai-review.yml` +- ✅ Check Actions tab for error logs + +### "Missing Token" Error + +**Problem:** Workflow fails with authentication error. + +**Solutions:** +- ✅ Verify `AI_REVIEW_TOKEN` secret is set (Gitea) +- ✅ Verify token has correct permissions: `repo`, `issue` +- ✅ For private OpenRabbit repos on GitHub, set `AI_REVIEW_TOKEN` + +### "LLM Call Failed" Error + +**Problem:** Workflow fails when calling the LLM. + +**Solutions:** +- ✅ Verify API key secret is set (`OPENAI_API_KEY`, etc.) +- ✅ Check API key is valid and has credits/quota remaining +- ✅ Verify `provider` in `config.yml` matches your secret +- ✅ For Ollama: verify `OLLAMA_HOST` is accessible from runner + +### Bot Not Responding to Commands + +**Problem:** Commenting `@codebot help` does nothing. + +**Solutions:** +- ✅ Verify bot name matches `mention_prefix` in `config.yml` +- ✅ Check bot username in workflow `if:` conditions matches actual bot account +- ✅ Verify `github.event.comment.user.login != 'BotUsername'` in workflows (prevents infinite loops) +- ✅ Check Actions tab to see if workflow ran + +### Labels Not Applied + +**Problem:** Bot reviews the code but doesn't add labels. + +**Solutions:** +- ✅ Run `@codebot setup-labels` to create required labels +- ✅ Verify bot account has permission to manage labels +- ✅ Check label names in `config.yml` match repository labels + +### Need More Help? + +- **[Troubleshooting Guide](docs/troubleshooting.md)** - Comprehensive troubleshooting +- **[Getting Started](docs/getting-started.md)** - Detailed setup walkthrough +- **[GitHub Issues](https://github.com/YourOrg/openrabbit/issues)** - Report bugs or ask questions + +--- + +## Next Steps + +Once OpenRabbit is working: + +### Customize Behavior +- **[Configuration Guide](docs/configuration.md)** - Adjust review settings, severity thresholds +- **[Agent Reference](docs/agents.md)** - Enable/disable agents, configure features +- **[Security Scanning](docs/SECURITY.md)** - Understand security rules, add custom rules + +### Enterprise Features +- **[Notifications](docs/enterprise.md#notifications)** - Slack/Discord alerts +- **[Metrics](docs/enterprise.md#metrics)** - Prometheus monitoring +- **[Audit Logging](docs/enterprise.md#audit-trail)** - Compliance and audit trails +- **[CODEOWNERS](docs/enterprise.md#codeowners)** - Enforce code ownership + +### Advanced Usage +- **[Workflow Reference](docs/workflows.md)** - Understand workflow routing +- **[CLI Usage](docs/getting-started.md#helper-cli-usage)** - Run reviews locally +- **[API Reference](docs/api-reference.md)** - Integrate with custom tools + +--- + +## Support + +- **Documentation:** [docs/](docs/) +- **Issues:** [GitHub Issues](https://github.com/YourOrg/openrabbit/issues) +- **Discussions:** [GitHub Discussions](https://github.com/YourOrg/openrabbit/discussions) + +--- + +**🎉 Enjoy automated code reviews with OpenRabbit!** diff --git a/README.md b/README.md index 3769002..6b24d82 100644 --- a/README.md +++ b/README.md @@ -26,6 +26,29 @@ Enterprise-grade AI code review system for **Gitea** and **GitHub** with automat --- +## 📦 Installation + +**Quick Setup (5 minutes):** + +```bash +# Clone OpenRabbit +git clone https://github.com/YourOrg/openrabbit.git +cd openrabbit + +# Run interactive setup wizard +./setup.sh +``` + +The wizard will generate workflow files, create configuration, and guide you through the remaining steps. + +**📖 See [INSTALL.md](INSTALL.md) for:** +- Detailed installation instructions +- Manual setup guide +- Platform-specific differences (Gitea vs GitHub) +- Troubleshooting common issues + +--- + ## Quick Start ### 1. Set Repository/Organization Secrets diff --git a/docs/README.md b/docs/README.md index 230def8..54d0040 100644 --- a/docs/README.md +++ b/docs/README.md @@ -6,19 +6,23 @@ Enterprise-grade AI code review system for Gitea with automated issue triage, PR | Document | Description | |----------|-------------| -| [Getting Started](getting-started.md) | Quick setup guide | +| [**Installation**](../INSTALL.md) | **Automated setup wizard & installation guide** | +| [Getting Started](getting-started.md) | Detailed setup walkthrough | | [Configuration](configuration.md) | All configuration options | | [Agents](agents.md) | Detailed agent documentation | -| [Security](security.md) | Security scanning features | +| [SECURITY](SECURITY.md) | Security best practices & scanning | | [API Reference](api-reference.md) | Client and agent APIs | | [Workflows](workflows.md) | Gitea workflow examples | | [Troubleshooting](troubleshooting.md) | Common issues and solutions | +| [Enterprise](enterprise.md) | Enterprise features & compliance | +| [CLAUDE](CLAUDE.md) | Claude Code integration guide | ## Quick Links -- **Setup**: See [Getting Started](getting-started.md) -- **Configuration**: See [Configuration](configuration.md) -- **Enterprise Features**: See [Enterprise](enterprise.md) +- **🚀 Installation**: See [../INSTALL.md](../INSTALL.md) - Automated setup wizard +- **⚙️ Configuration**: See [Configuration](configuration.md) +- **🏢 Enterprise Features**: See [Enterprise](enterprise.md) +- **🔧 Troubleshooting**: See [Troubleshooting](troubleshooting.md) ## Architecture Overview diff --git a/setup.sh b/setup.sh new file mode 100755 index 0000000..f5d3b2a --- /dev/null +++ b/setup.sh @@ -0,0 +1,300 @@ +#!/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!" diff --git a/templates/workflows/ai-chat.yml b/templates/workflows/ai-chat.yml new file mode 100644 index 0000000..db861c2 --- /dev/null +++ b/templates/workflows/ai-chat.yml @@ -0,0 +1,61 @@ +name: AI Chat ({{BOT_USERNAME}}) + +# WORKFLOW ROUTING: +# This workflow handles FREE-FORM questions/chat (no specific command) +# Other workflows: ai-issue-triage.yml (@{{BOT_NAME}} triage), ai-comment-reply.yml (specific commands) +# This is the FALLBACK for any @{{BOT_NAME}} mention that isn't a known command + +on: + issue_comment: + types: [created] + +# CUSTOMIZE YOUR BOT NAME: +# Change '@{{BOT_NAME}}' in all conditions below to match your config.yml mention_prefix +# Examples: '@bartender', '@uni', '@joey', '@codebot' + +jobs: + ai-chat: + # Only run if comment mentions the bot but NOT a specific command + # This prevents duplicate runs with ai-comment-reply.yml and ai-issue-triage.yml + # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: {{BOT_USERNAME}}) + if: | + {{PLATFORM}}.event.comment.user.login != '{{BOT_USERNAME}}' && + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}}') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} triage') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} help') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} explain') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} suggest') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} security') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} summarize') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} changelog') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} explain-diff') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} review-again') && + !contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} setup-labels') + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - uses: actions/checkout@v4 + with: + repository: {{OPENRABBIT_REPO}} + path: .ai-review + token: ${{ secrets.AI_REVIEW_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - run: pip install requests pyyaml + + - name: Run AI Chat + env: + AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }} + AI_REVIEW_REPO: ${{ {{PLATFORM}}.repository }} + AI_REVIEW_API_URL: {{API_URL}} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} + OLLAMA_HOST: ${{ secrets.OLLAMA_HOST }} + SEARXNG_URL: ${{ secrets.SEARXNG_URL }} + run: | + cd .ai-review/tools/ai-review + python main.py comment ${{ {{PLATFORM}}.repository }} ${{ {{PLATFORM}}.event.issue.number }} "${{ {{PLATFORM}}.event.comment.body }}" diff --git a/templates/workflows/ai-codebase-review.yml b/templates/workflows/ai-codebase-review.yml new file mode 100644 index 0000000..ff16d40 --- /dev/null +++ b/templates/workflows/ai-codebase-review.yml @@ -0,0 +1,58 @@ +name: AI Codebase Quality Review + +on: + # Weekly scheduled run + schedule: + - cron: "0 0 * * 0" # Every Sunday at midnight + + # Manual trigger + workflow_dispatch: + inputs: + report_type: + description: "Type of report to generate" + required: false + default: "full" + type: choice + options: + - full + - security + - quick + +jobs: + ai-codebase-review: + runs-on: ubuntu-latest + + steps: + # Checkout the repository + - uses: actions/checkout@v4 + with: + fetch-depth: 0 # Full history for analysis + + # Checkout central AI tooling + - uses: actions/checkout@v4 + with: + repository: {{OPENRABBIT_REPO}} + path: .ai-review + token: ${{ secrets.AI_REVIEW_TOKEN }} + + # Setup Python + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + # Install dependencies + - run: pip install requests pyyaml + + # Run AI codebase analysis + - name: Run AI Codebase Analysis + env: + AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }} + AI_REVIEW_REPO: ${{ {{PLATFORM}}.repository }} + AI_REVIEW_API_URL: {{API_URL}} + + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} + OLLAMA_HOST: ${{ secrets.OLLAMA_HOST }} + run: | + cd .ai-review/tools/ai-review + python main.py codebase ${{ {{PLATFORM}}.repository }} diff --git a/templates/workflows/ai-comment-reply.yml b/templates/workflows/ai-comment-reply.yml new file mode 100644 index 0000000..f6fff57 --- /dev/null +++ b/templates/workflows/ai-comment-reply.yml @@ -0,0 +1,98 @@ +name: AI Comment Reply + +# WORKFLOW ROUTING: +# This workflow handles SPECIFIC commands: help, explain, suggest, security, summarize, changelog, explain-diff, review-again, setup-labels +# Other workflows: ai-issue-triage.yml (@{{BOT_NAME}} triage), ai-chat.yml (free-form questions) + +on: + issue_comment: + types: [created] + +# CUSTOMIZE YOUR BOT NAME: +# Change '@{{BOT_NAME}}' in the 'if' condition below to match your config.yml mention_prefix +# Examples: '@bartender', '@uni', '@joey', '@codebot' + +jobs: + ai-reply: + runs-on: ubuntu-latest + # Only run for specific commands (not free-form chat or triage) + # This prevents duplicate runs with ai-chat.yml and ai-issue-triage.yml + # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: {{BOT_USERNAME}}) + if: | + {{PLATFORM}}.event.comment.user.login != '{{BOT_USERNAME}}' && + (contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} help') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} explain') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} suggest') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} security') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} summarize') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} changelog') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} explain-diff') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} review-again') || + contains({{PLATFORM}}.event.comment.body, '@{{BOT_NAME}} setup-labels')) + steps: + - uses: actions/checkout@v4 + + - uses: actions/checkout@v4 + with: + repository: {{OPENRABBIT_REPO}} + path: .ai-review + token: ${{ secrets.AI_REVIEW_TOKEN }} + + - uses: actions/setup-python@v5 + with: + python-version: "3.11" + + - run: pip install requests pyyaml + + - name: Run AI Comment Response + env: + AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }} + AI_REVIEW_API_URL: {{API_URL}} + OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} + OPENROUTER_API_KEY: ${{ secrets.OPENROUTER_API_KEY }} + OLLAMA_HOST: ${{ secrets.OLLAMA_HOST }} + run: | + cd .ai-review/tools/ai-review + + # Determine if this is a PR or issue comment + IS_PR="${{ {{PLATFORM}}.event.issue.pull_request != null }}" + REPO="${{ {{PLATFORM}}.repository }}" + ISSUE_NUMBER="${{ {{PLATFORM}}.event.issue.number }}" + + # Validate inputs + if [ -z "$REPO" ] || [ -z "$ISSUE_NUMBER" ]; then + echo "Error: Missing required parameters" + exit 1 + fi + + # Validate repository format (owner/repo) + if ! echo "$REPO" | grep -qE '^[a-zA-Z0-9_-]+/[a-zA-Z0-9_-]+$'; then + echo "Error: Invalid repository format: $REPO" + exit 1 + fi + + if [ "$IS_PR" = "true" ]; then + # This is a PR comment - use safe dispatch with minimal event data + # Build minimal event payload (does not include sensitive user data) + EVENT_DATA=$(cat <