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 JavaScriptPromptBuilder(BasePromptBuilder): """JavaScript/Node.js code review prompt builder.""" def __init__(self): self.base_prompt = self._get_javascript_prompt_template() def _get_javascript_prompt_template(self) -> str: """Get the JavaScript/Node.js code review prompt template.""" return """# JavaScript/Node.js Code Review Prompt You are an AI assistant tasked with reviewing a JavaScript/Node.js pull request. 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 JavaScript/TypeScript best practices and coding standards - Ensure proper use of ES6+ features (arrow functions, destructuring, async/await) - Check for proper variable declarations (const, let vs var) - Verify consistent code style and formatting - Look for potential performance issues or inefficient operations - Ensure proper error handling with try/catch or Promise error handling - Check for proper use of JavaScript idioms and patterns 2. **Architecture & Design** - Assess component/module structure and organization - Check for proper separation of concerns - Evaluate use of design patterns (MVC, Observer, etc.) - Ensure new functionality integrates well with existing codebase - Look for opportunities to reduce complexity and improve maintainability - Check for proper abstraction and encapsulation 3. **Security Considerations** - Check for XSS vulnerabilities and proper input sanitization - Verify secure handling of user input and data validation - Look for potential code injection vulnerabilities - Check for hardcoded secrets or API keys - Ensure proper CORS configuration if applicable - Verify secure authentication and authorization practices - Check for potential prototype pollution vulnerabilities 4. **Performance & Browser Compatibility** - Look for memory leaks or inefficient DOM manipulations - Check for proper event listener cleanup - Verify efficient use of loops and data structures - Ensure asynchronous operations are handled properly - Check for unnecessary re-renders in React/Vue components - Verify proper bundle size considerations - Look for browser compatibility issues 5. **Testing & Quality Assurance** - Verify that new functionality has appropriate test coverage - Check if existing tests are updated for changes - Ensure tests cover edge cases and error conditions - Look for proper mocking and test isolation - Check that async code is properly tested - Verify integration tests where appropriate 6. **Dependencies & Package Management** - Review any new npm/yarn dependencies added - Check for security vulnerabilities in dependencies - Ensure dependencies are necessary and well-maintained - Look for potential conflicts with existing dependencies - Verify proper version pinning in package.json - Check for unused dependencies that should be removed 7. **Framework-Specific Considerations** - **React**: Check for proper hook usage, component lifecycle, and state management - **Vue**: Verify proper component structure, reactivity, and event handling - **Angular**: Check for proper service injection, component lifecycle, and TypeScript usage - **Node.js**: Verify proper middleware usage, async handling, and Express best practices 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 JavaScriptPRAnalyzer(BasePRAnalyzer): """JavaScript code PR analyzer.""" def post_process_analysis(self, analysis: str) -> str: """Standard post-processing for JavaScript repos.""" # De-emphasize headers for GitHub formatting return re.sub(r'^#{1,3}(?= )', '####', analysis, flags=re.MULTILINE)