# Workflows This document provides ready-to-use workflow files for integrating OpenRabbit AI code review into your Gitea or GitHub repositories. Simply copy the workflow files below into your repository's `.gitea/workflows/` or `.github/workflows/` directory. --- ## Quick Start 1. Copy the workflow files to your repository 2. Configure the required secrets (see [Required Secrets](#required-secrets)) 3. Update the placeholders: - `YourOrg/OpenRabbit` - Your OpenRabbit fork repository - `https://git.example.com/api/v1` - Your Gitea instance API URL - `Bartender` - Your bot's username (for self-trigger prevention) --- ## Gitea Workflows ### 1. PR Review Workflow Automatically reviews pull requests when opened or updated. ```yaml # .gitea/workflows/enterprise-ai-review.yml name: Enterprise AI Code Review on: pull_request: types: [opened, synchronize] jobs: ai-review: runs-on: ubuntu-latest steps: # Checkout the PR repository - uses: actions/checkout@v4 with: fetch-depth: 0 # Checkout the CENTRAL AI tooling repo - uses: actions/checkout@v4 with: repository: YourOrg/OpenRabbit 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 the AI review - name: Run Enterprise AI Review env: AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }} AI_REVIEW_REPO: ${{ gitea.repository }} AI_REVIEW_API_URL: https://git.example.com/api/v1 AI_REVIEW_PR_NUMBER: ${{ gitea.event.pull_request.number }} 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 pr ${{ gitea.repository }} ${{ gitea.event.pull_request.number }} \ --title "${{ gitea.event.pull_request.title }}" # Fail CI on HIGH severity (optional) - name: Check Review Result if: failure() run: | echo "AI Review found HIGH severity issues. Please address them before merging." exit 1 ``` --- ### 2. Issue Triage Workflow Triggers on `@codebot triage` command in issue comments. ```yaml # .gitea/workflows/ai-issue-triage.yml name: AI Issue Triage # WORKFLOW ROUTING: # This workflow handles ONLY the 'triage' command # Other workflows: ai-comment-reply.yml (specific commands), ai-chat.yml (free-form questions) on: issue_comment: types: [created] jobs: ai-triage: runs-on: ubuntu-latest # Only run if comment contains @codebot triage # CRITICAL: Ignore bot's own comments to prevent infinite loops (bot username: Bartender) if: | github.event.comment.user.login != 'Bartender' && contains(github.event.comment.body, '@codebot triage') steps: - uses: actions/checkout@v4 - uses: actions/checkout@v4 with: repository: YourOrg/OpenRabbit 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 Issue Triage env: AI_REVIEW_TOKEN: ${{ secrets.AI_REVIEW_TOKEN }} AI_REVIEW_REPO: ${{ gitea.repository }} AI_REVIEW_API_URL: https://git.example.com/api/v1 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 issue ${{ gitea.repository }} ${{ gitea.event.issue.number }} ``` --- ### 3. Comment Reply Workflow Handles specific commands: `help`, `explain`, `suggest`, `security`, `summarize`, `changelog`, `explain-diff`, `review-again`, `setup-labels`. ```yaml # .gitea/workflows/ai-comment-reply.yml 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 (@codebot triage), ai-chat.yml (free-form questions) on: issue_comment: types: [created] # CUSTOMIZE YOUR BOT NAME: # Change '@codebot' 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: Bartender) if: | github.event.comment.user.login != 'Bartender' && (contains(github.event.comment.body, '@codebot help') || contains(github.event.comment.body, '@codebot explain') || contains(github.event.comment.body, '@codebot suggest') || contains(github.event.comment.body, '@codebot security') || contains(github.event.comment.body, '@codebot summarize') || contains(github.event.comment.body, '@codebot changelog') || contains(github.event.comment.body, '@codebot explain-diff') || contains(github.event.comment.body, '@codebot review-again') || contains(github.event.comment.body, '@codebot setup-labels')) steps: - uses: actions/checkout@v4 - uses: actions/checkout@v4 with: repository: YourOrg/OpenRabbit 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: https://git.example.com/api/v1 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="${{ gitea.event.issue.pull_request != null }}" REPO="${{ gitea.repository }}" ISSUE_NUMBER="${{ gitea.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 <