build(ci): configure pre-commit hook with modern stages and file argument support

This commit is contained in:
omkarande14
2026-09-28 17:42:12 +05:30
parent 3e1342fad0
commit 10bd585f83
2 changed files with 7 additions and 6 deletions
+2 -2
View File
@@ -7,5 +7,5 @@ repos:
name: Check Git Hygiene and PII Leakage name: Check Git Hygiene and PII Leakage
entry: python scripts/check_git_hygiene.py entry: python scripts/check_git_hygiene.py
language: system language: system
stages: [commit] stages: [pre-commit]
always_run: true pass_filenames: true
+5 -4
View File
@@ -110,9 +110,9 @@ def get_staged_or_tracked_files() -> list[str]:
files = [f.strip() for f in res2.stdout.splitlines() if f.strip()] files = [f.strip() for f in res2.stdout.splitlines() if f.strip()]
return files return files
def check_current_hygiene() -> bool: def check_current_hygiene(specified_files: list[str] = None) -> bool:
run_synthetic_canary_test() run_synthetic_canary_test()
files = get_staged_or_tracked_files() files = specified_files if specified_files else get_staged_or_tracked_files()
violations = [] violations = []
salt, forbidden_hashes = load_forbidden_hashes() salt, forbidden_hashes = load_forbidden_hashes()
@@ -142,7 +142,7 @@ def check_current_hygiene() -> bool:
print(f" - {v}") print(f" - {v}")
return False return False
print("[+] Git hygiene check passed cleanly: No un-anonymized PII, real GSTINs, or private data tracked.") print(f"[+] Git hygiene check passed cleanly: No un-anonymized PII, real GSTINs, or private data tracked ({len(files)} files checked).")
return True return True
def scan_full_history() -> bool: def scan_full_history() -> bool:
@@ -201,9 +201,10 @@ def scan_full_history() -> bool:
if __name__ == "__main__": if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Git Hygiene and PII Leakage Auditor") parser = argparse.ArgumentParser(description="Git Hygiene and PII Leakage Auditor")
parser.add_argument("--history", action="store_true", help="Scan entire repository commit history and blob tree") parser.add_argument("--history", action="store_true", help="Scan entire repository commit history and blob tree")
parser.add_argument("files", nargs="*", default=None, help="Files to scan (passed by pre-commit)")
args = parser.parse_args() args = parser.parse_args()
success = scan_full_history() if args.history else check_current_hygiene() success = scan_full_history() if args.history else check_current_hygiene(args.files)
if not success: if not success:
sys.exit(1) sys.exit(1)
sys.exit(0) sys.exit(0)