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\Exception\ActionFailed; |
15
|
|
|
use SebastianFeldmann\CaptainHook\Hook\Message\Rule; |
16
|
|
|
use SebastianFeldmann\CaptainHook\Hook\Message\RuleBook; |
17
|
|
|
use SebastianFeldmann\Git\Repository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class Beams |
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 Beams extends Book |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Execute the configured action. |
31
|
|
|
* |
32
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config $config |
33
|
|
|
* @param \SebastianFeldmann\CaptainHook\Console\IO $io |
34
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
35
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config\Action $action |
36
|
|
|
* @throws \Exception |
37
|
|
|
*/ |
38
|
2 |
|
public function execute(Config $config, IO $io, Repository $repository, Config\Action $action) |
39
|
|
|
{ |
40
|
2 |
|
$options = $action->getOptions(); |
41
|
2 |
|
$book = new RuleBook(); |
42
|
2 |
|
$book->setRules( |
43
|
|
|
[ |
44
|
2 |
|
new Rule\CapitalizeSubject(), |
45
|
2 |
|
new Rule\LimitSubjectLength($options->get('subjectLength', 50)), |
46
|
2 |
|
new Rule\NoPeriodOnSubjectEnd(), |
47
|
2 |
|
new Rule\UseImperativeMood(), |
48
|
2 |
|
new Rule\LimitBodyLineLength($options->get('bodyLineLength', 72)), |
49
|
2 |
|
new Rule\SeparateSubjectFromBodyWithBlankLine(), |
50
|
|
|
] |
51
|
|
|
); |
52
|
|
|
|
53
|
|
|
try { |
54
|
2 |
|
$this->validate($book, $repository); |
55
|
1 |
|
} catch (ActionFailed $exception) { |
56
|
1 |
|
$io->writeError(['Commit message does not match style', '', 'Message was:']); |
57
|
1 |
|
$io->writeError($repository->getCommitMsg()->getLines()); |
58
|
1 |
|
throw ActionFailed::fromPrevious($exception); |
59
|
|
|
} |
60
|
1 |
|
} |
61
|
|
|
} |
62
|
|
|
|