|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* This file is part of CaptainHook |
|
5
|
|
|
* |
|
6
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
9
|
|
|
* file that was distributed with this source code. |
|
10
|
|
|
*/ |
|
11
|
|
|
|
|
12
|
|
|
namespace CaptainHook\App\Hook; |
|
13
|
|
|
|
|
14
|
|
|
use CaptainHook\App\Config; |
|
15
|
|
|
use CaptainHook\App\Console\IO; |
|
16
|
|
|
use CaptainHook\App\Exception\ActionFailed; |
|
17
|
|
|
use Exception; |
|
18
|
|
|
use SebastianFeldmann\Git\Repository; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Debug hook to test hook triggering |
|
22
|
|
|
* |
|
23
|
|
|
* @package CaptainHook |
|
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
25
|
|
|
* @link https://github.com/captainhook-git/captainhook |
|
26
|
|
|
* @since Class available since Release 4.0.4 |
|
27
|
|
|
*/ |
|
28
|
|
|
abstract class Debug implements Action |
|
29
|
|
|
{ |
|
30
|
|
|
/** |
|
31
|
|
|
* Executes the action |
|
32
|
|
|
* |
|
33
|
|
|
* @param \CaptainHook\App\Config $config |
|
34
|
|
|
* @param \CaptainHook\App\Console\IO $io |
|
35
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
36
|
|
|
* @param \CaptainHook\App\Config\Action $action |
|
37
|
|
|
* @return void |
|
38
|
|
|
* @throws \Exception |
|
39
|
|
|
*/ |
|
40
|
|
|
abstract public function execute(Config $config, IO $io, Repository $repository, Config\Action $action): void; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* Generate some debug output |
|
44
|
|
|
* |
|
45
|
|
|
* @param \CaptainHook\App\Console\IO $io |
|
46
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
|
47
|
|
|
* @return void |
|
48
|
|
|
*/ |
|
49
|
3 |
|
protected function debugOutput(IO $io, Repository $repository): void |
|
50
|
|
|
{ |
|
51
|
3 |
|
$originalHookArguments = $io->getArguments(); |
|
52
|
|
|
|
|
53
|
3 |
|
$currentGitTag = 'no tags yet'; |
|
|
|
|
|
|
54
|
|
|
try { |
|
55
|
3 |
|
$currentGitTag = $repository->getInfoOperator()->getCurrentTag(); |
|
56
|
1 |
|
} catch (Exception $e) { |
|
57
|
|
|
// ignore it, it just means there are no tags yet |
|
58
|
|
|
} |
|
59
|
3 |
|
$io->write($this->getArgumentOutput($originalHookArguments), false); |
|
60
|
3 |
|
$io->write(' <comment>Current git-tag:</comment> ' . $currentGitTag); |
|
61
|
3 |
|
$io->write( |
|
62
|
3 |
|
' <comment>StandardInput:</comment> ' . PHP_EOL . |
|
63
|
3 |
|
' ' . implode(PHP_EOL . ' ', $io->getStandardInput()) |
|
64
|
3 |
|
); |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* Format output to display original hook arguments |
|
69
|
|
|
* |
|
70
|
|
|
* Returns a string with a newline character at the end. |
|
71
|
|
|
* |
|
72
|
|
|
* @param array<string> $args |
|
73
|
|
|
* @return string |
|
74
|
|
|
*/ |
|
75
|
3 |
|
protected function getArgumentOutput(array $args): string |
|
76
|
|
|
{ |
|
77
|
3 |
|
$out = ' <comment>Original arguments:</comment>' . PHP_EOL; |
|
78
|
3 |
|
foreach ($args as $name => $value) { |
|
79
|
3 |
|
$out .= ' <comment>' . $name . '</comment> => ' . $value . PHP_EOL; |
|
80
|
|
|
} |
|
81
|
3 |
|
return $out; |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|