1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Github Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved. |
6
|
|
|
* @license GNU General Public License version 2 or later; see LICENSE |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Joomla\Github\Package; |
10
|
|
|
|
11
|
|
|
use Joomla\Github\AbstractPackage; |
12
|
|
|
use Joomla\Uri\Uri; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* GitHub API Issues class for the Joomla Framework. |
16
|
|
|
* |
17
|
|
|
* @link https://developer.github.com/v3/issues |
18
|
|
|
* |
19
|
|
|
* @since 1.0 |
20
|
|
|
* |
21
|
|
|
* @property-read Issues\Assignees $assignees GitHub API object for assignees. |
22
|
|
|
* @property-read Issues\Comments $comments GitHub API object for comments. |
23
|
|
|
* @property-read Issues\Events $events GitHub API object for events. |
24
|
|
|
* @property-read Issues\Labels $labels GitHub API object for labels. |
25
|
|
|
* @property-read Issues\Milestones $milestones GitHub API object for milestones. |
26
|
|
|
*/ |
27
|
|
|
class Issues extends AbstractPackage |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Create an issue. |
31
|
|
|
* |
32
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
33
|
|
|
* @param string $repo The name of the GitHub repository. |
34
|
|
|
* @param string $title The title of the new issue. |
35
|
|
|
* @param string $body The body text for the new issue. |
36
|
|
|
* @param string $assignee The login for the GitHub user that this issue should be assigned to. |
37
|
|
|
* @param integer $milestone The milestone to associate this issue with. |
38
|
|
|
* @param string[] $labels The labels to associate with this issue. |
39
|
|
|
* @param string[] $assignees The logins for GitHub users to assign to this issue. |
40
|
|
|
* |
41
|
|
|
* @return object |
42
|
|
|
* |
43
|
|
|
* @since 1.0 |
44
|
|
|
* @throws \DomainException |
45
|
|
|
*/ |
46
|
|
|
public function create($user, $repo, $title, $body = null, $assignee = null, $milestone = null, array $labels = array(), |
47
|
|
|
array $assignees = array() |
48
|
|
|
) |
49
|
|
|
{ |
50
|
|
|
// Build the request path. |
51
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues'; |
52
|
|
|
|
53
|
|
|
// Ensure that we have a non-associative array. |
54
|
|
|
if (!empty($labels)) |
55
|
|
|
{ |
56
|
|
|
$labels = array_values($labels); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
// Build the request data. |
60
|
|
|
$data = array( |
61
|
|
|
'title' => $title, |
62
|
|
|
'milestone' => $milestone, |
63
|
|
|
'labels' => $labels, |
64
|
|
|
'body' => $body |
65
|
|
|
); |
66
|
|
|
|
67
|
|
|
if (is_string($assignee) && !empty($assignees)) |
68
|
|
|
{ |
69
|
|
|
throw new \UnexpectedValueException('You cannot pass both assignee and assignees. Only one may be provided.'); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
if (!empty($assignees)) |
73
|
|
|
{ |
74
|
|
|
$data['assignees'] = array_values($assignees); |
75
|
|
|
} |
76
|
|
|
elseif (is_string($assignee)) |
77
|
|
|
{ |
78
|
|
|
$data['assignee'] = $assignee; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
// Encode the request data. |
82
|
|
|
$data = json_encode($data); |
83
|
|
|
|
84
|
|
|
// Send the request. |
85
|
|
|
return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); |
86
|
|
|
} |
87
|
|
|
|
88
|
|
|
/** |
89
|
|
|
* Edit an issue. |
90
|
|
|
* |
91
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
92
|
|
|
* @param string $repo The name of the GitHub repository. |
93
|
|
|
* @param integer $issueId The issue number. |
94
|
|
|
* @param string $state The optional new state for the issue. [open, closed] |
95
|
|
|
* @param string $title The title of the new issue. |
96
|
|
|
* @param string $body The body text for the new issue. |
97
|
|
|
* @param string $assignee The login for the GitHub user that this issue should be assigned to. |
98
|
|
|
* @param integer $milestone The milestone to associate this issue with. |
99
|
|
|
* @param array $labels The labels to associate with this issue. |
100
|
|
|
* |
101
|
|
|
* @return object |
102
|
|
|
* |
103
|
|
|
* @since 1.0 |
104
|
|
|
* @throws \DomainException |
105
|
|
|
*/ |
106
|
|
|
public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, |
107
|
|
|
array $labels = null |
108
|
|
|
) |
109
|
|
|
{ |
110
|
|
|
// Build the request path. |
111
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; |
112
|
|
|
|
113
|
|
|
// Create the data object. |
114
|
|
|
$data = new \stdClass; |
115
|
|
|
|
116
|
|
|
// If a title is set add it to the data object. |
117
|
|
|
if (isset($title)) |
118
|
|
|
{ |
119
|
|
|
$data->title = $title; |
120
|
|
|
} |
121
|
|
|
|
122
|
|
|
// If a body is set add it to the data object. |
123
|
|
|
if (isset($body)) |
124
|
|
|
{ |
125
|
|
|
$data->body = $body; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
// If a state is set add it to the data object. |
129
|
|
|
if (isset($state)) |
130
|
|
|
{ |
131
|
|
|
$data->state = $state; |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
// If an assignee is set add it to the data object. |
135
|
|
|
if (isset($assignee)) |
136
|
|
|
{ |
137
|
|
|
$data->assignee = $assignee; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
// If a milestone is set add it to the data object. |
141
|
|
|
if (isset($milestone)) |
142
|
|
|
{ |
143
|
|
|
$data->milestone = $milestone; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
// If labels are set add them to the data object. |
147
|
|
|
if (isset($labels)) |
148
|
|
|
{ |
149
|
|
|
// Ensure that we have a non-associative array. |
150
|
|
|
if (isset($labels)) |
151
|
|
|
{ |
152
|
|
|
$labels = array_values($labels); |
153
|
|
|
} |
154
|
|
|
|
155
|
|
|
$data->labels = $labels; |
156
|
|
|
} |
157
|
|
|
|
158
|
|
|
// Encode the request data. |
159
|
|
|
$data = json_encode($data); |
160
|
|
|
|
161
|
|
|
// Send the request. |
162
|
|
|
return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); |
163
|
|
|
} |
164
|
|
|
|
165
|
|
|
/** |
166
|
|
|
* Get a single issue. |
167
|
|
|
* |
168
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
169
|
|
|
* @param string $repo The name of the GitHub repository. |
170
|
|
|
* @param integer $issueId The issue number. |
171
|
|
|
* |
172
|
|
|
* @return object |
173
|
|
|
* |
174
|
|
|
* @since 1.0 |
175
|
|
|
* @throws \DomainException |
176
|
|
|
*/ |
177
|
|
|
public function get($user, $repo, $issueId) |
178
|
|
|
{ |
179
|
|
|
// Build the request path. |
180
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; |
181
|
|
|
|
182
|
|
|
// Send the request. |
183
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* List issues. |
188
|
|
|
* |
189
|
|
|
* @param string $filter The filter type: assigned, created, mentioned, subscribed. |
190
|
|
|
* @param string $state The optional state to filter requests by. [open, closed] |
191
|
|
|
* @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
192
|
|
|
* @param string $sort The sort order: created, updated, comments, default: created. |
193
|
|
|
* @param string $direction The list direction: asc or desc, default: desc. |
194
|
|
|
* @param \DateTime $since Only issues updated at or after this time are returned. |
195
|
|
|
* @param integer $page The page number from which to get items. |
196
|
|
|
* @param integer $limit The number of items on a page. |
197
|
|
|
* |
198
|
|
|
* @return object |
199
|
|
|
* |
200
|
|
|
* @since 1.0 |
201
|
|
|
* @throws \DomainException |
202
|
|
|
*/ |
203
|
|
|
public function getList($filter = null, $state = null, $labels = null, $sort = null, |
204
|
|
|
$direction = null, \DateTime $since = null, $page = 0, $limit = 0 |
205
|
|
|
) |
206
|
|
|
{ |
207
|
|
|
// Build the request path. |
208
|
|
|
$path = '/issues'; |
209
|
|
|
|
210
|
|
|
$uri = new Uri($this->fetchUrl($path, $page, $limit)); |
211
|
|
|
|
212
|
|
|
if ($filter) |
|
|
|
|
213
|
|
|
{ |
214
|
|
|
$uri->setVar('filter', $filter); |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
if ($state) |
|
|
|
|
218
|
|
|
{ |
219
|
|
|
$uri->setVar('state', $state); |
220
|
|
|
} |
221
|
|
|
|
222
|
|
|
if ($labels) |
|
|
|
|
223
|
|
|
{ |
224
|
|
|
$uri->setVar('labels', $labels); |
225
|
|
|
} |
226
|
|
|
|
227
|
|
|
if ($sort) |
|
|
|
|
228
|
|
|
{ |
229
|
|
|
$uri->setVar('sort', $sort); |
230
|
|
|
} |
231
|
|
|
|
232
|
|
|
if ($direction) |
|
|
|
|
233
|
|
|
{ |
234
|
|
|
$uri->setVar('direction', $direction); |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
if ($since) |
238
|
|
|
{ |
239
|
|
|
$uri->setVar('since', $since->format(\DateTime::ISO8601)); |
240
|
|
|
} |
241
|
|
|
|
242
|
|
|
// Send the request. |
243
|
|
|
return $this->processResponse($this->client->get((string) $uri)); |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* List issues for a repository. |
248
|
|
|
* |
249
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
250
|
|
|
* @param string $repo The name of the GitHub repository. |
251
|
|
|
* @param string $milestone The milestone number, 'none', or *. |
252
|
|
|
* @param string $state The optional state to filter requests by. [open, closed] |
253
|
|
|
* @param string $assignee The assignee name, 'none', or *. |
254
|
|
|
* @param string $mentioned The GitHub user name. |
255
|
|
|
* @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
256
|
|
|
* @param string $sort The sort order: created, updated, comments, default: created. |
257
|
|
|
* @param string $direction The list direction: asc or desc, default: desc. |
258
|
|
|
* @param \DateTime $since Only issues updated at or after this time are returned. |
259
|
|
|
* @param integer $page The page number from which to get items. |
260
|
|
|
* @param integer $limit The number of items on a page. |
261
|
|
|
* |
262
|
|
|
* @return object |
263
|
|
|
* |
264
|
|
|
* @since 1.0 |
265
|
|
|
* @throws \DomainException |
266
|
|
|
*/ |
267
|
|
|
public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, |
268
|
|
|
$sort = null, $direction = null, \DateTime $since = null, $page = 0, $limit = 0 |
269
|
|
|
) |
270
|
|
|
{ |
271
|
|
|
// Build the request path. |
272
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues'; |
273
|
|
|
|
274
|
|
|
$uri = new Uri($this->fetchUrl($path, $page, $limit)); |
275
|
|
|
|
276
|
|
|
if ($milestone) |
|
|
|
|
277
|
|
|
{ |
278
|
|
|
$uri->setVar('milestone', $milestone); |
279
|
|
|
} |
280
|
|
|
|
281
|
|
|
if ($state) |
|
|
|
|
282
|
|
|
{ |
283
|
|
|
$uri->setVar('state', $state); |
284
|
|
|
} |
285
|
|
|
|
286
|
|
|
if ($assignee) |
|
|
|
|
287
|
|
|
{ |
288
|
|
|
$uri->setVar('assignee', $assignee); |
289
|
|
|
} |
290
|
|
|
|
291
|
|
|
if ($mentioned) |
|
|
|
|
292
|
|
|
{ |
293
|
|
|
$uri->setVar('mentioned', $mentioned); |
294
|
|
|
} |
295
|
|
|
|
296
|
|
|
if ($labels) |
|
|
|
|
297
|
|
|
{ |
298
|
|
|
$uri->setVar('labels', $labels); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
if ($sort) |
|
|
|
|
302
|
|
|
{ |
303
|
|
|
$uri->setVar('sort', $sort); |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
if ($direction) |
|
|
|
|
307
|
|
|
{ |
308
|
|
|
$uri->setVar('direction', $direction); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
if ($since) |
312
|
|
|
{ |
313
|
|
|
$uri->setVar('since', $since->format(\DateTime::RFC3339)); |
314
|
|
|
} |
315
|
|
|
|
316
|
|
|
// Send the request. |
317
|
|
|
return $this->processResponse($this->client->get((string) $uri)); |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Lock an issue. |
322
|
|
|
* |
323
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
324
|
|
|
* @param string $repo The name of the GitHub repository. |
325
|
|
|
* @param integer $issueId The issue number. |
326
|
|
|
* |
327
|
|
|
* @return object |
328
|
|
|
* |
329
|
|
|
* @since 1.4.0 |
330
|
|
|
* @throws \DomainException |
331
|
|
|
*/ |
332
|
|
View Code Duplication |
public function lock($user, $repo, $issueId) |
|
|
|
|
333
|
|
|
{ |
334
|
|
|
// Build the request path. |
335
|
|
|
$path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; |
336
|
|
|
|
337
|
|
|
return $this->processResponse($this->client->put($this->fetchUrl($path), array()), 204); |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Unlock an issue. |
342
|
|
|
* |
343
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
344
|
|
|
* @param string $repo The name of the GitHub repository. |
345
|
|
|
* @param integer $issueId The issue number. |
346
|
|
|
* |
347
|
|
|
* @return object |
348
|
|
|
* |
349
|
|
|
* @since 1.4.0 |
350
|
|
|
* @throws \DomainException |
351
|
|
|
*/ |
352
|
|
|
public function unlock($user, $repo, $issueId) |
353
|
|
|
{ |
354
|
|
|
// Build the request path. |
355
|
|
|
$path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; |
356
|
|
|
|
357
|
|
|
return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); |
358
|
|
|
} |
359
|
|
|
} |
360
|
|
|
|
In PHP, under loose comparison (like
==
, or!=
, orswitch
conditions), values of different types might be equal.For
string
values, the empty string''
is a special case, in particular the following results might be unexpected: