1
|
|
|
<?php |
2
|
|
|
declare(strict_types = 1); |
3
|
|
|
|
4
|
|
|
namespace PurpleBooth\GitGitHubLint; |
5
|
|
|
|
6
|
|
|
use Github\Client; |
7
|
|
|
use PhpSpec\Exception\Exception; |
8
|
|
|
use PurpleBooth\GitGitHubLint\Exception\GitHubLintException; |
9
|
|
|
use PurpleBooth\GitLintValidators\ValidatorFactoryImplementation; |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* A vanity interface to make it easier to use this library |
13
|
|
|
* |
14
|
|
|
* @package PurpleBooth\GitGitHubLint |
15
|
|
|
*/ |
16
|
|
|
class GitHubLintImplementation implements GitHubLint |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var AnalysePullRequestCommits |
20
|
|
|
*/ |
21
|
|
|
private $analyser; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* GitHubLintImplementation constructor. |
25
|
|
|
* |
26
|
|
|
* @param Client $client |
27
|
|
|
*/ |
28
|
|
|
public function __construct(Client $client) |
29
|
|
|
{ |
30
|
|
|
$validatorFactory = new ValidatorFactoryImplementation(); |
31
|
|
|
|
32
|
|
|
$this->analyser = new AnalysePullRequestCommitsImplementation( |
33
|
|
|
new CommitMessageServiceImplementation($client), |
34
|
|
|
new ValidateMessagesImplementation( |
35
|
|
|
$validatorFactory->getMessageValidator() |
36
|
|
|
), |
37
|
|
|
new StatusSendServiceImplementation($client) |
38
|
|
|
); |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Analyse the commits on a pull request and set the statuses |
43
|
|
|
* |
44
|
|
|
* @param string $username |
45
|
|
|
* @param string $repository |
46
|
|
|
* @param int $pullRequest |
47
|
|
|
* |
48
|
|
|
* @throws GitHubLintException if an undocumented exception is thrown, it'll be wrapped in this exception. |
49
|
|
|
*/ |
50
|
|
|
public function analyse(string $username, string $repository, int $pullRequest) |
51
|
|
|
{ |
52
|
|
|
try { |
53
|
|
|
$this->analyser->check($username, $repository, $pullRequest); |
54
|
|
|
} catch (Exception $exception) { |
55
|
|
|
throw new GitHubLintException("An unexpected error has occurred", 0, $exception); |
56
|
|
|
} |
57
|
|
|
} |
58
|
|
|
} |
59
|
|
|
|