From 4b6ce9581562169d836e8d5e7b6247d325a97e4b Mon Sep 17 00:00:00 2001 From: Aditya <97450298+1234-ad@users.noreply.github.com> Date: Mon, 12 Jan 2026 22:09:21 +0530 Subject: [PATCH] fix: resolve UnboundLocalError for 'results' variable in process_pull_request Initialize 'results' dictionary at the beginning of process_pull_request() to prevent UnboundLocalError when referenced in _send_discord_notification() before assignment. This ensures the variable is always defined, even if an exception occurs early in the processing pipeline. Changes: - Initialize results dict with default error state at function start - Update results with success data before sending Discord notification - Ensures results is always defined for error handling paths Fixes #53 --- pr_review/main.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) 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