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\Git; |
13
|
|
|
|
14
|
|
|
use CaptainHook\App\Console\IO; |
15
|
|
|
use CaptainHook\App\Git\ChangedFiles\Detector\Factory; |
16
|
|
|
use SebastianFeldmann\Git\Repository; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class ChangedFiles |
20
|
|
|
* |
21
|
|
|
* @package CaptainHook |
22
|
|
|
* @author Sebastian Feldmann <[email protected]> |
23
|
|
|
* @link https://github.com/captainhook-git/captainhook |
24
|
|
|
* @since Class available since Release 5.2.0 |
25
|
|
|
*/ |
26
|
|
|
abstract class ChangedFiles |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Returns the list of changed files using the necessary Detector |
30
|
|
|
* |
31
|
|
|
* @param \CaptainHook\App\Console\IO $io |
32
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
33
|
|
|
* @param array<string> $filter |
34
|
|
|
* @return array<string> |
35
|
|
|
*/ |
36
|
16 |
|
public static function getChangedFiles(IO $io, Repository $repository, array $filter): array |
37
|
|
|
{ |
38
|
16 |
|
$factory = new Factory(); |
39
|
16 |
|
$detector = $factory->getDetector($io, $repository); |
40
|
|
|
|
41
|
16 |
|
$files = $detector->getChangedFiles($filter); |
42
|
16 |
|
self::displayFilesFound($io, $files); |
43
|
16 |
|
return $files; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Output the changed files in verbose mode |
48
|
|
|
* |
49
|
|
|
* @param \CaptainHook\App\Console\IO $io |
50
|
|
|
* @param array<string> $files |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
|
54
|
16 |
|
private static function displayFilesFound(IO $io, array $files): void |
55
|
|
|
{ |
56
|
16 |
|
if ($io->isVerbose()) { |
57
|
|
|
$io->write(' <info>Changed files</info>', true, IO::VERBOSE); |
58
|
|
|
foreach ($files as $file) { |
59
|
|
|
$io->write(' - ' . $file, true, IO::VERBOSE); |
60
|
|
|
} |
61
|
|
|
} |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|