1 <?php
2 /**
3 * @package Joomla.Platform
4 * @subpackage GitHub
5 *
6 * @copyright Copyright (C) 2005 - 2017 Open Source Matters, Inc. All rights reserved.
7 * @license GNU General Public License version 2 or later; see LICENSE
8 */
9
10 defined('JPATH_PLATFORM') or die;
11
12 /**
13 * GitHub API Forks class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/repos/forks
16 *
17 * @since 11.3
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackageRepositoriesForks extends JGithubPackage
21 {
22 /**
23 * Method to fork a repository.
24 *
25 * @param string $user The name of the owner of the GitHub repository.
26 * @param string $repo The name of the GitHub repository.
27 * @param string $org The organization to fork the repo into. By default it is forked to the current user.
28 *
29 * @return object
30 *
31 * @since 11.4
32 * @throws DomainException
33 */
34 public function create($user, $repo, $org = '')
35 {
36 // Build the request path.
37 $path = '/repos/' . $user . '/' . $repo . '/forks';
38
39 if (strlen($org) > 0)
40 {
41 $data = json_encode(
42 array('org' => $org)
43 );
44 }
45 else
46 {
47 $data = json_encode(array());
48 }
49
50 // Send the request.
51 $response = $this->client->post($this->fetchUrl($path), $data);
52
53 // Validate the response code.
54 if ($response->code != 202)
55 {
56 // Decode the error response and throw an exception.
57 $error = json_decode($response->body);
58 throw new DomainException($error->message, $response->code);
59 }
60
61 return json_decode($response->body);
62 }
63
64 /**
65 * Method to list forks for a repository.
66 *
67 * @param string $user The name of the owner of the GitHub repository.
68 * @param string $repo The name of the GitHub repository.
69 * @param integer $page Page to request
70 * @param integer $limit Number of results to return per page
71 *
72 * @return array
73 *
74 * @since 11.4
75 * @throws DomainException
76 */
77 public function getList($user, $repo, $page = 0, $limit = 0)
78 {
79 // Build the request path.
80 $path = '/repos/' . $user . '/' . $repo . '/forks';
81
82 // Send the request.
83 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
84
85 // Validate the response code.
86 if ($response->code != 200)
87 {
88 // Decode the error response and throw an exception.
89 $error = json_decode($response->body);
90 throw new DomainException($error->message, $response->code);
91 }
92
93 return json_decode($response->body);
94 }
95 }
96