Improve pr-polisher formatting and output checks (#3243)

1. Sync the local refs/remotes/origin/master tracking ref to
   refs/remotes/upstream/master before running javaIncrementalFormatCheck
   so google-java-format-git-diff.sh only evaluates the current branch's
   diff in fork-based workflows.
2. Clean up the temporary gjf.out file generated by
   javaIncrementalFormatCheck and run check_workspace_clean() after
   formatting checks.
3. Fix broken ANSI color escape sequences in check_diff.py.
This commit is contained in:
Ben McIlwain
2026-10-01 20:01:55 +00:00
committed by GitHub
parent 7f85d6a7de
commit a6bb0a48f5
@@ -17,12 +17,13 @@ import subprocess
import re
import sys
import datetime
import os
# Color codes
RED = "\03.3[91m"
YELLOW = "\03.3[93m"
GREEN = "\03.3[92m"
RESET = "\03.3[0m"
RED = "\033[91m"
YELLOW = "\033[93m"
GREEN = "\033[92m"
RESET = "\033[0m"
errors_found = 0
warnings_found = 0
@@ -144,10 +145,20 @@ def check_license_headers():
def check_formatting():
print("\n--- Checking Project Formatting ---")
try:
# Keep local origin/master tracking ref in sync with upstream/master so
# google-java-format-git-diff.sh only checks the current branch's diff.
try:
run_cmd("git rev-parse --verify refs/remotes/upstream/master")
run_cmd("git update-ref refs/remotes/origin/master refs/remotes/upstream/master")
except Exception as e:
log_warning(f"Failed to fast-forward origin/master to upstream/master: {e}")
run_cmd("./gradlew spotlessCheck javaIncrementalFormatCheck")
log_success("All formatting checks (spotless and javaIncrementalFormat) passed.")
except Exception as e:
log_error("Formatting checks failed. Run './gradlew spotlessApply javaIncrementalFormatApply' to fix.")
finally:
if os.path.exists("gjf.out"):
os.remove("gjf.out")
def check_diff_anti_patterns():
print("\n--- Checking Code Anti-Patterns in Diff ---")
@@ -311,11 +322,11 @@ def main():
check_single_commit()
check_commit_message()
check_workspace_clean()
check_package_lock()
check_license_headers()
check_missing_tests()
check_formatting()
check_package_lock()
check_workspace_clean()
check_diff_anti_patterns()
print("\n========================================")