hooks.php
6.58 KB
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
<?php
/**
* @package Joomla.Platform
* @subpackage GitHub
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE
*/
defined('JPATH_PLATFORM') or die;
/**
* GitHub API Hooks class for the Joomla Platform.
*
* @since 3.1.4
* @deprecated 4.0 Use the `joomla/github` package via Composer instead
*/
class JGithubHooks extends JGithubObject
{
/**
* Array containing the allowed hook events
*
* @var array
* @since 3.1.4
*/
protected $events = array(
'push',
'issues',
'issue_comment',
'commit_comment',
'pull_request',
'gollum',
'watch',
'download',
'fork',
'fork_apply',
'member',
'public',
'status',
);
/**
* Method to create a hook on a repository.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param string $name The name of the service being called.
* @param array $config Array containing the config for the service.
* @param array $events The events the hook will be triggered for.
* @param boolean $active Flag to determine if the hook is active
*
* @deprecated use repositories->hooks->create()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
* @throws RuntimeException
*/
public function create($user, $repo, $name, array $config, array $events = array('push'), $active = true)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks';
// Check to ensure all events are in the allowed list
foreach ($events as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your events array contains an unauthorized event.');
}
}
$data = json_encode(
array('name' => $name, 'config' => $config, 'events' => $events, 'active' => $active)
);
return $this->processResponse(
$this->client->post($this->fetchUrl($path), $data),
201
);
}
/**
* Method to delete a hook
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to delete.
*
* @deprecated use repositories->hooks->delete()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
*/
public function delete($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
return $this->processResponse(
$this->client->delete($this->fetchUrl($path)),
204
);
}
/**
* Method to edit a hook.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to edit.
* @param string $name The name of the service being called.
* @param array $config Array containing the config for the service.
* @param array $events The events the hook will be triggered for. This resets the currently set list
* @param array $addEvents Events to add to the hook.
* @param array $removeEvents Events to remove from the hook.
* @param boolean $active Flag to determine if the hook is active
*
* @deprecated use repositories->hooks->edit()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
* @throws RuntimeException
*/
public function edit($user, $repo, $id, $name, array $config, array $events = array('push'), array $addEvents = array(),
array $removeEvents = array(), $active = true)
{
// Check to ensure all events are in the allowed list
foreach ($events as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your events array contains an unauthorized event.');
}
}
foreach ($addEvents as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your active_events array contains an unauthorized event.');
}
}
foreach ($removeEvents as $event)
{
if (!in_array($event, $this->events))
{
throw new RuntimeException('Your remove_events array contains an unauthorized event.');
}
}
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
$data = json_encode(
array(
'name' => $name,
'config' => $config,
'events' => $events,
'add_events' => $addEvents,
'remove_events' => $removeEvents,
'active' => $active,
)
);
return $this->processResponse(
$this->client->patch($this->fetchUrl($path), $data)
);
}
/**
* Method to get details about a single hook for the repository.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to retrieve
*
* @deprecated use repositories->hooks->get()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
*/
public function get($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id;
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Method to list hooks for a repository.
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $page Page to request
* @param integer $limit Number of results to return per page
*
* @deprecated use repositories->hooks->getList()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
*/
public function getList($user, $repo, $page = 0, $limit = 0)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks';
return $this->processResponse(
$this->client->get($this->fetchUrl($path))
);
}
/**
* Method to test a hook against the latest repository commit
*
* @param string $user The name of the owner of the GitHub repository.
* @param string $repo The name of the GitHub repository.
* @param integer $id ID of the hook to delete
*
* @deprecated use repositories->hooks->test()
*
* @return object
*
* @since 3.1.4
* @throws DomainException
*/
public function test($user, $repo, $id)
{
// Build the request path.
$path = '/repos/' . $user . '/' . $repo . '/hooks/' . $id . '/test';
return $this->processResponse(
$this->client->post($this->fetchUrl($path), json_encode('')),
204
);
}
}