-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #18 from vardumper/feature/add-composer-hooks
chore(git hooks): added brainmaestro/composer-git-hooks alpha release…
- Loading branch information
Showing
4 changed files
with
173 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Commit message must be in correct format | ||
# https://semver.org/ | ||
# https://www.conventionalcommits.org/ | ||
# https://youtu.be/nOVZxZX5dx8 | ||
|
||
# Colors | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
YELLOW='\033[0;33m' | ||
NC='\033[0m' # No Color | ||
|
||
# commit headline must be in the correct format | ||
commit_msg_file=$(git rev-parse --git-dir)/COMMIT_EDITMSG | ||
|
||
# Read the commit message from the COMMIT_EDITMSG file | ||
commit_msg=$(cat "$commit_msg_file") | ||
|
||
# Regular expression pattern for conventional commit format | ||
pattern="^(build|ci|docs|feat|fix|perf|refactor|style|test|chore|revert|release)(\(.+\))?: .{1,}" | ||
|
||
# Check if the commit message matches the pattern | ||
if [[ ! $commit_msg =~ $pattern ]]; then | ||
printf "${RED}Aborting. ${YELLOW}Your commit message is invalid.${NC} | ||
Syntax: | ||
${YELLOW}<type>${NC}(${YELLOW}<scope>${NC}): ${YELLOW}<subject>${NC} | ||
${YELLOW}<type>${NC} can be one of | ||
build chore ci docs feat fix perf refactor revert style test | ||
${YELLOW}<scope>${NC} is optional | ||
${YELLOW}<subject>${NC} there must be a description of the change | ||
Find more on this topic here: | ||
- https://semver.org/ | ||
- https://www.conventionalcommits.org/ | ||
- https://youtu.be/nOVZxZX5dx8 | ||
" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Colors | ||
RED='\033[0;31m' | ||
GREEN='\033[0;32m' | ||
YELLOW='\033[0;33m' | ||
NC='\033[0m' # No Color | ||
|
||
echo "pre commit hook start" | ||
printf "committing as ${YELLOW}$(git config user.name) ${NC}/ ${YELLOW}$(git config user.email)${NC}\n" | ||
|
||
PHP_CS_FIXER="./vendor/bin/php-cs-fixer" | ||
PHP_CS_CONFIG=".php-cs-fixer.dist.php" | ||
PHP_STAN="./vendor/bin/phpstan" | ||
CHANGED_FILES=$(git diff --cached --name-only --diff-filter=ACM -- '*.php') | ||
|
||
if [ -n "$CHANGED_FILES" ]; then | ||
echo "php-cs-fixer start" | ||
$PHP_CS_FIXER fix --config "$PHP_CS_CONFIG" $CHANGED_FILES; | ||
echo "php-cs-fixer finish" | ||
|
||
echo "php-stan start" | ||
if $PHP_STAN analyse -c ./phpstan.neon --memory_limit=512M $CHANGED_FILES; then | ||
echo "php-stan finish" | ||
else | ||
printf "${RED}Aborting. ${YELLOW}Please fix the errors php-stan found.${NC}\n" | ||
exit 1 | ||
fi | ||
|
||
git add $CHANGED_FILES; | ||
fi | ||
|
||
echo "pre commit hook finish" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.