import re from typing import Dict from .base import BasePRWaiter, BasePromptBuilder, BasePRAnalyzer class StandardPRWaiter(BasePRWaiter): """Standard PR waiter that checks for basic CI completion.""" def wait_for_analysis_ready( self, github_client, pr_number: int, timeout: int = 600 ) -> Dict: """Wait for CI checks to complete before analysis.""" # For now, just proceed immediately for general repos # In the future, this could check for CI status, required reviews, etc. pr_data = github_client.get_pr_details(pr_number) return pr_data class PythonGeneralPromptBuilder(BasePromptBuilder): """Python/General code review prompt builder.""" def __init__(self): self.base_prompt = self._get_python_general_prompt_template() def _get_python_general_prompt_template(self) -> str: """Get the Python/general code review prompt template.""" return """# Python/General Code Review Prompt You are an AI assistant tasked with reviewing a pull request for a Python project. You will be given the PR title, description, and code diff. Perform a thorough review, focusing on the following key areas: 1. **Code Quality & Best Practices** - Follow Python PEP 8 style guidelines and naming conventions - Ensure proper error handling and exception management - Check for code clarity, readability, and maintainability - Verify appropriate use of Python idioms and patterns - Look for potential performance issues or inefficient algorithms - Ensure proper documentation (docstrings, comments) where needed 2. **Architecture & Design** - Assess if the code follows good software design principles (SOLID, DRY, etc.) - Check for proper separation of concerns and modularity - Evaluate the overall structure and organization of the code - Ensure new functionality integrates well with existing codebase - Look for opportunities to reduce complexity and improve maintainability 3. **Security Considerations** - Check for potential security vulnerabilities (SQL injection, XSS, etc.) - Ensure sensitive data is not exposed in logs or error messages - Verify proper input validation and sanitization - Check for hardcoded secrets, passwords, or API keys - Ensure secure defaults and proper access controls 4. **Testing & Reliability** - Verify that new functionality has appropriate test coverage - Check if existing tests are updated for changes - Look for edge cases that might not be covered - Ensure error conditions are properly tested - Check that tests are meaningful and not just for coverage 5. **Dependencies & Compatibility** - Review any new dependencies added to the project - Check for version compatibility issues - Ensure dependencies are necessary and well-maintained - Look for potential conflicts with existing dependencies - Verify that requirements are properly documented After analyzing the PR against the above points, **separate your feedback into two categories**: **Blocking Issues** and **Suggestions for Improvement**. - **Blocking Issues** should detail any problems that **must** be addressed before merging. These include security vulnerabilities, breaking changes, test failures, or significant architectural problems. - **Suggestions for Improvement** should cover optional improvements that would enhance code quality, performance, or maintainability but don't necessarily block the merge. **Tone and style**: Present your feedback in a **constructive and helpful manner**. Focus on explaining the reasoning behind suggestions and provide specific examples or alternatives where possible. **Output format**: Use clear markdown formatting with headers for "Blocking Issues" and "Suggestions for Improvement". If there are no blocking issues, state "No blocking issues found" before proceeding to suggestions. PR Title: {pr_title} PR Description: {pr_body} Code Changes: {diff} Comments (if any): {comments} """ def build_prompt(self, pr_data: Dict) -> str: """Build the complete prompt with PR data.""" return self.base_prompt.format( pr_title=pr_data['pr_title'], pr_body=pr_data['pr_body'], diff=pr_data['diff'], comments='\n'.join( [comment['body'] for comment in pr_data.get('comments', [])] ), ) class PythonGeneralPRAnalyzer(BasePRAnalyzer): """Python/General code PR analyzer.""" def post_process_analysis(self, analysis: str) -> str: """Standard post-processing for general repos.""" # De-emphasize headers for GitHub formatting return re.sub(r'^#{1,3}(?= )', '####', analysis, flags=re.MULTILINE)