1 | <?php |
||
9 | class SendCommentService |
||
10 | { |
||
11 | /** |
||
12 | * @var Client |
||
13 | */ |
||
14 | private $client; |
||
15 | /** |
||
16 | * @var DiffService |
||
17 | */ |
||
18 | private $diffService; |
||
19 | |||
20 | public function __construct(Client $client, DiffService $diffService) |
||
25 | |||
26 | public function sendCodeCoverageCommentToMergeRequest(CloverFile $cloverFile, CloverFile $previousCloverFile, string $projectName, int $mergeRequestId, string $commitId, string $gitlabUrl) |
||
27 | { |
||
28 | $coverage = $cloverFile->getCoveragePercentage(); |
||
29 | $previousCoverage = $previousCloverFile->getCoveragePercentage(); |
||
30 | |||
31 | $additionalText = ''; |
||
32 | $style = ''; |
||
33 | if ($coverage > $previousCoverage + 0.0001) { |
||
34 | $additionalText = sprintf('(<em>+%.2f%%</em>)', ($coverage - $previousCoverage)*100); |
||
35 | $style .= 'background-color: #00994c; color: white'; |
||
36 | } elseif ($coverage < $previousCoverage - 0.0001) { |
||
37 | $additionalText = sprintf('(<em>-%.2f%%</em>)', ($previousCoverage - $coverage)*100); |
||
38 | $style .= 'background-color: #ff6666; color: white'; |
||
39 | } |
||
40 | |||
41 | $differences = $this->diffService->getMeaningfulDifferences($cloverFile, $previousCloverFile); |
||
42 | $differencesHtml = $this->getDifferencesHtml($differences, $commitId, $gitlabUrl); |
||
|
|||
43 | |||
44 | // Note: there is a failure in the way Gitlab escapes HTML for the tables. Let's use this!. |
||
45 | $message = sprintf('<table> |
||
46 | <tr> |
||
47 | <td>PHP code coverage:</td> |
||
48 | <td style="font-weight: bold">%.2f%%</td> |
||
49 | <td style="%s">%s</td> |
||
50 | <td width="99%%"></td> |
||
51 | </tr> |
||
52 | </table><br/>%s', $cloverFile->getCoveragePercentage()*100, $style, $additionalText, $differencesHtml); |
||
53 | |||
54 | $this->client->merge_requests->addComment($projectName, $mergeRequestId, $message); |
||
55 | } |
||
56 | |||
57 | public function sendDifferencesCommentsInCommit(CloverFile $cloverFile, CloverFile $previousCloverFile, string $projectName, string $commitId) |
||
72 | |||
73 | /** |
||
74 | * @param Difference[] $differences |
||
75 | * @return string |
||
76 | */ |
||
77 | private function getDifferencesHtml(array $differences, string $commitId, string $gitlabUrl, string $projectName) : string |
||
115 | |||
116 | private function getLinkToMethodInCommit(string $gitlabUrl, string $projectName, string $commit, string $filePath, int $line) |
||
120 | } |
||
121 |
This check looks for function calls that miss required arguments.