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 ForkEvent 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::REPOSITORY_FORKED), |
24
|
2 |
|
new Information($this->buildUrl($event), $this->buildPayload(), $this->buildMessage($event)), |
25
|
2 |
|
new Ring(3000, 80), |
26
|
2 |
|
$this->buildSound($event, $specialRepositories), |
27
|
|
|
); |
28
|
2 |
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param array<string,mixed> $event |
32
|
|
|
*/ |
33
|
2 |
|
private function buildUrl(array $event): string |
34
|
|
|
{ |
35
|
2 |
|
return 'https://github.com/' . $event['repo']['name']; |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @param array<string,mixed> $event |
40
|
|
|
*/ |
41
|
2 |
|
private function buildPayload(): string |
42
|
|
|
{ |
43
|
2 |
|
return 'not sure if stupid but works anyway'; |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param array<string,mixed> $event |
48
|
|
|
*/ |
49
|
2 |
|
private function buildMessage(array $event): string |
50
|
|
|
{ |
51
|
2 |
|
return \sprintf('%s forked %s', $event['actor']['login'], $event['repo']['name']); |
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @param array<string,mixed> $event |
56
|
|
|
* @param array<string> $specialRepositories |
57
|
|
|
*/ |
58
|
2 |
|
private function buildSound(array $event, array $specialRepositories): BaseSound |
59
|
|
|
{ |
60
|
2 |
|
if (in_array($event['repo']['name'], $specialRepositories, true)) { |
61
|
1 |
|
return new SwellEgg(); |
62
|
|
|
} |
63
|
|
|
|
64
|
1 |
|
return new Swell(); |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|