|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of CaptainHook. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace sebastianfeldmann\CaptainHook\Runner\Action; |
|
11
|
|
|
|
|
12
|
|
|
use sebastianfeldmann\CaptainHook\Config; |
|
13
|
|
|
use sebastianfeldmann\CaptainHook\Console\IO; |
|
14
|
|
|
use sebastianfeldmann\CaptainHook\Exception; |
|
15
|
|
|
use sebastianfeldmann\CaptainHook\Git\Repository; |
|
16
|
|
|
use sebastianfeldmann\CaptainHook\Hook\Action; |
|
17
|
|
|
use Symfony\Component\Process\Process; |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Class Cli |
|
21
|
|
|
* |
|
22
|
|
|
* @package CaptainHook |
|
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
24
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
|
25
|
|
|
* @since Class available since Release 0.9.0 |
|
26
|
|
|
*/ |
|
27
|
|
|
class Cli implements Action |
|
28
|
|
|
{ |
|
29
|
|
|
/** |
|
30
|
|
|
* Execute the configured action. |
|
31
|
|
|
* |
|
32
|
|
|
* @param \sebastianfeldmann\CaptainHook\Config $config |
|
33
|
|
|
* @param \sebastianfeldmann\CaptainHook\Console\IO $io |
|
34
|
|
|
* @param \sebastianfeldmann\CaptainHook\Git\Repository $repository |
|
35
|
|
|
* @param \sebastianfeldmann\CaptainHook\Config\Action $action |
|
36
|
|
|
* @throws \sebastianfeldmann\CaptainHook\Exception\ActionExecution |
|
37
|
|
|
*/ |
|
38
|
3 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) |
|
39
|
|
|
{ |
|
40
|
3 |
|
$process = new Process($action->getAction()); |
|
41
|
3 |
|
$process->run(); |
|
42
|
|
|
|
|
43
|
3 |
|
if (!$process->isSuccessful()) { |
|
44
|
1 |
|
throw new Exception\ActionExecution($process->getOutput() . PHP_EOL . $process->getErrorOutput()); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
2 |
|
$io->write($process->getOutput()); |
|
48
|
2 |
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|