Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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
18 changes: 18 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 роли: пользователь, модератор и администратор:
Expand Down
44 changes: 44 additions & 0 deletions setup.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
<#
.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
}

$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
}

# 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'
Loading