1
|
|
|
<?php declare(strict_types=1); |
2
|
|
|
|
3
|
|
|
namespace ekinhbayar\GitAmp\Event\GitHub; |
4
|
|
|
|
5
|
|
|
use ekinhbayar\GitAmp\Event\BaseEvent; |
6
|
|
|
use ekinhbayar\GitAmp\Presentation\Information; |
7
|
|
|
use ekinhbayar\GitAmp\Presentation\Ring; |
8
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\BaseSound; |
9
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\Clav; |
10
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\ClavEgg; |
11
|
|
|
use ekinhbayar\GitAmp\Presentation\Type; |
12
|
|
|
|
13
|
|
|
class IssueCommentEvent extends BaseEvent |
14
|
|
|
{ |
15
|
|
|
/** |
16
|
|
|
* @param array<string,mixed> $event |
17
|
|
|
* @param array<string> $specialRepositories |
18
|
|
|
*/ |
19
|
4 |
|
public function __construct(array $event, array $specialRepositories) |
20
|
|
|
{ |
21
|
4 |
|
parent::__construct( |
22
|
4 |
|
(int) $event['id'], |
23
|
4 |
|
new Type(Type::COMMENTED_ON_ISSUE), |
24
|
4 |
|
new Information( |
25
|
4 |
|
$event['payload']['issue']['html_url'], |
26
|
4 |
|
$this->buildPayload($event), |
27
|
4 |
|
$this->buildMessage($event), |
28
|
|
|
), |
29
|
4 |
|
new Ring(3000, 80), |
30
|
4 |
|
$this->buildSound($event, $specialRepositories), |
31
|
|
|
); |
32
|
4 |
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @param array<string,mixed> $event |
36
|
|
|
*/ |
37
|
4 |
|
private function buildPayload(array $event): string |
38
|
|
|
{ |
39
|
4 |
|
if (isset($event['comment']['body'])) { |
40
|
2 |
|
return $event['comment']['body']; |
41
|
|
|
} |
42
|
|
|
|
43
|
2 |
|
return $event['payload']['issue']['title']; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array<string,mixed> $event |
48
|
|
|
*/ |
49
|
4 |
|
private function buildMessage(array $event): string |
50
|
|
|
{ |
51
|
4 |
|
return \sprintf('%s commented in %s', $event['actor']['login'], $event['repo']['name']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array<string,mixed> $event |
56
|
|
|
* @param array<string> $specialRepositories |
57
|
|
|
*/ |
58
|
4 |
|
private function buildSound(array $event, array $specialRepositories): BaseSound |
59
|
|
|
{ |
60
|
4 |
|
if (in_array($event['repo']['name'], $specialRepositories, true)) { |
61
|
2 |
|
return new ClavEgg(); |
62
|
|
|
} |
63
|
|
|
|
64
|
2 |
|
return new Clav(\strlen($this->buildPayload($event)) * 1.1); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|