|
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\Type; |
|
8
|
|
|
use ekinhbayar\GitAmp\Presentation\Ring; |
|
9
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\BaseSound; |
|
10
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\Celesta; |
|
11
|
|
|
use ekinhbayar\GitAmp\Presentation\Sound\CelestaEgg; |
|
12
|
|
|
|
|
13
|
|
|
class PushEvent extends BaseEvent |
|
14
|
|
|
{ |
|
15
|
|
|
private const SPECIAL_REPOSITORIES = [ |
|
16
|
|
|
'ekinhbayar/gitamp', |
|
17
|
|
|
'amphp/amp', |
|
18
|
|
|
]; |
|
19
|
|
|
|
|
20
|
4 |
|
public function __construct(array $event) |
|
21
|
|
|
{ |
|
22
|
4 |
|
parent::__construct( |
|
23
|
4 |
|
(int) $event['id'], |
|
24
|
4 |
|
new Type(1), |
|
25
|
4 |
|
new Information($this->buildUrl($event), $this->buildPayload($event), $this->buildMessage($event)), |
|
26
|
4 |
|
new Ring(3000, 80), |
|
27
|
4 |
|
$this->buildSound($event), |
|
28
|
|
|
); |
|
|
|
|
|
|
29
|
|
|
} |
|
30
|
|
|
|
|
31
|
4 |
|
private function buildUrl(array $event): string |
|
32
|
|
|
{ |
|
33
|
4 |
|
return 'https://github.com/' . $event['repo']['name']; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
4 |
|
private function buildPayload(array $event): string |
|
37
|
|
|
{ |
|
38
|
4 |
|
if (isset($event['payload']['commits'][0]['message'])) { |
|
39
|
2 |
|
return $event['payload']['commits'][0]['message']; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
2 |
|
return 'https://github.com/' . $event['actor']['login']; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
4 |
|
private function buildMessage(array $event): string |
|
46
|
|
|
{ |
|
47
|
4 |
|
return \sprintf('%s pushed to %s', $event['actor']['login'], $event['repo']['name']); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
4 |
|
private function buildSound(array $event): BaseSound |
|
51
|
|
|
{ |
|
52
|
4 |
|
if (\in_array($event['repo']['name'], self::SPECIAL_REPOSITORIES, true)) { |
|
53
|
2 |
|
return new CelestaEgg(); |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
2 |
|
return new Celesta(\strlen($this->buildPayload($event)) * 1.1); |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
|