Skip to content

Commit 74784cf

Browse files
committed
Okay
1 parent 690546d commit 74784cf

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

58 files changed

+2989
-55
lines changed

.editorconfig

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
insert_final_newline = true
7+
indent_style = space
8+
indent_size = 4
9+
trim_trailing_whitespace = true
10+
11+
[*.md]
12+
trim_trailing_whitespace = false
13+
14+
[*.yml]
15+
indent_size = 2

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
.idea/
2+
vendor/
3+
composer.lock
4+
.phpunit.result.cache

composer.json

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,25 +3,37 @@
33
"description": "Tools for managing git hooks in Laravel apps",
44
"keywords": [
55
"igorsgm",
6-
"laravel-git-hooks"
6+
"laravel-git-hooks",
7+
"git",
8+
"git-hooks",
9+
"pint-pre-commit",
10+
"pre-commit",
11+
"pre-commit-hook",
12+
"pint-pre-commit"
713
],
814
"homepage": "https://github.com/igorsgm/laravel-git-hooks",
915
"license": "MIT",
1016
"type": "library",
1117
"authors": [
1218
{
1319
"name": "Igor Moraes",
14-
"email": "[email protected]",
15-
"role": "Developer"
20+
"email": "[email protected]"
1621
}
1722
],
1823
"require": {
19-
"php": "^7.4|^8.0",
20-
"illuminate/support": "^8.0"
24+
"php": "^7.2|^8.0",
25+
"illuminate/container": "^5.6|^6.0|^7.0|^8.0|^9.0",
26+
"illuminate/config": "^5.6|^6.0|^7.0|^8.0|^9.0",
27+
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0",
28+
"illuminate/contracts": "^5.6|^6.0|^7.0|^8.0|^9.0",
29+
"illuminate/console": "^5.6|^6.0|^7.0|^8.0|^9.0",
30+
"illuminate/pipeline": "^5.6|^6.0|^7.0|^8.0|^9.0"
2131
},
2232
"require-dev": {
2333
"orchestra/testbench": "^6.0",
24-
"phpunit/phpunit": "^9.0"
34+
"phpunit/phpunit": "^9.0",
35+
"mockery/mockery": "^1.4.4",
36+
"laravel/pint": "^1.2"
2537
},
2638
"autoload": {
2739
"psr-4": {
@@ -36,7 +48,6 @@
3648
"scripts": {
3749
"test": "vendor/bin/phpunit",
3850
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
39-
4051
},
4152
"config": {
4253
"sort-packages": true
@@ -45,10 +56,9 @@
4556
"laravel": {
4657
"providers": [
4758
"Igorsgm\\LaravelGitHooks\\LaravelGitHooksServiceProvider"
48-
],
49-
"aliases": {
50-
"LaravelGitHooks": "Igorsgm\\LaravelGitHooks\\LaravelGitHooksFacade"
51-
}
59+
]
5260
}
53-
}
61+
},
62+
"minimum-stability": "dev",
63+
"prefer-stable": true
5464
}

config/config.php

Lines changed: 0 additions & 8 deletions
This file was deleted.

config/git-hooks.php

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?php
2+
3+
return [
4+
5+
/*
6+
|-----------------------------------------------------------------
7+
| Pre-Commit Hooks
8+
|-----------------------------------------------------------------
9+
|
10+
| The pre-commit hook is run first, before you even type in a commit message. It's used to inspect the snapshot
11+
| that's about to be committed, to see if you've forgotten something, to make sure tests run, or to examine
12+
| whatever you need to inspect in the code. Exiting non-zero from this hook aborts the commit, although you
13+
| can bypass it with git commit --no-verify. You can do things like check for code style (run lint or something
14+
| equivalent), check for trailing whitespace (the default hook does exactly this), or check for appropriate
15+
| documentation on new methods.
16+
|
17+
| These hooks must implement \Igorsgm\LaravelGitHooks\Contracts\PreCommitHook
18+
|
19+
*/
20+
'pre-commit' => [
21+
22+
],
23+
24+
/*
25+
|-----------------------------------------------------------------
26+
| Pre-Commit-Message Hooks
27+
|-----------------------------------------------------------------
28+
|
29+
| The prepare-commit-msg hook is run before the commit message editor is fired up but after the default message
30+
| is created. It lets you edit the default message before the commit author sees it. This hook takes a few
31+
| parameters: the path to the file that holds the commit message so far, the type of commit, and the commit
32+
| SHA-1 if this is an amended commit. This hook generally isn't useful for normal commits; rather, it's good for
33+
| commits where the default message is auto-generated, such as templated commit messages, merge commits, squashed
34+
| commits, and amended commits. You may use it in conjunction with a commit template to programmatically insert
35+
| information.
36+
|
37+
| These hooks must implement \Igorsgm\LaravelGitHooks\Contracts\MessageHook
38+
|
39+
*/
40+
'prepare-commit-msg' => [
41+
42+
],
43+
44+
/*
45+
|-----------------------------------------------------------------
46+
| Commit-Msg Hooks
47+
|-----------------------------------------------------------------
48+
|
49+
| The commit-msg hook takes one parameter, which again is the path to a temporary file that contains the commit
50+
| message written by the developer. If this script exits non-zero, Git aborts the commit process, so you can use
51+
| it to validate your project state or commit message before allowing a commit to go through.
52+
|
53+
| These hooks must implement \Igorsgm\LaravelGitHooks\Contracts\MessageHook
54+
|
55+
*/
56+
'commit-msg' => [
57+
58+
],
59+
60+
/*
61+
|-----------------------------------------------------------------
62+
| Post-Commit Hooks
63+
|-----------------------------------------------------------------
64+
|
65+
| After the entire commit process is completed, the post-commit hook runs. It doesn't take any parameters,
66+
| but you can easily get the last commit by running git log -1 HEAD. Generally, this script is used for
67+
| notification or something similar.
68+
|
69+
| These hooks must implement \Igorsgm\LaravelGitHooks\Contracts\PostCommitHook
70+
|
71+
*/
72+
'post-commit' => [
73+
74+
],
75+
76+
/*
77+
|-----------------------------------------------------------------
78+
| Pre-Rebase Hooks
79+
|-----------------------------------------------------------------
80+
|
81+
| The pre-rebase hook runs before you rebase anything and can halt the process by exiting non-zero.
82+
| You can use this hook to disallow rebasing any commits that have already been pushed.
83+
| The example pre-rebase hook that Git installs does this, although it makes some assumptions that may not
84+
| match with your workflow.
85+
|
86+
*/
87+
'pre-rebase' => [
88+
89+
],
90+
91+
/*
92+
|-----------------------------------------------------------------
93+
| Post-Rewrite Hooks
94+
|-----------------------------------------------------------------
95+
|
96+
| The post-rewrite hook is run by commands that replace commits, such as git commit --amend and git rebase
97+
| (though not by git filter-branch). Its single argument is which command triggered the rewrite, and it receives
98+
| a list of rewrites on stdin. This hook has many of the same uses as the post-checkout and post-merge hooks.
99+
|
100+
*/
101+
'post-rewrite' => [
102+
103+
],
104+
105+
/*
106+
|-----------------------------------------------------------------
107+
| Post-Checkout Hooks
108+
|-----------------------------------------------------------------
109+
|
110+
| After you run a successful git checkout, the post-checkout hook runs; you can use it to set up your working
111+
| directory properly for your project environment. This may mean moving in large binary files that you don't want
112+
| source controlled, auto-generating documentation, or something along those lines.
113+
|
114+
*/
115+
'post-checkout' => [
116+
117+
],
118+
119+
/*
120+
|-----------------------------------------------------------------
121+
| Post-Merge Hooks
122+
|-----------------------------------------------------------------
123+
|
124+
| The post-merge hook runs after a successful merge command. You can use it to restore data in the working tree
125+
| that Git can't track, such as permissions data. This hook can likewise validate the presence of files external
126+
| to Git control that you may want copied in when the working tree changes.
127+
|
128+
*/
129+
'post-merge' => [
130+
131+
],
132+
133+
/*
134+
|-----------------------------------------------------------------
135+
| Pre-Push Hooks
136+
|-----------------------------------------------------------------
137+
|
138+
| The pre-push hook runs during git push, after the remote refs have been updated but before any objects have
139+
| been transferred. It receives the name and location of the remote as parameters, and a list of to-be-updated
140+
| refs through stdin. You can use it to validate a set of ref updates before a push occurs (a non-zero exit code
141+
| will abort the push).
142+
|
143+
| These hooks must implement \Igorsgm\LaravelGitHooks\Contracts\PrePushHook
144+
|
145+
*/
146+
'pre-push' => [
147+
148+
],
149+
];

phpunit.xml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
5+
bootstrap="vendor/autoload.php"
6+
colors="true"
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
13+
<coverage>
14+
<include>
15+
<directory suffix=".php">./src</directory>
16+
</include>
17+
</coverage>
18+
<testsuites>
19+
<testsuite name="Unit">
20+
<directory suffix="Test.php">./tests</directory>
21+
</testsuite>
22+
</testsuites>
23+
</phpunit>

pint.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "laravel"
3+
}

src/CommitMessageStorage.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<?php
2+
3+
namespace Igorsgm\LaravelGitHooks;
4+
5+
class CommitMessageStorage implements Contracts\CommitMessageStorage
6+
{
7+
/**
8+
* {@inheritDoc}
9+
*/
10+
public function get(string $path): string
11+
{
12+
return file_get_contents($path);
13+
}
14+
15+
/**
16+
* {@inheritDoc}
17+
*/
18+
public function update(string $path, string $message): void
19+
{
20+
file_put_contents($path, $message);
21+
}
22+
}

src/Configurator.php

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?php
2+
3+
namespace Igorsgm\LaravelGitHooks;
4+
5+
use Igorsgm\LaravelGitHooks\Contracts\HookStorage;
6+
use Illuminate\Contracts\Foundation\Application;
7+
8+
class Configurator implements Contracts\Configurator
9+
{
10+
/**
11+
* @var HookStorage
12+
*/
13+
protected $storage;
14+
15+
/**
16+
* @var array
17+
*/
18+
protected $hooksMap;
19+
20+
/**
21+
* @var Application
22+
*/
23+
protected $app;
24+
25+
/**
26+
* @param Application $app
27+
* @param HookStorage $storage
28+
* @param array $hooksMap
29+
*/
30+
public function __construct(Application $app, HookStorage $storage, array $hooksMap)
31+
{
32+
$this->storage = $storage;
33+
$this->hooksMap = $hooksMap;
34+
$this->app = $app;
35+
}
36+
37+
/**
38+
* {@inheritDoc}
39+
*/
40+
public function run(): void
41+
{
42+
foreach ($this->hooksMap as $hook) {
43+
$hookStubPath = __DIR__.'/Console/Commands/stubs/hook';
44+
$command = 'git:'.$hook;
45+
46+
$hookPath = $this->app->basePath('.git/hooks/'.$hook);
47+
48+
$hookScript = str_replace(
49+
['{command}', '{path}'],
50+
[$command, $this->app->basePath()],
51+
file_get_contents($hookStubPath)
52+
);
53+
54+
$this->storage->store(
55+
$hookPath,
56+
$hookScript
57+
);
58+
}
59+
}
60+
}

0 commit comments

Comments
 (0)