Test: Final Verification of AI Reviewer#5
Conversation
| @@ -0,0 +1,397 @@ | |||
| """ | |||
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp API key của OpenRouter bị hạn chế hoặc hết hạn, có thể gây lỗi không mong muốn.
|
|
||
| # Configure Logging | ||
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
|
There was a problem hiding this comment.
🤖 AI Review: Hàm should_review không xử lý trường hợp filename là None hoặc rỗng, có thể gây lỗi.
|
|
||
| def get_pr_diff(repo, pr_number): | ||
| """Fetch PR diff using PyGithub.""" | ||
| pr = repo.get_pull(pr_number) |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp PR không tồn tại hoặc không thể truy cập, có thể gây lỗi không mong muốn.
| query = """ | ||
| query($owner: String!, $repo: String!, $prNumber: Int!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequest(number: $prNumber) { |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp thread_id là None hoặc không hợp lệ, có thể gây lỗi khi gọi GraphQL.
| threads = pr_data.get('reviewThreads', {}).get('nodes', []) | ||
| if not threads: | ||
| logging.info("No review threads found.") | ||
| return |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp response từ OpenRouter không chứa dữ liệu hợp lệ, có thể gây lỗi khi parse JSON.
| ) | ||
| except Exception as e: | ||
| logging.error(f"Failed to initialize OpenAI client: {e}") | ||
| return [] |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp commit không tồn tại hoặc không thể truy cập, có thể gây lỗi khi tạo comment.
| logging.warning("OpenRouter response has empty content.") | ||
| return [] | ||
|
|
||
| content = content.strip() |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp event_data không chứa thông tin pull_request, có thể gây lỗi không mong muốn.
|
|
||
| body = f"🤖 **AI Review**: {comment_text}" | ||
|
|
||
| try: |
There was a problem hiding this comment.
🤖 AI Review: Không có xử lý cho trường hợp repo_name không hợp lệ hoặc không thể phân tách thành owner và repository_name.
| @@ -0,0 +1,404 @@ | |||
| """ | |||
There was a problem hiding this comment.
🤖 AI Review: Không nên sử dụng model free-tier cho production do giới hạn và độ tin cậy thấp.
|
|
||
| # Configure Logging | ||
| logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s') | ||
|
|
There was a problem hiding this comment.
🤖 AI Review: Nên thêm kiểm tra cho trường hợp filename là None hoặc rỗng.
| return False | ||
| if any(part in filename.split('/') for part in IGNORED_DIRS): | ||
| return False | ||
| return True |
There was a problem hiding this comment.
🤖 AI Review: Cần xử lý ngoại lệ khi file.patch không tồn tại hoặc không thể truy cập.
| # Only review added or modified files (not deleted) | ||
| if file.status == 'removed': | ||
| continue | ||
|
|
There was a problem hiding this comment.
🤖 AI Review: Nên sử dụng timeout cho request để tránh treo vô hạn.
| query = """ | ||
| query($owner: String!, $repo: String!, $prNumber: Int!) { | ||
| repository(owner: $owner, name: $repo) { | ||
| pullRequest(number: $prNumber) { |
There was a problem hiding this comment.
🤖 AI Review: Cần kiểm tra và xử lý trường hợp data hoặc data['data'] là None.
| threads = pr_data.get('reviewThreads', {}).get('nodes', []) | ||
| if not threads: | ||
| logging.info("No review threads found.") | ||
| return |
There was a problem hiding this comment.
🤖 AI Review: Nên giới hạn kích thước của prompt để tránh vượt quá giới hạn của API.
| logging.error(f"Network error fetching threads: {e}") | ||
| except Exception as e: | ||
| logging.error(f"Failed to fetch/resolve threads: {e}") | ||
|
|
There was a problem hiding this comment.
🤖 AI Review: Cần kiểm tra và xử lý trường hợp response.choices[0] là None.
| ) | ||
| except Exception as e: | ||
| logging.error(f"Failed to initialize OpenAI client: {e}") | ||
| return [] |
There was a problem hiding this comment.
🤖 AI Review: Nên thêm kiểm tra cho trường hợp commit là None hoặc không tồn tại.
| Hãy trả về kết quả là một JSON list thuần túy (không markdown block, không giải thích thêm), mỗi item có format sau: | ||
| [ | ||
| { | ||
| "filename": "tên_file", |
There was a problem hiding this comment.
🤖 AI Review: Cần xử lý ngoại lệ khi line_number không phải là số nguyên hợp lệ.
| logging.warning("OpenRouter response has empty content.") | ||
| return [] | ||
|
|
||
| content = content.strip() |
There was a problem hiding this comment.
🤖 AI Review: Nên kiểm tra và xử lý trường hợp event_data không chứa thông tin pull_request.
No description provided.