From 2c67903d41a6083e0087f3e606017b9bc3213b22 Mon Sep 17 00:00:00 2001 From: Vladimir Valekzhanin Date: Tue, 6 Oct 2026 15:05:05 +0300 Subject: [PATCH 1/4] chore: add pre-commit hooks for lint, format and unit tests --- .pre-commit-config.yaml | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .pre-commit-config.yaml diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..6b86cc7 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,37 @@ +# Pre-commit hooks for this Java/Maven project (the Java-conventional +# equivalent of husky hooks in JS projects). +# +# All hooks are CHECK-ONLY (no auto-fix): +# - lint via `mvn checkstyle:check` +# - format via `mvn spotless:check` (use `mvn spotless:apply` manually to fix) +# - unit tests via `mvn test` (integration tests tagged `integration` are +# already excluded from the default build via surefire `excludedGroups` +# in pom.xml, so no live backend is needed) +# +# Install/activate (per clone): +# pip install pre-commit # or: brew install pre-commit +# pre-commit install +# +# Run manually: +# pre-commit run --all-files +repos: + - repo: local + hooks: + - id: checkstyle-check + name: "lint: mvn checkstyle:check" + entry: mvn -B checkstyle:check + language: system + pass_filenames: false + always_run: true + - id: spotless-check + name: "format: mvn spotless:check" + entry: mvn -B spotless:check + language: system + pass_filenames: false + always_run: true + - id: unit-tests + name: "test: mvn test (unit only, integration excluded)" + entry: mvn -B test + language: system + pass_filenames: false + always_run: true From 6356389d5c770d74af49bb925631ab1ca8af457a Mon Sep 17 00:00:00 2001 From: Vladimir Valekzhanin Date: Tue, 6 Oct 2026 15:07:13 +0300 Subject: [PATCH 2/4] chore: add PowerShell setup script for pre-commit hooks --- setup.ps1 | 43 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 setup.ps1 diff --git a/setup.ps1 b/setup.ps1 new file mode 100644 index 0000000..1f59885 --- /dev/null +++ b/setup.ps1 @@ -0,0 +1,43 @@ +<# +.SYNOPSIS + Sets up git pre-commit hooks for this repo (pre-commit framework). + +.DESCRIPTION + Installs the `pre-commit` package if missing and runs `pre-commit install` + so the lint/format/unit-test checks run automatically on every `git commit`. + Works on Windows PowerShell 5.1 and PowerShell 7+. +#> +$ErrorActionPreference = 'Stop' + +function Test-Command($Name) { + return $null -ne (Get-Command $Name -ErrorAction SilentlyContinue) +} + +if (-not (Test-Command 'git')) { + Write-Error 'git not found in PATH. Install Git for Windows and retry.' + exit 1 +} + +if (-not (Test-Command 'python')) { + Write-Error 'Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.' + exit 1 +} + +# Must run inside the repo so hooks land in .git/hooks. +$null = git rev-parse --show-toplevel 2>$null +if ($LASTEXITCODE -ne 0) { + Write-Error 'Not inside a git repository. Run this script from the repo root.' + exit 1 +} + +python -m pre_commit --version > $null 2>&1 +if ($LASTEXITCODE -ne 0) { + Write-Host 'pre-commit not found, installing via pip...' + python -m pip install --user pre-commit +} + +# Use `python -m` so it works even if pip --user Scripts dir is not on PATH. +python -m pre_commit install +Write-Host '' +Write-Host 'Done. Hooks will run on every commit.' +Write-Host 'To check everything right now: pre-commit run --all-files' From bffab9f02f4ecd446c50abc521fb7fa9bcffa04b Mon Sep 17 00:00:00 2001 From: Vladimir Valekzhanin Date: Tue, 6 Oct 2026 15:09:20 +0300 Subject: [PATCH 3/4] fix: resolve python or python3 in setup script --- setup.ps1 | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/setup.ps1 b/setup.ps1 index 1f59885..1a11d1d 100644 --- a/setup.ps1 +++ b/setup.ps1 @@ -18,7 +18,8 @@ if (-not (Test-Command 'git')) { exit 1 } -if (-not (Test-Command 'python')) { +$Python = if (Test-Command 'python') { 'python' } elseif (Test-Command 'python3') { 'python3' } else { $null } +if (-not $Python) { Write-Error 'Python not found in PATH. Install Python 3 (python.org) with "Add to PATH" and retry.' exit 1 } @@ -30,14 +31,14 @@ if ($LASTEXITCODE -ne 0) { exit 1 } -python -m pre_commit --version > $null 2>&1 +& $Python -m pre_commit --version > $null 2>&1 if ($LASTEXITCODE -ne 0) { Write-Host 'pre-commit not found, installing via pip...' - python -m pip install --user pre-commit + & $Python -m pip install --user pre-commit } # Use `python -m` so it works even if pip --user Scripts dir is not on PATH. -python -m pre_commit install +& $Python -m pre_commit install Write-Host '' Write-Host 'Done. Hooks will run on every commit.' Write-Host 'To check everything right now: pre-commit run --all-files' From f151c51200a8756807e08b8df9a1cde151d0ecbb Mon Sep 17 00:00:00 2001 From: Vladimir Valekzhanin Date: Tue, 6 Oct 2026 15:11:01 +0300 Subject: [PATCH 4/4] docs: document git hooks setup --- README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/README.md b/README.md index 148e859..1f22d8a 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,24 @@ mvn javafx:run в `Program.java`). Для проверки вёрстки отдельной страницы можно временно подменить `INITIAL_PAGE_PATH` на нужный FXML. +## Git hooks + +Перед каждым коммитом автоматически проверяются: линт (`checkstyle:check`), +формат (`spotless:check`) и unit-тесты (`mvn test`, без интеграционных). +Настройка один раз на клон: + +```powershell +# Windows (PowerShell 5.1 / 7+): +.\setup.ps1 + +# macOS / Linux: +pip install pre-commit +pre-commit install +``` + +Ручная проверка всего сразу: `pre-commit run --all-files`. +Если упал формат — поправить: `mvn spotless:apply`. + ## RBAC В системе предусмотрено 3 роли: пользователь, модератор и администратор: