Skip to content

Commit 2876592

Browse files
Fix: Definitively resolve UnboundLocalError for timestamp tracking
- Addresses a persistent `UnboundLocalError` related to `latest_overall_review_activity_dt`. - While the variable was initialized at the top of `main()`, to ensure robust scoping within the loop that processes overall reviews, a temporary variable (`temp_latest_overall_review_dt`) is now used for accumulating the latest timestamp within that specific loop. - The main `latest_overall_review_activity_dt` is then updated from this temporary variable if any overall review timestamps were processed. - This change ensures the variable is always defined before use in the conditional check that was causing the error. (This commit also includes prior changes for removing the absl-py dependency and refactoring logging, which were part of the same active development session.)
1 parent 6912996 commit 2876592

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

scripts/print_github_reviews.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,22 +430,25 @@ def parse_repo_url(url_string):
430430
# Output overall reviews if any exist after filtering
431431
if filtered_overall_reviews:
432432
print("# Code Reviews\n\n") # Changed heading
433+
# Explicitly re-initialize before this loop to be absolutely sure for the update logic within it.
434+
# The main initialization at the top of main() handles the case where this block is skipped.
435+
temp_latest_overall_review_dt = None # Use a temporary variable for this loop's accumulation
433436
for review in filtered_overall_reviews:
434437
user = review.get("user", {}).get("login", "Unknown user")
435438
submitted_at_str = review.get("submitted_at", "N/A") # Keep original string for printing
436439
state = review.get("state", "N/A")
437440
body = review.get("body", "").strip()
438441

439-
# Track latest overall review timestamp
442+
# Track latest overall review timestamp within this block
440443
if submitted_at_str and submitted_at_str != "N/A":
441444
try:
442445
if sys.version_info < (3, 11):
443446
dt_str_submitted = submitted_at_str.replace("Z", "+00:00")
444447
else:
445448
dt_str_submitted = submitted_at_str
446449
current_review_submitted_dt = datetime.datetime.fromisoformat(dt_str_submitted)
447-
if latest_overall_review_activity_dt is None or current_review_submitted_dt > latest_overall_review_activity_dt:
448-
latest_overall_review_activity_dt = current_review_submitted_dt
450+
if temp_latest_overall_review_dt is None or current_review_submitted_dt > temp_latest_overall_review_dt:
451+
temp_latest_overall_review_dt = current_review_submitted_dt
449452
except ValueError:
450453
sys.stderr.write(f"Warning: Could not parse overall review submitted_at for --since suggestion: {submitted_at_str}\n")
451454

@@ -462,6 +465,11 @@ def parse_repo_url(url_string):
462465
print("\n### Summary Comment:")
463466
print(body)
464467
print("\n---")
468+
469+
# After processing all overall reviews in this block, update the main variable
470+
if temp_latest_overall_review_dt:
471+
latest_overall_review_activity_dt = temp_latest_overall_review_dt
472+
465473
# Add an extra newline to separate from line comments if any overall reviews were printed
466474
print("\n")
467475

0 commit comments

Comments
 (0)