|
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 IssuesEvent extends BaseEvent |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param array<string,mixed> $event |
|
17
|
|
|
* @param array<string> $specialRepositories |
|
18
|
|
|
*/ |
|
19
|
2 |
|
public function __construct(array $event, array $specialRepositories) |
|
20
|
|
|
{ |
|
21
|
2 |
|
parent::__construct( |
|
22
|
2 |
|
(int) $event['id'], |
|
23
|
2 |
|
new Type(Type::ISSUE_ACTION), |
|
24
|
2 |
|
new Information( |
|
25
|
2 |
|
$event['payload']['issue']['html_url'], |
|
26
|
2 |
|
$event['payload']['issue']['title'], |
|
27
|
2 |
|
$this->buildMessage($event), |
|
28
|
|
|
), |
|
29
|
2 |
|
new Ring(3000, 80), |
|
30
|
2 |
|
$this->buildSound($event, $specialRepositories), |
|
31
|
|
|
); |
|
32
|
2 |
|
} |
|
33
|
|
|
|
|
34
|
|
|
/** |
|
35
|
|
|
* @param array<string,mixed> $event |
|
36
|
|
|
*/ |
|
37
|
2 |
|
private function buildMessage(array $event): string |
|
38
|
|
|
{ |
|
39
|
2 |
|
return \sprintf( |
|
40
|
|
|
'%s %s an issue in %s', |
|
41
|
2 |
|
$event['actor']['login'], |
|
42
|
2 |
|
$event['payload']['action'], |
|
43
|
2 |
|
$event['repo']['name'], |
|
44
|
|
|
); |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
|
|
/** |
|
48
|
|
|
* @param array<string,mixed> $event |
|
49
|
|
|
* @param array<string> $specialRepositories |
|
50
|
|
|
*/ |
|
51
|
2 |
|
private function buildSound(array $event, array $specialRepositories): BaseSound |
|
52
|
|
|
{ |
|
53
|
2 |
|
if (in_array($event['repo']['name'], $specialRepositories, true)) { |
|
54
|
1 |
|
return new ClavEgg(); |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
1 |
|
return new Clav(\strlen($event['payload']['issue']['title']) * 1.1); |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
|