|
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\Swell; |
|
10
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\SwellEgg; |
|
11
|
|
|
use ekinhbayar\GitAmp\Presentation\Type; |
|
12
|
|
|
|
|
13
|
|
|
class CreateEvent extends BaseEvent |
|
14
|
|
|
{ |
|
15
|
|
|
/** |
|
16
|
|
|
* @param array<string,mixed> $event |
|
17
|
|
|
* @param array<string> $specialRepositories |
|
18
|
|
|
*/ |
|
19
|
6 |
|
public function __construct(array $event, array $specialRepositories) |
|
20
|
|
|
{ |
|
21
|
6 |
|
parent::__construct( |
|
22
|
6 |
|
(int) $event['id'], |
|
23
|
6 |
|
new Type(Type::REPOSITORY_CREATED), |
|
24
|
6 |
|
new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)), |
|
25
|
6 |
|
new Ring(3000, 80), |
|
26
|
6 |
|
$this->buildSound($event, $specialRepositories), |
|
27
|
|
|
); |
|
28
|
6 |
|
} |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* @param array<string,mixed> $event |
|
32
|
|
|
*/ |
|
33
|
6 |
|
private function buildUrl(array $event): string |
|
34
|
|
|
{ |
|
35
|
6 |
|
return 'https://github.com/' . $event['repo']['name']; |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* @param array<string,mixed> $event |
|
40
|
|
|
*/ |
|
41
|
6 |
|
private function buildPayload(array $event): string |
|
42
|
|
|
{ |
|
43
|
6 |
|
if (isset($event['payload']['description'])) { |
|
44
|
2 |
|
return $event['payload']['description']; |
|
45
|
|
|
} |
|
46
|
|
|
|
|
47
|
4 |
|
return 'https://github.com/' . $event['repo']['name']; |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* @param array<string,mixed> $event |
|
52
|
|
|
*/ |
|
53
|
6 |
|
private function buildMessage(array $event): string |
|
54
|
|
|
{ |
|
55
|
6 |
|
return \sprintf('%s created %s', $event['actor']['login'], $event['repo']['name']); |
|
56
|
|
|
} |
|
57
|
|
|
|
|
58
|
|
|
/** |
|
59
|
|
|
* @param array<string,mixed> $event |
|
60
|
|
|
* @param array<string> $specialRepositories |
|
61
|
|
|
*/ |
|
62
|
6 |
|
private function buildSound(array $event, array $specialRepositories): BaseSound |
|
63
|
|
|
{ |
|
64
|
6 |
|
if (in_array($event['repo']['name'], $specialRepositories, true)) { |
|
65
|
2 |
|
return new SwellEgg(); |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
4 |
|
return new Swell(); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|