diff --git a/detailed_prompt.txt b/detailed_prompt.txt index 51123a0..a496f1e 100644 --- a/detailed_prompt.txt +++ b/detailed_prompt.txt @@ -1,4 +1,9 @@ Please review the code with the following points in mind and provide suggestions: + +Do not be verbose, directly point out issues. Be strict, not overly polite. Only include relevant code-related comments. + +Review the following code changes, noting that lines starting with "-" indicate deleted code, and lines starting with "+" indicate new code. Focus on the new code and don't think too much about the code that was removed: + 1. **Code Structure and Readability** - Does the code follow consistent naming conventions and coding style? - Are the methods and classes concise, and does each adhere to the single responsibility principle? @@ -10,27 +15,14 @@ Please review the code with the following points in mind and provide suggestions 3. **Performance and Efficiency** - Is there room for improving the performance of the code? - Are there any parts of the code that could lead to performance bottlenecks? -4. **Security** - - Are there any potential security vulnerabilities? - - Is input validation and error handling adequate? -5. **Testing** +4. **Testing** - Does the code include sufficient unit tests? - Do the tests cover the main functionalities and edge cases? -For each suggestion, please provide: -1. The file name -2. The line number or range of line numbers -3. Your comment or suggestion - Format your response as follows: -FILE: filename.py -LINES: 10-15 -Your detailed comment or suggestion here. - -FILE: another_file.py -LINE: 42 -Another comment or suggestion. +file: filename.py (file path) +line: 15 (target issue location with line number) +comment: Your detailed comment please only focus on potential issues and improvements. do not include general feedback. -Do not add any char before FILE and LINE Please provide specific code snippets and improvement suggestions so that the developers can easily understand and implement your feedback. Thank you! \ No newline at end of file diff --git a/main.py b/main.py index a3a7123..bdb808d 100644 --- a/main.py +++ b/main.py @@ -139,8 +139,7 @@ def create_client(provider: str, **kwargs) -> AIClient: class IssueByLineNumber(BaseModel): comment: str - start_line: int - end_line: int + line: int class FileIssues(BaseModel): file_path: str @@ -152,8 +151,7 @@ class IssuesComment(BaseModel): class ReviewComment(BaseModel): file: str - start_line: int - end_line: int + line: int comment: str class BaseReview(ABC): @@ -222,7 +220,7 @@ def parse_review_result(self, review_result: Union[str, IssuesComment], summary_ for file_issue in issues_comment.file_issues: for issue in file_issue.issues: result.comments.append( - ReviewComment(file=file_issue.file_path, start_line=issue.start_line, end_line=issue.end_line, comment=issue.comment) + ReviewComment(file=file_issue.file_path, line=issue.line, comment=issue.comment) ) return result @@ -244,7 +242,7 @@ def submit_comments(self, code_change, comments, changes): pass @abstractmethod - def create_position(self, code_change, changes, file_path, line_number, end_line): + def create_position(self, code_change, changes, file_path, line_number): pass def find_line_numbers(self, diff, target_line): @@ -344,7 +342,7 @@ def submit_comments(self, mr, comments, changes): print(f"Failed to create comment: {e}") print(f"Comment details: File: {comment['file']}, Line: {comment['line']}, Comment: {comment['comment'][:50]}...") - def create_position(self, mr, changes, file_path, line_number, end_line): + def create_position(self, mr, changes, file_path, line_number): for change in changes['changes']: if change['new_path'] == file_path: old_line, new_line = self.find_line_numbers(change['diff'], line_number) @@ -427,7 +425,7 @@ def build_review_request(self, changes, summary_only: bool, mr_infomation: str): def submit_comments(self, pr, comments: list[ReviewComment], changes): for comment in comments: try: - position = self.create_position(pr, changes, comment.file, comment.start_line, comment.end_line) + position = self.create_position(pr, changes, comment.file, comment.line) if position: head_commit = pr.get_commits().reversed[0] pr_comment = pr.create_review_comment( @@ -440,14 +438,14 @@ def submit_comments(self, pr, comments: list[ReviewComment], changes): print(f"Created comment: {pr_comment}") else: print( - f"Warning: Could not create position for file {comment.file} line {comment.end_line}. Skipping comment.") + f"Warning: Could not create position for file {comment.file} line {comment.line}. Skipping comment.") except Exception as e: print(f"Failed to create comment. Error type: {type(e).__name__}") print(f"Error message: {str(e)}") print( - f"Comment details: File: {comment.file}, Line: {comment.end_line}, Comment: {comment.comment[:50]}...") + f"Comment details: File: {comment.file}, Line: {comment.line}, Comment: {comment.comment[:50]}...") - def create_position(self, pr, changes, file_path, target_line, end_line): + def create_position(self, pr, changes, file_path, target_line): for change in changes['changes']: if change['new_path'] == file_path: old_line, new_line = self.find_line_numbers(change['diff'], target_line)