mr-feek / laravel-git-hooks
A simple laravel package for adding custom git hooks to your laravel projects. Ships with phpunit, phpcs, and eslint
Installs: 2 349
Dependents: 0
Suggesters: 0
Security: 0
Stars: 12
Watchers: 3
Forks: 6
Open Issues: 3
Requires
- php: ~5.6|~7.0
- illuminate/console: ~5.1
- illuminate/support: ~5.1
- phpunit/phpunit: >=5.4.3
- squizlabs/php_codesniffer: ^3.0
- symfony/finder: ^3.3
- weebly/phpstan-laravel: ^1.0
Requires (Dev)
- mockery/mockery: ^0.9.9
- moon/artisan: ^v1.9
- orchestra/testbench: ~3.0
This package is auto-updated.
Last update: 2021-08-11 08:15:47 UTC
README
This is a community project and not an "official" Laravel one
This package provides a way to add custom git hooks to your laravel project. Easily configure any command to be fired throughout the git-hook process. Want to ensure that all tests pass before a bad commit is pushed? Now's your chance!
Currently, the following git hooks are supported:
- pre-commit
- prepare-commit-msg
- pre-push
- post-checkout
Install
Via Composer
$ composer require mr-feek/laravel-git-hooks --dev
Edit your laravel project's composer.json
so that these hooks are installed for every developer after they use composer.
"post-autoload-dump": [
...
"@php artisan hooks:install"
]
Configuration
- Publish this package's configuration file:
php artisan vendor:publish --provider="Feek\LaravelGitHooks\LaravelGitHooksServiceProvider"
- Register specific artisan commands to be run in the configuration array. For example, all commands nested within the
pre-commit
array key will be run prior to a git commit. All commands nested within thepre-push
array key will be run prior to a git push. If any of these registered commands fail, then the git action will be prevented.
<?php return [ 'commit-msg' => [ // ], 'pre-commit' => [ 'php artisan hooks:phpcs --diff --proxiedArguments="-p -n --standard=PSR2"', 'php artisan hooks:eslint --diff --proxiedArguments="--fix --quiet"', ], 'pre-push' => [ './vendor/bin/phpunit' ], 'post-checkout' => [ 'php artisan hooks:install-deps' ], 'prepare-commit-msg' => [ 'php artisan hooks:semantic-commits', ], ];
Commands
This package ships with several handy artisan commands which work nicely as git hooks. The following commands come included:
- phpcs
- phpcbf
- phpstan
- If you are using this command, you will have a much better experience by creating a custom phpstan.neon file
- install dependencies (composer, yarn, npm)
- eslint
- semantic commit messages
Sniffer Commands
The PHPCS
, PHPCBF
, PHPSTAN
, and ESLINT
commands all allow you to pass arguments to the underlying process being executed. You
can utilize this via the --proxiedArguments
flag. In the code examples above, the following phpcs command will be executed:
phpcs -p -n --standard=PSR2
Supported Versions Of Laravel
Laravel ^5.5 is actively supported. Need support for earlier versions of Laravel? Feel free to open a PR
Change log
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING and CODE_OF_CONDUCT for details.
Wondering how to go about working on a laravel package? See http://laraveldaily.com/how-to-create-a-laravel-5-package-in-10-easy-steps/ and https://laravel.com/docs/5.5/packages
Credits
- Fiachra McDermott
- All Contributors
- Fish hook icon originally provided by Carson Wittenberg.
License
The MIT License (MIT). Please see License File for more information