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\Hook\Message\Action; |
11
|
|
|
|
12
|
|
|
use SebastianFeldmann\CaptainHook\Config; |
13
|
|
|
use SebastianFeldmann\CaptainHook\Console\IO; |
14
|
|
|
use SebastianFeldmann\CaptainHook\Console\IOUtil; |
15
|
|
|
use SebastianFeldmann\CaptainHook\Exception\ActionFailed; |
16
|
|
|
use SebastianFeldmann\CaptainHook\Hook\Message\RuleBook; |
17
|
|
|
use SebastianFeldmann\Cli\Output\Util as OutputUtil; |
18
|
|
|
use SebastianFeldmann\Git\Repository; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Class Beams |
22
|
|
|
* |
23
|
|
|
* @package CaptainHook |
24
|
|
|
* @author Sebastian Feldmann <[email protected]> |
25
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
26
|
|
|
* @since Class available since Release 0.9.0 |
27
|
|
|
*/ |
28
|
|
|
class Beams extends Book |
29
|
|
|
{ |
30
|
|
|
/** |
31
|
|
|
* Execute the configured action. |
32
|
|
|
* |
33
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config $config |
34
|
|
|
* @param \SebastianFeldmann\CaptainHook\Console\IO $io |
35
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
36
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config\Action $action |
37
|
|
|
* @throws \Exception |
38
|
|
|
*/ |
39
|
2 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) |
40
|
|
|
{ |
41
|
2 |
|
$options = $action->getOptions(); |
42
|
2 |
|
$book = new RuleBook(); |
43
|
2 |
|
$book->setRules(RuleBook\RuleSet::beams( |
44
|
2 |
|
$options->get('subjectLength', 50), |
45
|
2 |
|
$options->get('bodyLineLength', 72) |
46
|
|
|
)); |
47
|
|
|
|
48
|
|
|
try { |
49
|
2 |
|
$this->validate($book, $repository); |
50
|
1 |
|
} catch (ActionFailed $exception) { |
51
|
1 |
|
$this->writeError($io, $repository); |
52
|
1 |
|
throw ActionFailed::fromPrevious($exception); |
53
|
|
|
} |
54
|
1 |
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Write error to stdErr. |
58
|
|
|
* |
59
|
|
|
* @param \SebastianFeldmann\CaptainHook\Console\IO $io |
60
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
61
|
|
|
*/ |
62
|
1 |
|
private function writeError(IO $io, Repository $repository) |
63
|
|
|
{ |
64
|
1 |
|
$io->writeError(array_merge( |
65
|
|
|
[ |
66
|
1 |
|
'<error>COMMIT MESSAGE DOES NOT MEET THE REQUIREMENTS</error>', |
67
|
1 |
|
IOUtil::getLineSeparator(), |
68
|
|
|
], |
69
|
1 |
|
OutputUtil::trimEmptyLines($repository->getCommitMsg()->getLines()), |
70
|
1 |
|
[IOUtil::getLineSeparator()] |
71
|
|
|
)); |
72
|
1 |
|
} |
73
|
|
|
} |
74
|
|
|
|