|
1
|
|
|
<?php |
|
2
|
|
|
declare(strict_types = 1); |
|
3
|
|
|
|
|
4
|
|
|
namespace PurpleBooth\GitGitHubLint; |
|
5
|
|
|
|
|
6
|
|
|
/** |
|
7
|
|
|
* Analyses pull request commit messages |
|
8
|
|
|
* |
|
9
|
|
|
* @package PurpleBooth\GitGitHubLint |
|
10
|
|
|
*/ |
|
11
|
|
|
class AnalysePullRequestCommitsImplementation implements AnalysePullRequestCommits |
|
12
|
|
|
{ |
|
13
|
|
|
/** |
|
14
|
|
|
* @var CommitMessageService |
|
15
|
|
|
*/ |
|
16
|
|
|
private $commitMessageService; |
|
17
|
|
|
/** |
|
18
|
|
|
* @var ValidateMessages |
|
19
|
|
|
*/ |
|
20
|
|
|
private $validationService; |
|
21
|
|
|
/** |
|
22
|
|
|
* @var StatusSendService |
|
23
|
|
|
*/ |
|
24
|
|
|
private $statusSendService; |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* AnalyseAndReportOnCommitImplementation constructor. |
|
28
|
|
|
* |
|
29
|
|
|
* @param CommitMessageService $commitMessageService |
|
30
|
|
|
* @param ValidateMessages $validationService |
|
31
|
|
|
* @param StatusSendService $statusSendService |
|
32
|
|
|
*/ |
|
33
|
|
|
public function __construct( |
|
34
|
|
|
CommitMessageService $commitMessageService, |
|
35
|
|
|
ValidateMessages $validationService, |
|
36
|
|
|
StatusSendService $statusSendService |
|
37
|
|
|
) { |
|
38
|
|
|
$this->commitMessageService = $commitMessageService; |
|
39
|
|
|
$this->validationService = $validationService; |
|
40
|
|
|
$this->statusSendService = $statusSendService; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Validate the messages in a pull request |
|
45
|
|
|
* |
|
46
|
|
|
* @param string $username |
|
47
|
|
|
* @param string $repository |
|
48
|
|
|
* @param int $pullRequestId |
|
49
|
|
|
*/ |
|
50
|
|
|
public function check(string $username, string $repository, int $pullRequestId) |
|
51
|
|
|
{ |
|
52
|
|
|
$messages = $this->commitMessageService->getMessages($username, $repository, $pullRequestId); |
|
53
|
|
|
$this->validationService->validate($messages); |
|
54
|
|
|
|
|
55
|
|
|
/** @var GitHubMessage $message */ |
|
56
|
|
|
foreach ($messages as $message) { |
|
57
|
|
|
$this->statusSendService->updateStatus($username, $repository, $message); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
} |
|
61
|
|
|
|