These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
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 | |||
13 | /** |
||
14 | * GitHub API Activity class for the Joomla Framework. |
||
15 | * |
||
16 | * @since 1.0 |
||
17 | * |
||
18 | * @documentation http://developer.github.com/v3/repos |
||
19 | * |
||
20 | * @property-read Repositories\Branches $branches GitHub API object for branches. |
||
21 | * @property-read Repositories\Collaborators $collaborators GitHub API object for collaborators. |
||
22 | * @property-read Repositories\Comments $comments GitHub API object for comments. |
||
23 | * @property-read Repositories\Commits $commits GitHub API object for commits. |
||
24 | * @property-read Repositories\Contents $contents GitHub API object for contents. |
||
25 | * @property-read Repositories\Deployments $deployments GitHub API object for deployments. |
||
26 | * @property-read Repositories\Downloads $downloads GitHub API object for downloads. |
||
27 | * @property-read Repositories\Forks $forks GitHub API object for forks. |
||
28 | * @property-read Repositories\Hooks $hooks GitHub API object for hooks. |
||
29 | * @property-read Repositories\Keys $keys GitHub API object for keys. |
||
30 | * @property-read Repositories\Merging $merging GitHub API object for merging. |
||
31 | * @property-read Repositories\Pages $pages GitHub API object for pages. |
||
32 | * @property-read Repositories\Releases $releases GitHub API object for releases. |
||
33 | * @property-read Repositories\Statistics $statistics GitHub API object for statistics. |
||
34 | * @property-read Repositories\Statuses $statuses GitHub API object for statuses. |
||
35 | */ |
||
36 | class Repositories extends AbstractPackage |
||
37 | { |
||
38 | /** |
||
39 | * List your repositories. |
||
40 | * |
||
41 | * List repositories for the authenticated user. |
||
42 | * |
||
43 | * @param string $type Sort type. all, owner, public, private, member. Default: all. |
||
44 | * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. |
||
45 | * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. |
||
46 | * |
||
47 | * @return object |
||
48 | * |
||
49 | * @since 1.0 |
||
50 | * @throws \RuntimeException |
||
51 | */ |
||
52 | public function getListOwn($type = 'all', $sort = 'full_name', $direction = '') |
||
53 | { |
||
54 | View Code Duplication | if (false == in_array($type, array('all', 'owner', 'public', 'private', 'member'))) |
|
0 ignored issues
–
show
|
|||
55 | { |
||
56 | throw new \RuntimeException('Invalid type'); |
||
57 | } |
||
58 | |||
59 | View Code Duplication | if (false == in_array($sort, array('created', 'updated', 'pushed', 'full_name'))) |
|
0 ignored issues
–
show
|
|||
60 | { |
||
61 | throw new \RuntimeException('Invalid sort field'); |
||
62 | } |
||
63 | |||
64 | // Sort direction default: when using full_name: asc, otherwise desc. |
||
65 | $direction = ($direction) ? : (('full_name' == $sort) ? 'asc' : 'desc'); |
||
66 | |||
67 | View Code Duplication | if (false == in_array($direction, array('asc', 'desc'))) |
|
0 ignored issues
–
show
|
|||
68 | { |
||
69 | throw new \RuntimeException('Invalid sort order'); |
||
70 | } |
||
71 | |||
72 | // Build the request path. |
||
73 | $path = '/user/repos' |
||
74 | . '?type=' . $type |
||
75 | . '&sort=' . $sort |
||
76 | . '&direction=' . $direction; |
||
77 | |||
78 | // Send the request. |
||
79 | return $this->processResponse( |
||
80 | $this->client->get($this->fetchUrl($path)) |
||
81 | ); |
||
82 | } |
||
83 | |||
84 | /** |
||
85 | * List user repositories. |
||
86 | * |
||
87 | * List public repositories for the specified user. |
||
88 | * |
||
89 | * @param string $user The user name. |
||
90 | * @param string $type Sort type. all, owner, member. Default: all. |
||
91 | * @param string $sort Sort field. created, updated, pushed, full_name, default: full_name. |
||
92 | * @param string $direction Sort direction. asc or desc, default: when using full_name: asc, otherwise desc. |
||
93 | * |
||
94 | * @return object |
||
95 | * |
||
96 | * @since 1.0 |
||
97 | * @throws \RuntimeException |
||
98 | */ |
||
99 | public function getListUser($user, $type = 'all', $sort = 'full_name', $direction = '') |
||
100 | { |
||
101 | if (false == in_array($type, array('all', 'owner', 'member'))) |
||
0 ignored issues
–
show
|
|||
102 | { |
||
103 | throw new \RuntimeException('Invalid type'); |
||
104 | } |
||
105 | |||
106 | View Code Duplication | if (false == in_array($sort, array('created', 'updated', 'pushed', 'full_name'))) |
|
0 ignored issues
–
show
|
|||
107 | { |
||
108 | throw new \RuntimeException('Invalid sort field'); |
||
109 | } |
||
110 | |||
111 | // Sort direction default: when using full_name: asc, otherwise desc. |
||
112 | $direction = ($direction) ? : (('full_name' == $sort) ? 'asc' : 'desc'); |
||
113 | |||
114 | View Code Duplication | if (false == in_array($direction, array('asc', 'desc'))) |
|
0 ignored issues
–
show
|
|||
115 | { |
||
116 | throw new \RuntimeException('Invalid sort order'); |
||
117 | } |
||
118 | |||
119 | // Build the request path. |
||
120 | $path = '/users/' . $user . '/repos' |
||
121 | . '?type=' . $type |
||
122 | . '&sort=' . $sort |
||
123 | . '&direction=' . $direction; |
||
124 | |||
125 | // Send the request. |
||
126 | return $this->processResponse( |
||
127 | $this->client->get($this->fetchUrl($path)) |
||
128 | ); |
||
129 | } |
||
130 | |||
131 | /** |
||
132 | * List organization repositories. |
||
133 | * |
||
134 | * List repositories for the specified org. |
||
135 | * |
||
136 | * @param string $org The name of the organization. |
||
137 | * @param string $type Sort type. all, public, private, forks, sources, member. Default: all. |
||
138 | * |
||
139 | * @return object |
||
140 | * |
||
141 | * @since 1.0 |
||
142 | * @throws \RuntimeException |
||
143 | */ |
||
144 | public function getListOrg($org, $type = 'all') |
||
145 | { |
||
146 | View Code Duplication | if (false == in_array($type, array('all', 'public', 'private', 'forks', 'sources', 'member'))) |
|
0 ignored issues
–
show
|
|||
147 | { |
||
148 | throw new \RuntimeException('Invalid type'); |
||
149 | } |
||
150 | |||
151 | // Build the request path. |
||
152 | $path = '/orgs/' . $org . '/repos' |
||
153 | . '?type=' . $type; |
||
154 | |||
155 | // Send the request. |
||
156 | return $this->processResponse( |
||
157 | $this->client->get($this->fetchUrl($path)) |
||
158 | ); |
||
159 | } |
||
160 | |||
161 | /** |
||
162 | * List all public repositories. |
||
163 | * |
||
164 | * This provides a dump of every repository, in the order that they were created. |
||
165 | * |
||
166 | * @param integer $id The integer ID of the last Repository that you’ve seen. |
||
167 | * |
||
168 | * @return object |
||
169 | * |
||
170 | * @since 1.0 |
||
171 | * @throws \RuntimeException |
||
172 | */ |
||
173 | View Code Duplication | public function getList($id = 0) |
|
174 | { |
||
175 | // Build the request path. |
||
176 | $path = '/repositories'; |
||
177 | $path .= ($id) ? '?since=' . (int) $id : ''; |
||
178 | |||
179 | // Send the request. |
||
180 | return $this->processResponse( |
||
181 | $this->client->get($this->fetchUrl($path)) |
||
182 | ); |
||
183 | } |
||
184 | |||
185 | /** |
||
186 | * Create. |
||
187 | * |
||
188 | * Create a new repository for the authenticated user or an organization. OAuth users must supply repo scope. |
||
189 | * |
||
190 | * @param string $name The repository name. |
||
191 | * @param string $org The organization name (if needed). |
||
192 | * @param string $description The repository description. |
||
193 | * @param string $homepage The repository homepage. |
||
194 | * @param boolean $private Set true to create a private repository, false to create a public one. |
||
195 | * Creating private repositories requires a paid GitHub account. |
||
196 | * @param boolean $has_issues Set true to enable issues for this repository, false to disable them. |
||
197 | * @param boolean $has_wiki Set true to enable the wiki for this repository, false to disable it. |
||
198 | * @param boolean $has_downloads Set true to enable downloads for this repository, false to disable them. |
||
199 | * @param integer $team_id The id of the team that will be granted access to this repository. |
||
200 | * This is only valid when creating a repo in an organization. |
||
201 | * @param boolean $auto_init true to create an initial commit with empty README. |
||
202 | * @param string $gitignore_template Desired language or platform .gitignore template to apply. |
||
203 | * Use the name of the template without the extension. |
||
204 | * For example, “Haskell” Ignored if auto_init parameter is not provided. |
||
205 | * |
||
206 | * @return object |
||
207 | * |
||
208 | * @since 1.0 |
||
209 | */ |
||
210 | public function create($name, $org = '', $description = '', $homepage = '', $private = false, $has_issues = false, |
||
211 | $has_wiki = false, $has_downloads = false, $team_id = 0, $auto_init = false, $gitignore_template = '') |
||
212 | { |
||
213 | $path = ($org) |
||
214 | // Create a repository for an organization |
||
215 | ? '/orgs/' . $org . '/repos' |
||
216 | // Create a repository for a user |
||
217 | : '/user/repos'; |
||
218 | |||
219 | $data = array( |
||
220 | 'name' => $name, |
||
221 | 'description' => $description, |
||
222 | 'homepage' => $homepage, |
||
223 | 'private' => $private, |
||
224 | 'has_issues' => $has_issues, |
||
225 | 'has_wiki' => $has_wiki, |
||
226 | 'has_downloads' => $has_downloads, |
||
227 | 'team_id' => $team_id, |
||
228 | 'auto_init' => $auto_init, |
||
229 | 'gitignore_template' => $gitignore_template |
||
230 | ); |
||
231 | |||
232 | // Send the request. |
||
233 | return $this->processResponse( |
||
234 | $this->client->post($this->fetchUrl($path), json_encode($data)), |
||
235 | 201 |
||
236 | ); |
||
237 | } |
||
238 | |||
239 | /** |
||
240 | * Get. |
||
241 | * |
||
242 | * @param string $owner Repository owner. |
||
243 | * @param string $repo Repository name. |
||
244 | * |
||
245 | * @return object |
||
246 | * |
||
247 | * @since 1.0 |
||
248 | */ |
||
249 | public function get($owner, $repo) |
||
250 | { |
||
251 | // Build the request path. |
||
252 | $path = '/repos/' . $owner . '/' . $repo; |
||
253 | |||
254 | // Send the request. |
||
255 | return $this->processResponse( |
||
256 | $this->client->get($this->fetchUrl($path)) |
||
257 | ); |
||
258 | } |
||
259 | |||
260 | /** |
||
261 | * Edit. |
||
262 | * |
||
263 | * @param string $owner Repository owner. |
||
264 | * @param string $repo Repository name. |
||
265 | * @param string $name The repository name. |
||
266 | * @param string $description The repository description. |
||
267 | * @param string $homepage The repository homepage. |
||
268 | * @param boolean $private Set true to create a private repository, false to create a public one. |
||
269 | * Creating private repositories requires a paid GitHub account. |
||
270 | * @param boolean $has_issues Set true to enable issues for this repository, false to disable them. |
||
271 | * @param boolean $has_wiki Set true to enable the wiki for this repository, false to disable it. |
||
272 | * @param boolean $has_downloads Set true to enable downloads for this repository, false to disable them. |
||
273 | * @param string $default_branch Update the default branch for this repository |
||
274 | * |
||
275 | * @return object |
||
276 | * |
||
277 | * @since 1.0 |
||
278 | */ |
||
279 | public function edit($owner, $repo, $name, $description = '', $homepage = '', $private = false, $has_issues = false, |
||
280 | $has_wiki = false, $has_downloads = false, $default_branch = '') |
||
281 | { |
||
282 | $path = '/repos/' . $owner . '/' . $repo; |
||
283 | |||
284 | $data = array( |
||
285 | 'name' => $name, |
||
286 | 'description' => $description, |
||
287 | 'homepage' => $homepage, |
||
288 | 'private' => $private, |
||
289 | 'has_issues' => $has_issues, |
||
290 | 'has_wiki' => $has_wiki, |
||
291 | 'has_downloads' => $has_downloads, |
||
292 | 'default_branch' => $default_branch |
||
293 | ); |
||
294 | |||
295 | // Send the request. |
||
296 | return $this->processResponse( |
||
297 | $this->client->patch($this->fetchUrl($path), json_encode($data)) |
||
298 | ); |
||
299 | } |
||
300 | |||
301 | /** |
||
302 | * List contributors. |
||
303 | * |
||
304 | * @param string $owner Repository owner. |
||
305 | * @param string $repo Repository name. |
||
306 | * @param boolean $anon Set to 1 or true to include anonymous contributors in results. |
||
307 | * |
||
308 | * @return object |
||
309 | * |
||
310 | * @since 1.0 |
||
311 | */ |
||
312 | View Code Duplication | public function getListContributors($owner, $repo, $anon = false) |
|
313 | { |
||
314 | // Build the request path. |
||
315 | $path = '/repos/' . $owner . '/' . $repo . '/contributors'; |
||
316 | |||
317 | $path .= ($anon) ? '?anon=true' : ''; |
||
318 | |||
319 | // Send the request. |
||
320 | return $this->processResponse( |
||
321 | $this->client->get($this->fetchUrl($path)) |
||
322 | ); |
||
323 | } |
||
324 | |||
325 | /** |
||
326 | * List languages. |
||
327 | * |
||
328 | * List languages for the specified repository. The value on the right of a language is the number of bytes of code |
||
329 | * written in that language. |
||
330 | * |
||
331 | * @param string $owner Repository owner. |
||
332 | * @param string $repo Repository name. |
||
333 | * |
||
334 | * @return object |
||
335 | * |
||
336 | * @since 1.0 |
||
337 | */ |
||
338 | public function getListLanguages($owner, $repo) |
||
339 | { |
||
340 | // Build the request path. |
||
341 | $path = '/repos/' . $owner . '/' . $repo . '/languages'; |
||
342 | |||
343 | // Send the request. |
||
344 | return $this->processResponse( |
||
345 | $this->client->get($this->fetchUrl($path)) |
||
346 | ); |
||
347 | } |
||
348 | |||
349 | /** |
||
350 | * List Teams |
||
351 | * |
||
352 | * @param string $owner Repository owner. |
||
353 | * @param string $repo Repository name. |
||
354 | * |
||
355 | * @return object |
||
356 | * |
||
357 | * @since 1.0 |
||
358 | */ |
||
359 | public function getListTeams($owner, $repo) |
||
360 | { |
||
361 | // Build the request path. |
||
362 | $path = '/repos/' . $owner . '/' . $repo . '/teams'; |
||
363 | |||
364 | // Send the request. |
||
365 | return $this->processResponse( |
||
366 | $this->client->get($this->fetchUrl($path)) |
||
367 | ); |
||
368 | } |
||
369 | |||
370 | /** |
||
371 | * List Tags. |
||
372 | * |
||
373 | * @param string $owner Repository owner. |
||
374 | * @param string $repo Repository name. |
||
375 | * |
||
376 | * @return object |
||
377 | * |
||
378 | * @since 1.0 |
||
379 | */ |
||
380 | public function getListTags($owner, $repo) |
||
381 | { |
||
382 | // Build the request path. |
||
383 | $path = '/repos/' . $owner . '/' . $repo . '/tags'; |
||
384 | |||
385 | // Send the request. |
||
386 | return $this->processResponse( |
||
387 | $this->client->get($this->fetchUrl($path)) |
||
388 | ); |
||
389 | } |
||
390 | |||
391 | /** |
||
392 | * List Branches. |
||
393 | * |
||
394 | * @param string $owner Repository owner. |
||
395 | * @param string $repo Repository name. |
||
396 | * |
||
397 | * @return object |
||
398 | * |
||
399 | * @since 1.0 |
||
400 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::getList() instead |
||
401 | */ |
||
402 | public function getListBranches($owner, $repo) |
||
403 | { |
||
404 | return $this->branches->getList($owner, $repo); |
||
405 | } |
||
406 | |||
407 | /** |
||
408 | * Get a Branch. |
||
409 | * |
||
410 | * @param string $owner Repository owner. |
||
411 | * @param string $repo Repository name. |
||
412 | * @param string $branch Branch name. |
||
413 | * |
||
414 | * @return object |
||
415 | * |
||
416 | * @since 1.0 |
||
417 | * @deprecated 2.0 Use Joomla\Github\Package\Repositories\Branches::get() instead |
||
418 | */ |
||
419 | public function getBranch($owner, $repo, $branch) |
||
420 | { |
||
421 | return $this->branches->get($owner, $repo, $branch); |
||
422 | } |
||
423 | |||
424 | /** |
||
425 | * Delete a Repository. |
||
426 | * |
||
427 | * Deleting a repository requires admin access. If OAuth is used, the delete_repo scope is required. |
||
428 | * |
||
429 | * @param string $owner Repository owner. |
||
430 | * @param string $repo Repository name. |
||
431 | * |
||
432 | * @return object |
||
433 | * |
||
434 | * @since 1.0 |
||
435 | */ |
||
436 | public function delete($owner, $repo) |
||
437 | { |
||
438 | // Build the request path. |
||
439 | $path = '/repos/' . $owner . '/' . $repo; |
||
440 | |||
441 | // Send the request. |
||
442 | return $this->processResponse( |
||
443 | $this->client->delete($this->fetchUrl($path)) |
||
444 | ); |
||
445 | } |
||
446 | } |
||
447 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.