Files
mongo/buildscripts/bazel_rules_mongo/codeowners/validate_codeowners.py
Zack Winter fbc2f1ea04 SERVER-111295 [v8.0] Set python as formatter in format_multirun (#41681)
GitOrigin-RevId: 0a5f595c13f329cc64a37f58e7369dd9469ee848
2026-01-15 19:55:28 +00:00

53 lines
1.3 KiB
Python
Executable File

#!/usr/bin/env python3
"""Script for validating CODEOWNERS file."""
import os
import subprocess
import sys
def get_validator_env() -> dict:
"""Prepare the environment for the codeowners-validator."""
env = os.environ.copy()
env.update(
{
"REPOSITORY_PATH": ".",
"CHECKS": "duppatterns,syntax",
"EXPERIMENTAL_CHECKS": "avoid-shadowing",
}
)
return env
def run_validator(validator_path: str) -> int:
"""Run the codeowners validation."""
if not os.path.isfile(validator_path):
raise RuntimeError(f"Validator was not found at input path: {validator_path}")
print(f"Using validator at: {validator_path}")
env = get_validator_env()
try:
result = subprocess.run(
[validator_path], env=env, check=True, capture_output=True, text=True
)
if result.stdout:
print(result.stdout)
return 0
except subprocess.CalledProcessError as exc:
if exc.stdout:
print(exc.stdout, file=sys.stderr)
if exc.stderr:
print(exc.stderr, file=sys.stderr)
return exc.returncode
except FileNotFoundError:
print(
"Error: Failed to run codeowners-validator after installation",
file=sys.stderr,
)
return 1
except Exception:
raise