File tree Expand file tree Collapse file tree 9 files changed +60
-85
lines changed Expand file tree Collapse file tree 9 files changed +60
-85
lines changed Original file line number Diff line number Diff line change 3
3
namespace Igorsgm \GitHooks \Console \Commands ;
4
4
5
5
use Igorsgm \GitHooks \Contracts \HookCommand ;
6
- use Igorsgm \GitHooks \Exceptions \HookFailException ;
7
- use Igorsgm \GitHooks \Git \GitHelper ;
8
- use Igorsgm \GitHooks \Git \Log ;
9
- use Igorsgm \GitHooks \Traits \WithPipeline ;
6
+ use Igorsgm \GitHooks \Traits \WithCommitLog ;
10
7
use Illuminate \Console \Command ;
11
8
12
9
class PostCommit extends Command implements HookCommand
13
10
{
14
- use WithPipeline ;
11
+ use WithCommitLog ;
15
12
16
13
/**
17
14
* The name and signature of the console command.
@@ -34,34 +31,4 @@ public function getHook(): string
34
31
{
35
32
return 'post-commit ' ;
36
33
}
37
-
38
- /**
39
- * Execute the console command.
40
- *
41
- * @return mixed
42
- */
43
- public function handle ()
44
- {
45
- try {
46
- $ this ->sendLogCommitThroughHooks (
47
- new Log (
48
- GitHelper::getLastCommitFromLog ()
49
- )
50
- );
51
- } catch (HookFailException $ e ) {
52
- return 1 ;
53
- }
54
- }
55
-
56
- /**
57
- * Send the log commit through the pipes
58
- *
59
- * @param Log $log
60
- */
61
- protected function sendLogCommitThroughHooks (Log $ log ): void
62
- {
63
- $ this ->makePipeline ()
64
- ->send ($ log )
65
- ->thenReturn ();
66
- }
67
34
}
Original file line number Diff line number Diff line change @@ -38,7 +38,7 @@ public function getHook(): string
38
38
/**
39
39
* Execute the console command.
40
40
*
41
- * @return mixed
41
+ * @return int|void
42
42
*/
43
43
public function handle ()
44
44
{
Original file line number Diff line number Diff line change 3
3
namespace Igorsgm \GitHooks \Console \Commands ;
4
4
5
5
use Igorsgm \GitHooks \Contracts \HookCommand ;
6
- use Igorsgm \GitHooks \Exceptions \HookFailException ;
7
- use Igorsgm \GitHooks \Git \GitHelper ;
8
- use Igorsgm \GitHooks \Git \Log ;
9
- use Igorsgm \GitHooks \Traits \WithPipeline ;
6
+ use Igorsgm \GitHooks \Traits \WithCommitLog ;
10
7
use Illuminate \Console \Command ;
11
8
12
9
class PrePush extends Command implements HookCommand
13
10
{
14
- use WithPipeline ;
11
+ use WithCommitLog ;
15
12
16
13
/**
17
14
* The name and signature of the console command.
@@ -34,34 +31,4 @@ public function getHook(): string
34
31
{
35
32
return 'pre-push ' ;
36
33
}
37
-
38
- /**
39
- * Execute the console command.
40
- *
41
- * @return mixed
42
- */
43
- public function handle ()
44
- {
45
- try {
46
- $ this ->sendLogCommitThroughHooks (
47
- new Log (
48
- GitHelper::getLastCommitFromLog ()
49
- )
50
- );
51
- } catch (HookFailException $ e ) {
52
- return 1 ;
53
- }
54
- }
55
-
56
- /**
57
- * Send the log commit through the pipes
58
- *
59
- * @param Log $log
60
- */
61
- protected function sendLogCommitThroughHooks (Log $ log ): void
62
- {
63
- $ this ->makePipeline ()
64
- ->send ($ log )
65
- ->thenReturn ();
66
- }
67
34
}
Original file line number Diff line number Diff line change @@ -25,6 +25,8 @@ class RegisterHooks extends Command
25
25
* Execute the console command.
26
26
*
27
27
* @param GitHooks $gitHooks
28
+ * @return void
29
+ * @throws \Exception
28
30
*/
29
31
public function handle (GitHooks $ gitHooks )
30
32
{
Original file line number Diff line number Diff line change @@ -56,7 +56,7 @@ public function __construct(string $log)
56
56
*/
57
57
private function parse (array $ lines ): void
58
58
{
59
- foreach ($ lines as $ key => $ line ) {
59
+ foreach ($ lines as $ line ) {
60
60
if (strpos ($ line , 'commit ' ) === 0 ) {
61
61
preg_match ('/(?<hash>[a-z0-9]{40})/ ' , $ line , $ matches );
62
62
$ this ->hash = $ matches ['hash ' ] ?? null ;
Original file line number Diff line number Diff line change 2
2
3
3
namespace Igorsgm \GitHooks ;
4
4
5
+ use Exception ;
6
+
5
7
class GitHooks
6
8
{
7
9
/**
@@ -37,12 +39,14 @@ public function getAvailableHooks()
37
39
/**
38
40
* Install git hook
39
41
*
40
- * @param string $hook
42
+ * @param string $hookName
43
+ * @return void
44
+ * @throws Exception
41
45
*/
42
46
public function install ($ hookName )
43
47
{
44
48
if (! is_dir ($ this ->getGitHooksDir ())) {
45
- throw new \ Exception ('Git not initialized in this project. ' );
49
+ throw new Exception ('Git not initialized in this project. ' );
46
50
}
47
51
48
52
$ command = 'git-hooks: ' .$ hookName ;
Original file line number Diff line number Diff line change 3
3
namespace Igorsgm \GitHooks ;
4
4
5
5
use Closure ;
6
- use Exception ;
7
6
use Illuminate \Contracts \Container \Container ;
8
7
use Illuminate \Pipeline \Pipeline ;
9
8
use Throwable ;
@@ -97,10 +96,8 @@ protected function carry()
97
96
: $ pipe (...$ parameters );
98
97
99
98
return $ this ->handleCarry ($ carry );
100
- } catch (Exception $ e ) {
101
- $ this ->handleException ($ passable , $ e );
102
99
} catch (Throwable $ e ) {
103
- $ this ->handleException ($ passable , $ e );
100
+ return $ this ->handleException ($ passable , $ e );
104
101
}
105
102
};
106
103
};
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ namespace Igorsgm \GitHooks \Traits ;
4
+
5
+ use Igorsgm \GitHooks \Exceptions \HookFailException ;
6
+ use Igorsgm \GitHooks \Git \GitHelper ;
7
+ use Igorsgm \GitHooks \Git \Log ;
8
+
9
+ trait WithCommitLog
10
+ {
11
+ use WithPipeline;
12
+
13
+ /**
14
+ * Execute the console command.
15
+ *
16
+ * @return int|void
17
+ */
18
+ public function handle ()
19
+ {
20
+ try {
21
+ $ this ->sendLogCommitThroughHooks (
22
+ new Log (
23
+ GitHelper::getLastCommitFromLog ()
24
+ )
25
+ );
26
+ } catch (HookFailException $ e ) {
27
+ return 1 ;
28
+ }
29
+ }
30
+
31
+ /**
32
+ * Send the log commit through the pipes
33
+ *
34
+ * @param Log $log
35
+ */
36
+ protected function sendLogCommitThroughHooks (Log $ log ): void
37
+ {
38
+ $ this ->makePipeline ()
39
+ ->send ($ log )
40
+ ->thenReturn ();
41
+ }
42
+ }
Original file line number Diff line number Diff line change @@ -21,8 +21,8 @@ protected function makePipeline(): Pipeline
21
21
22
22
return $ pipeline
23
23
->through ($ this ->getRegisteredHooks ())
24
- ->withCallback ($ this ->showInfoAboutHook ());
25
- // ->withExceptionCallback($this->showHookErrorAndExit());
24
+ ->withCallback ($ this ->showInfoAboutHook ())
25
+ ->withExceptionCallback ($ this ->showHookErrorAndExit ());
26
26
}
27
27
28
28
/**
@@ -61,11 +61,7 @@ public function getRegisteredHooks(): array
61
61
$ hooks = collect ((array ) config ('git-hooks. ' .$ this ->getHook ()));
62
62
63
63
return $ hooks ->map (function ($ hook , $ i ) {
64
- if (is_int ($ i )) {
65
- return $ hook ;
66
- }
67
-
68
- return $ i ;
64
+ return is_int ($ i ) ? $ hook : $ i ;
69
65
})->all ();
70
66
}
71
67
}
You can’t perform that action at this time.
0 commit comments