You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://packagist.org/packages/igorsgm/laravel-git-hooks)
<palign="center">A powerful and easy-to-use package for managing Git hooks within your Laravel projects. Improve your code quality, reduce the time spent on code reviews, and catch potential bugs before they make it into your repository.</p>
6
4
7
-
This is where your description should go. Try and limit it to a paragraph or two, and maybe throw in a mention of what PSRs you support to avoid any confusion with users and contributors.
-**Pre-configured Hooks:** Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
26
+
-**Manage Git Hooks:** Easily manage your Git hooks in your Laravel projects with a streamlined and organized approach.
27
+
-**Edit Commit Messages:** Gain control over your commit messages by customizing them to meet your project requirements and maintain a clean Git history.
28
+
-**Create Custom Hooks:** Add and integrate custom hooks tailored to your specific project needs, ensuring better code quality and adherence to guidelines.
29
+
-**Artisan Command for Hook Generation:** The package includes a convenient Artisan command that allows you to effortlessly generate new hooks of various types. Such as: `pre-commit`, `prepare-commit-msg`, `commit-msg`, `post-commit`, `pre-push`
30
+
-**Code Quality:** The package is thoroughly tested, with 100% of code coverage, ensuring its reliability and stability in a wide range of Laravel projects.
31
+
32
+
## 1️⃣ Installation
33
+
34
+
- You can install the package via composer:
35
+
```bash
36
+
composer require igorsgm/laravel-git-hooks --dev
37
+
```
38
+
39
+
- Publish the config file and customize it in the way you want:
- Now whenever you make a change in your `config/git-hooks.php` file, please register your git hooks by running the artisan command:
45
+
```bash
46
+
php artisan git-hooks:register
47
+
```
48
+
49
+
Once you've configured and registered the hooks, you're all set!
50
+
51
+
## 2️⃣ General Usage
52
+
### Usage of the configured pre-commit hooks
53
+
To use the already created pre-commit hooks of this package, you can simply edit the `pre-commit` section of git-hooks.php config file. Here's an example of how to configure them:
1) If you need to create a custom Git hook for your project, Laravel Git Hooks makes it easy with the `git-hooks:make` Artisan command. To create a new custom hook, simply run the following command:
67
+
```bash
68
+
php artisan git-hooks:make
69
+
```
70
+
This command will prompt you to choose the type of hook you want to create (e.g., `pre-commit`, `post-commit`, etc.) and to provide a name forthe hook. Once you've provided the required information, the command will generate a new hook classin the `app/Console/GitHooks` directory.
71
+
2) To start using your custom hook, open the generated file and implement the `handle()` method with your desired logic.
72
+
3) Add your custom hook to the appropriate array in the git-hooks.php config file:
class MyPostCommitHook implements \Igorsgm\GitHooks\Contracts\PostCommitHook
221
+
{
222
+
// ...
223
+
224
+
public functionhandle(Log$log, Closure $next)
225
+
{
226
+
// TODO: Implement post commit hook logic here.
227
+
228
+
// You can interact with the commit log
229
+
$hash = $log->getHash();
230
+
$author = $log->getAuthor();
231
+
$date = $log->getDate();
232
+
$message = $log->getMessage();
233
+
234
+
// If you want to cancel the commit, you have to throw an exception.
235
+
// i.e: throw new HookFailException();
236
+
237
+
// Run the next hook in the chain
238
+
return$next($log);
239
+
}
240
+
}
241
+
```
242
+
243
+
### Pre-push Hook
244
+
> The pre-push hook runs during git push, after the remote refs have been updated but before any objects have been
245
+
transferred. It receives the name and location of the remote as parameters, and a list of to-be-updated refs through
246
+
stdin. You can use it to validate a set of ref updates before a push occurs (a non-zero exit code will abort the push).
247
+
248
+
```php
249
+
// config/git-hooks.php
250
+
return [
251
+
...
252
+
'pre-push'=> [
253
+
\App\Console\GitHooks\MyPrePushHook::class,
254
+
],
255
+
...
256
+
];
257
+
```
258
+
259
+
The class structure of the `pre-push` hooks is the same as the `post-commit` hook shown right above, but implementing `\Igorsgm\GitHooks\Contracts\PrePushHook` interface.
260
+
23
261
### Testing
24
262
25
-
```bash
263
+
```bash
26
264
composer test
27
265
```
28
266
@@ -34,19 +272,11 @@ Please see [CHANGELOG](CHANGELOG.md) for more information what has changed recen
34
272
35
273
Please see [CONTRIBUTING](CONTRIBUTING.md) for details.
36
274
37
-
### Security
38
-
39
-
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
40
-
41
275
## Credits
42
276
43
-
-[Igor Moraes](https://github.com/igorsgm)
44
-
-[All Contributors](../../contributors)
277
+
- [Igor Moraes](https://github.com/igorsgm)
278
+
- [Pavel Buchnev](https://github.com/butschster)
45
279
46
280
## License
47
281
48
282
The MIT License (MIT). Please see [License File](LICENSE.md) for more information.
49
-
50
-
## Laravel Package Boilerplate
51
-
52
-
This package was generated using the [Laravel Package Boilerplate](https://laravelpackageboilerplate.com).
0 commit comments