/
PushEvent.php
134 lines (101 loc) · 2.89 KB
/
PushEvent.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php
namespace Webhook\Payload;
use Webhook\Payload;
use Webhook\PayloadData;
/**
* Payload data provided by PushEvent
* @see https://developer.github.com/v3/activity/events/types/#pushevent
*/
class PushEvent extends Payload {
/**
* @var \Webhook\PayloadData\Organization
*/
public $organization;
/**
* @var \Webhook\PayloadData\Repository
*/
public $repository;
/**
* @var string
* The full Git ref that was pushed. Example: "refs/heads/master".
*/
public $ref;
/**
* @var string
* The SHA of the most recent commit on ref after the push.
*/
public $before;
/**
* @var string
* The SHA of the most recent commit on ref before the push.
*/
public $after;
/**
* @var string
* Compare View URL
*/
public $compare;
/**
* @var \Webhook\PayloadData\Commit[]
*/
public $commits = [];
/**
* @var \Webhook\PayloadData\HeadCommit
*/
public $head_commit;
/**
* @var \Webhook\PayloadData\Pusher
*/
public $pusher;
/**
* @var object
* @private
*/
private $input;
const EVENT_NAME = 'push';
/**
* Populates a "generic" Payload <b>Event</b> object corresponding to this event.
* @return \Webhook\Payload\Event
*/
public function toEvent() : Event {
return new Event($this->input,static::EVENT_NAME);
}
/**
* Provides the event name.
* @return string
*/
public function getEvent(): string {
return static::EVENT_NAME;
}
/**
* @param object $input payload input
*/
public function __construct($input) {
$this->input = $input;
parent::__construct($input);
}
/**
* Indicates that the populating of this Payload object is complete.
* @return void
*/
public function populateComplete() {
parent::populateComplete();
foreach($this->commits as &$commit) {
if ((!$commit instanceof PayloadData\Commit) && is_object($commit)) {
$commit = (new PayloadData\Commit)->populateFromObject($commit);
}
}
if ((!$this->head_commit instanceof PayloadData\HeadCommit) && is_object($this->head_commit)) {
$this->head_commit = (new PayloadData\HeadCommit)->populateFromObject($this->head_commit);
}
if ((!$this->pusher instanceof PayloadData\Pusher) && is_object($this->pusher)) {
$this->pusher = (new PayloadData\Pusher)->populateFromObject($this->pusher);
}
if (!$this->organization instanceof PayloadData\Organization) {
$this->organization = (new PayloadData\Organization)->populateFromObject($this->organization);
}
if (!$this->repository instanceof PayloadData\Repository) {
$this->repository = (new PayloadData\Repository)->populateFromObject($this->repository);
}
}
}