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 * @since 11.3
16 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
17 */
18 class JGithubForks extends JGithubObject
19 {
20 /**
21 * Method to fork a repository.
22 *
23 * @param string $user The name of the owner of the GitHub repository.
24 * @param string $repo The name of the GitHub repository.
25 * @param string $org The organization to fork the repo into. By default it is forked to the current user.
26 *
27 * @deprecated use repositories->forks->create()
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 * @deprecated use repositories->forks->getList()
73 *
74 * @return array
75 *
76 * @since 11.4
77 * @throws DomainException
78 */
79 public function getList($user, $repo, $page = 0, $limit = 0)
80 {
81 // Build the request path.
82 $path = '/repos/' . $user . '/' . $repo . '/forks';
83
84 // Send the request.
85 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
86
87 // Validate the response code.
88 if ($response->code != 200)
89 {
90 // Decode the error response and throw an exception.
91 $error = json_decode($response->body);
92 throw new DomainException($error->message, $response->code);
93 }
94
95 return json_decode($response->body);
96 }
97 }
98