|
| 1 | +repos: |
| 2 | + # ---------------------------- |
| 3 | + # Formatting |
| 4 | + # ---------------------------- |
| 5 | + - repo: https://github.com/psf/black |
| 6 | + rev: 24.4.2 |
| 7 | + hooks: |
| 8 | + - id: black |
| 9 | + language_version: python3.10 |
| 10 | + |
| 11 | + # ---------------------------- |
| 12 | + # Linting (hard errors only) |
| 13 | + # ---------------------------- |
| 14 | + - repo: https://github.com/PyCQA/flake8 |
| 15 | + rev: 6.1.0 |
| 16 | + hooks: |
| 17 | + - id: flake8 |
| 18 | + args: |
| 19 | + - --count |
| 20 | + - --select=E9,F63,F7,F82 |
| 21 | + - --show-source |
| 22 | + - --statistics |
| 23 | + |
| 24 | + # ---------------------------- |
| 25 | + # Generic hygiene |
| 26 | + # ---------------------------- |
| 27 | + - repo: https://github.com/pre-commit/pre-commit-hooks |
| 28 | + rev: v4.6.0 |
| 29 | + hooks: |
| 30 | + - id: trailing-whitespace |
| 31 | + - id: end-of-file-fixer |
| 32 | + - id: check-yaml |
| 33 | + - id: check-json |
| 34 | + - id: check-added-large-files |
| 35 | + args: ["--maxkb=100"] |
| 36 | + |
| 37 | + # ---------------------------- |
| 38 | + # Project-specific hooks |
| 39 | + # ---------------------------- |
| 40 | + - repo: local |
| 41 | + hooks: |
| 42 | + - id: pytest |
| 43 | + name: pytest |
| 44 | + entry: pytest -q |
| 45 | + language: system |
| 46 | + pass_filenames: false |
| 47 | + |
| 48 | + - id: secret-scan |
| 49 | + name: simple secret scan |
| 50 | + entry: | |
| 51 | + python - <<'EOF' |
| 52 | + import sys, re, pathlib |
| 53 | +
|
| 54 | + patterns = [ |
| 55 | + re.compile(r"AIzaSy[A-Za-z0-9_-]{33}"), |
| 56 | + re.compile(r"client_secrets\.json"), |
| 57 | + re.compile(r"oauth", re.I), |
| 58 | + ] |
| 59 | +
|
| 60 | + bad = False |
| 61 | +
|
| 62 | + for p in pathlib.Path(".").rglob("*"): |
| 63 | + if not p.is_file(): |
| 64 | + continue |
| 65 | + if p.suffix in {".pyc", ".png", ".jpg", ".jpeg", ".gif"}: |
| 66 | + continue |
| 67 | +
|
| 68 | + try: |
| 69 | + text = p.read_text(errors="ignore") |
| 70 | + except Exception: |
| 71 | + continue |
| 72 | +
|
| 73 | + for pat in patterns: |
| 74 | + if pat.search(text): |
| 75 | + print(f"Secret pattern found in {p}") |
| 76 | + bad = True |
| 77 | +
|
| 78 | + sys.exit(1 if bad else 0) |
| 79 | + EOF |
| 80 | + language: system |
| 81 | + pass_filenames: false |
0 commit comments