Add pre-commit hook for formatting and tests
- Add scripts/pre-commit hook that runs format check and tests - Add mix hooks.install alias to install the hook - Document git hooks in AGENTS.md - Fix test database config to use local user 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
1e61383eb6
commit
67657bf717
4 changed files with 45 additions and 3 deletions
|
|
@ -16,12 +16,19 @@ mix deps.get
|
|||
# Create database
|
||||
mix ecto.create
|
||||
|
||||
# Install git hooks
|
||||
mix hooks.install
|
||||
|
||||
# Start the server
|
||||
mix phx.server
|
||||
```
|
||||
|
||||
The app will be available at http://localhost:4000
|
||||
|
||||
### Git hooks
|
||||
|
||||
A pre-commit hook is provided that runs `mix format --check-formatted` and `mix test` before each commit. Install it with `mix hooks.install` or manually copy `scripts/pre-commit` to `.git/hooks/pre-commit`.
|
||||
|
||||
## Project guidelines
|
||||
|
||||
- **Prefer small, focused commits** - each commit should represent a single logical change
|
||||
|
|
|
|||
|
|
@ -6,8 +6,8 @@ import Config
|
|||
# to provide built-in test partitioning in CI environment.
|
||||
# Run `mix help test` for more information.
|
||||
config :localspot, Localspot.Repo,
|
||||
username: "postgres",
|
||||
password: "postgres",
|
||||
username: "kevinsivic",
|
||||
password: "",
|
||||
hostname: "localhost",
|
||||
database: "localspot_test#{System.get_env("MIX_TEST_PARTITION")}",
|
||||
pool: Ecto.Adapters.SQL.Sandbox,
|
||||
|
|
|
|||
9
mix.exs
9
mix.exs
|
|
@ -88,7 +88,14 @@ defmodule Localspot.MixProject do
|
|||
"esbuild localspot --minify",
|
||||
"phx.digest"
|
||||
],
|
||||
precommit: ["compile --warnings-as-errors", "deps.unlock --unused", "format", "test"]
|
||||
precommit: ["compile --warnings-as-errors", "deps.unlock --unused", "format", "test"],
|
||||
"hooks.install": &hooks_install/1
|
||||
]
|
||||
end
|
||||
|
||||
defp hooks_install(_) do
|
||||
File.cp!("scripts/pre-commit", ".git/hooks/pre-commit")
|
||||
File.chmod!(".git/hooks/pre-commit", 0o755)
|
||||
Mix.shell().info("Installed pre-commit hook")
|
||||
end
|
||||
end
|
||||
|
|
|
|||
28
scripts/pre-commit
Executable file
28
scripts/pre-commit
Executable file
|
|
@ -0,0 +1,28 @@
|
|||
#!/bin/sh
|
||||
#
|
||||
# Pre-commit hook for localspot
|
||||
# Runs formatting check and tests before allowing commits
|
||||
#
|
||||
# To install: cp scripts/pre-commit .git/hooks/pre-commit
|
||||
|
||||
set -e
|
||||
|
||||
echo "Running pre-commit checks..."
|
||||
|
||||
# Check formatting (without modifying files)
|
||||
echo "Checking code formatting..."
|
||||
mix format --check-formatted
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Code is not formatted. Run 'mix format' to fix."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Run tests
|
||||
echo "Running tests..."
|
||||
mix test
|
||||
if [ $? -ne 0 ]; then
|
||||
echo "❌ Tests failed. Please fix before committing."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
echo "✅ All pre-commit checks passed!"
|
||||
Loading…
Reference in a new issue