1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Part of the Joomla Framework Github Package |
4
|
|
|
* |
5
|
|
|
* @copyright Copyright (C) 2005 - 2015 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
|
|
|
* @documentation http://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(), array $assignees = array()) |
47
|
|
|
{ |
48
|
|
|
// Build the request path. |
49
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues'; |
50
|
|
|
|
51
|
|
|
// Ensure that we have a non-associative array. |
52
|
|
|
if (!empty($labels)) |
53
|
|
|
{ |
54
|
|
|
$labels = array_values($labels); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
// Build the request data. |
58
|
|
|
$data = json_encode( |
59
|
|
|
array( |
60
|
|
|
'title' => $title, |
61
|
|
|
'assignee' => $assignee, |
62
|
|
|
'milestone' => $milestone, |
63
|
|
|
'labels' => $labels, |
64
|
|
|
'body' => $body, |
65
|
|
|
'assignees' => $assignees, |
66
|
|
|
) |
67
|
|
|
); |
68
|
|
|
|
69
|
|
|
// Send the request. |
70
|
|
|
return $this->processResponse($this->client->post($this->fetchUrl($path), $data), 201); |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* Edit an issue. |
75
|
|
|
* |
76
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
77
|
|
|
* @param string $repo The name of the GitHub repository. |
78
|
|
|
* @param integer $issueId The issue number. |
79
|
|
|
* @param string $state The optional new state for the issue. [open, closed] |
80
|
|
|
* @param string $title The title of the new issue. |
81
|
|
|
* @param string $body The body text for the new issue. |
82
|
|
|
* @param string $assignee The login for the GitHub user that this issue should be assigned to. |
83
|
|
|
* @param integer $milestone The milestone to associate this issue with. |
84
|
|
|
* @param array $labels The labels to associate with this issue. |
85
|
|
|
* |
86
|
|
|
* @return object |
87
|
|
|
* |
88
|
|
|
* @since 1.0 |
89
|
|
|
* @throws \DomainException |
90
|
|
|
*/ |
91
|
|
|
public function edit($user, $repo, $issueId, $state = null, $title = null, $body = null, $assignee = null, $milestone = null, array $labels = null) |
92
|
|
|
{ |
93
|
|
|
// Build the request path. |
94
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; |
95
|
|
|
|
96
|
|
|
// Create the data object. |
97
|
|
|
$data = new \stdClass; |
98
|
|
|
|
99
|
|
|
// If a title is set add it to the data object. |
100
|
|
|
if (isset($title)) |
101
|
|
|
{ |
102
|
|
|
$data->title = $title; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
// If a body is set add it to the data object. |
106
|
|
|
if (isset($body)) |
107
|
|
|
{ |
108
|
|
|
$data->body = $body; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
// If a state is set add it to the data object. |
112
|
|
|
if (isset($state)) |
113
|
|
|
{ |
114
|
|
|
$data->state = $state; |
115
|
|
|
} |
116
|
|
|
|
117
|
|
|
// If an assignee is set add it to the data object. |
118
|
|
|
if (isset($assignee)) |
119
|
|
|
{ |
120
|
|
|
$data->assignee = $assignee; |
121
|
|
|
} |
122
|
|
|
|
123
|
|
|
// If a milestone is set add it to the data object. |
124
|
|
|
if (isset($milestone)) |
125
|
|
|
{ |
126
|
|
|
$data->milestone = $milestone; |
127
|
|
|
} |
128
|
|
|
|
129
|
|
|
// If labels are set add them to the data object. |
130
|
|
|
if (isset($labels)) |
131
|
|
|
{ |
132
|
|
|
// Ensure that we have a non-associative array. |
133
|
|
|
if (isset($labels)) |
134
|
|
|
{ |
135
|
|
|
$labels = array_values($labels); |
136
|
|
|
} |
137
|
|
|
|
138
|
|
|
$data->labels = $labels; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
// Encode the request data. |
142
|
|
|
$data = json_encode($data); |
143
|
|
|
|
144
|
|
|
// Send the request. |
145
|
|
|
return $this->processResponse($this->client->patch($this->fetchUrl($path), $data)); |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* Get a single issue. |
150
|
|
|
* |
151
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
152
|
|
|
* @param string $repo The name of the GitHub repository. |
153
|
|
|
* @param integer $issueId The issue number. |
154
|
|
|
* |
155
|
|
|
* @return object |
156
|
|
|
* |
157
|
|
|
* @since 1.0 |
158
|
|
|
* @throws \DomainException |
159
|
|
|
*/ |
160
|
|
|
public function get($user, $repo, $issueId) |
161
|
|
|
{ |
162
|
|
|
// Build the request path. |
163
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues/' . (int) $issueId; |
164
|
|
|
|
165
|
|
|
// Send the request. |
166
|
|
|
return $this->processResponse($this->client->get($this->fetchUrl($path))); |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* List issues. |
171
|
|
|
* |
172
|
|
|
* @param string $filter The filter type: assigned, created, mentioned, subscribed. |
173
|
|
|
* @param string $state The optional state to filter requests by. [open, closed] |
174
|
|
|
* @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
175
|
|
|
* @param string $sort The sort order: created, updated, comments, default: created. |
176
|
|
|
* @param string $direction The list direction: asc or desc, default: desc. |
177
|
|
|
* @param \DateTime $since Only issues updated at or after this time are returned. |
178
|
|
|
* @param integer $page The page number from which to get items. |
179
|
|
|
* @param integer $limit The number of items on a page. |
180
|
|
|
* |
181
|
|
|
* @return object |
182
|
|
|
* |
183
|
|
|
* @since 1.0 |
184
|
|
|
* @throws \DomainException |
185
|
|
|
*/ |
186
|
|
|
public function getList($filter = null, $state = null, $labels = null, $sort = null, |
187
|
|
|
$direction = null, \DateTime $since = null, $page = 0, $limit = 0) |
188
|
|
|
{ |
189
|
|
|
// Build the request path. |
190
|
|
|
$path = '/issues'; |
191
|
|
|
|
192
|
|
|
$uri = new Uri($this->fetchUrl($path, $page, $limit)); |
193
|
|
|
|
194
|
|
|
if ($filter) |
|
|
|
|
195
|
|
|
{ |
196
|
|
|
$uri->setVar('filter', $filter); |
197
|
|
|
} |
198
|
|
|
|
199
|
|
|
if ($state) |
|
|
|
|
200
|
|
|
{ |
201
|
|
|
$uri->setVar('state', $state); |
202
|
|
|
} |
203
|
|
|
|
204
|
|
|
if ($labels) |
|
|
|
|
205
|
|
|
{ |
206
|
|
|
$uri->setVar('labels', $labels); |
207
|
|
|
} |
208
|
|
|
|
209
|
|
|
if ($sort) |
|
|
|
|
210
|
|
|
{ |
211
|
|
|
$uri->setVar('sort', $sort); |
212
|
|
|
} |
213
|
|
|
|
214
|
|
|
if ($direction) |
|
|
|
|
215
|
|
|
{ |
216
|
|
|
$uri->setVar('direction', $direction); |
217
|
|
|
} |
218
|
|
|
|
219
|
|
|
if ($since) |
220
|
|
|
{ |
221
|
|
|
$uri->setVar('since', $since->format(\DateTime::ISO8601)); |
222
|
|
|
} |
223
|
|
|
|
224
|
|
|
// Send the request. |
225
|
|
|
return $this->processResponse($this->client->get((string) $uri)); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* List issues for a repository. |
230
|
|
|
* |
231
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
232
|
|
|
* @param string $repo The name of the GitHub repository. |
233
|
|
|
* @param string $milestone The milestone number, 'none', or *. |
234
|
|
|
* @param string $state The optional state to filter requests by. [open, closed] |
235
|
|
|
* @param string $assignee The assignee name, 'none', or *. |
236
|
|
|
* @param string $mentioned The GitHub user name. |
237
|
|
|
* @param string $labels The list of comma separated Label names. Example: bug,ui,@high. |
238
|
|
|
* @param string $sort The sort order: created, updated, comments, default: created. |
239
|
|
|
* @param string $direction The list direction: asc or desc, default: desc. |
240
|
|
|
* @param \DateTime $since Only issues updated at or after this time are returned. |
241
|
|
|
* @param integer $page The page number from which to get items. |
242
|
|
|
* @param integer $limit The number of items on a page. |
243
|
|
|
* |
244
|
|
|
* @return object |
245
|
|
|
* |
246
|
|
|
* @since 1.0 |
247
|
|
|
* @throws \DomainException |
248
|
|
|
*/ |
249
|
|
|
public function getListByRepository($user, $repo, $milestone = null, $state = null, $assignee = null, $mentioned = null, $labels = null, |
250
|
|
|
$sort = null, $direction = null, \DateTime $since = null, $page = 0, $limit = 0) |
251
|
|
|
{ |
252
|
|
|
// Build the request path. |
253
|
|
|
$path = '/repos/' . $user . '/' . $repo . '/issues'; |
254
|
|
|
|
255
|
|
|
$uri = new Uri($this->fetchUrl($path, $page, $limit)); |
256
|
|
|
|
257
|
|
|
if ($milestone) |
|
|
|
|
258
|
|
|
{ |
259
|
|
|
$uri->setVar('milestone', $milestone); |
260
|
|
|
} |
261
|
|
|
|
262
|
|
|
if ($state) |
|
|
|
|
263
|
|
|
{ |
264
|
|
|
$uri->setVar('state', $state); |
265
|
|
|
} |
266
|
|
|
|
267
|
|
|
if ($assignee) |
|
|
|
|
268
|
|
|
{ |
269
|
|
|
$uri->setVar('assignee', $assignee); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
if ($mentioned) |
|
|
|
|
273
|
|
|
{ |
274
|
|
|
$uri->setVar('mentioned', $mentioned); |
275
|
|
|
} |
276
|
|
|
|
277
|
|
|
if ($labels) |
|
|
|
|
278
|
|
|
{ |
279
|
|
|
$uri->setVar('labels', $labels); |
280
|
|
|
} |
281
|
|
|
|
282
|
|
|
if ($sort) |
|
|
|
|
283
|
|
|
{ |
284
|
|
|
$uri->setVar('sort', $sort); |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
if ($direction) |
|
|
|
|
288
|
|
|
{ |
289
|
|
|
$uri->setVar('direction', $direction); |
290
|
|
|
} |
291
|
|
|
|
292
|
|
|
if ($since) |
293
|
|
|
{ |
294
|
|
|
$uri->setVar('since', $since->format(\DateTime::RFC3339)); |
295
|
|
|
} |
296
|
|
|
|
297
|
|
|
// Send the request. |
298
|
|
|
return $this->processResponse($this->client->get((string) $uri)); |
299
|
|
|
} |
300
|
|
|
|
301
|
|
|
/** |
302
|
|
|
* Lock an issue. |
303
|
|
|
* |
304
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
305
|
|
|
* @param string $repo The name of the GitHub repository. |
306
|
|
|
* @param integer $issueId The issue number. |
307
|
|
|
* |
308
|
|
|
* @return object |
309
|
|
|
* |
310
|
|
|
* @since 1.4.0 |
311
|
|
|
* @throws \DomainException |
312
|
|
|
*/ |
313
|
|
View Code Duplication |
public function lock($user, $repo, $issueId) |
|
|
|
|
314
|
|
|
{ |
315
|
|
|
// Build the request path. |
316
|
|
|
$path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; |
317
|
|
|
|
318
|
|
|
return $this->processResponse($this->client->put($this->fetchUrl($path), array()), 204); |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* Unlock an issue. |
323
|
|
|
* |
324
|
|
|
* @param string $user The name of the owner of the GitHub repository. |
325
|
|
|
* @param string $repo The name of the GitHub repository. |
326
|
|
|
* @param integer $issueId The issue number. |
327
|
|
|
* |
328
|
|
|
* @return object |
329
|
|
|
* |
330
|
|
|
* @since 1.4.0 |
331
|
|
|
* @throws \DomainException |
332
|
|
|
*/ |
333
|
|
|
public function unlock($user, $repo, $issueId) |
334
|
|
|
{ |
335
|
|
|
// Build the request path. |
336
|
|
|
$path = "/repos/$user/$repo/issues/" . (int) $issueId . '/lock'; |
337
|
|
|
|
338
|
|
|
return $this->processResponse($this->client->delete($this->fetchUrl($path)), 204); |
339
|
|
|
} |
340
|
|
|
} |
341
|
|
|
|
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: