Skip to content

Commit

Permalink
chore: Add pre-commit hooks with config instructions
Browse files Browse the repository at this point in the history
Signed-off-by: Sietze van Buuren <s.van.buuren@gmail.com>
  • Loading branch information
swvanbuuren committed Nov 30, 2024
1 parent e01c6eb commit 78d3e10
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
26 changes: 26 additions & 0 deletions .githooks/commit-msg
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#!/bin/sh
#
# A hook script to check that the commit message follows Angular style.

# Regex to match Angular commit message style (validating only the first line)
COMMIT_MSG_REGEX="^(feat|fix|docs|style|refactor|test|chore|build|ci|perf|revert)(\(\w+\))?: .{1,50}"

# Read only the first line of the commit message
FIRST_LINE=$(head -n 1 "$1")

# Validate the first line
if ! echo "$FIRST_LINE" | grep -qE "$COMMIT_MSG_REGEX"; then
echo >&2 "ERROR: Commit message does not follow Angular style."
echo >&2 ""
echo >&2 "The first line must follow the format: <type>(<scope>): <short description>"
echo >&2 ""
echo >&2 "Examples:"
echo >&2 " feat(core): add new feature"
echo >&2 " fix(parser): handle edge case"
echo >&2 " docs(readme): update project overview"
echo >&2 ""
exit 1
fi

# If the first line is valid, allow the commit
exit 0
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,15 @@ started](https://swvanbuuren.github.io/simple-cdd-yaml/getting_started/) guide.
Check out the [documentation](https://swvanbuuren.github.io/simple-cdd-yaml/) to
get started, find more background information and query the code reference.

## Pre-commit hooks

This repository comes with pre-commit hooks, which are stored in
[`.githooks`](.githooks). To enable the hooks issue:

```bash
git config --local core.hooksPath .githooks/
```

## License

An MIT style license applies for Simple-CDD-YAML, see the [LICENSE](LICENSE)
Expand Down

0 comments on commit 78d3e10

Please sign in to comment.