# AI Code Review Tool - Implementation Plan ## Overview A minimalist tool that receives Bitbucket webhooks for PR events, fetches code diffs, performs an AI review using LangChain, and emails a summary to the developer. ## Features - **Multi-Repo Support**: One tool can handle webhooks from multiple repositories. - **AI Review**: Focuses on Syntax, DRY (Don't Repeat Yourself), and Clean Code principles. - **Asynchronous Processing**: Uses background tasks to prevent webhook timeouts. ## Proposed Changes ### 1. API Endpoint (app.py) - `POST /webhook/bitbucket`: - Extracts `workspace`, `repo_slug`, `pull_request_id`, and `author_email`. - Triggers a background review task. ### 2. Review Engine (scripts/ai_code_reviewer.py) - **Diff Fetcher**: Calls Bitbucket API `GET /repositories/{workspace}/{repo_slug}/pullrequests/{id}/diff`. - **LangChain Reviewer**: - Prompt: "Review this diff for syntax, DRY violations, and quality." - LLM: OpenAI (GPT-4o) or Google (Gemini). ### 3. Notification (scripts/email_notifier.py) - Formats the LLM output into a clean email. - Sends via `mail_service` or SMTP. ## Setup Requirements 1. **Bitbucket App Password**: Create at Workspace level with `Pull Request: Read`. 2. **Environment Variables**: - `BITBUCKET_USERNAME` - `BITBUCKET_APP_PASSWORD` - `OPENAI_API_KEY` or `GOOGLE_API_KEY` - `SMTP_CONFIG` (if needed)