diff --git a/pr_review/main.py b/pr_review/main.py index 9ee4152..66c2726 100644 --- a/pr_review/main.py +++ b/pr_review/main.py @@ -56,6 +56,14 @@ def process_pull_request(self, repo: str, pr_number: int, experience_level: str Returns: Processing results """ + # Initialize results early to avoid UnboundLocalError + results = { + 'pr_number': pr_number, + 'repository': repo, + 'status': 'error', + 'error': 'Unknown error occurred' + } + try: logger.info(f"Processing PR #{pr_number} in {repo}") @@ -105,10 +113,7 @@ def process_pull_request(self, repo: str, pr_number: int, experience_level: str self.github_client.create_issue_comment(repo, pr_number, comment_body) - # Send Discord notification - asyncio.create_task(self._send_discord_notification(results, comment_body)) - - # Return processing results + # Update results with success data BEFORE sending notification results = { 'pr_number': pr_number, 'repository': repo, @@ -119,6 +124,9 @@ def process_pull_request(self, repo: str, pr_number: int, experience_level: str 'status': 'success' } + # Send Discord notification with properly initialized results + asyncio.create_task(self._send_discord_notification(results, comment_body)) + logger.info(f"Successfully processed PR #{pr_number}") return results