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 References 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 JGithubRefs extends JGithubObject
19 {
20 /**
21 * Method to create an issue.
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 $ref The name of the fully qualified reference.
26 * @param string $sha The SHA1 value to set this reference to.
27 *
28 * @deprecated use data->refs->create()
29 *
30 * @return object
31 *
32 * @since 11.3
33 */
34 public function create($user, $repo, $ref, $sha)
35 {
36 // Build the request path.
37 $path = '/repos/' . $user . '/' . $repo . '/git/refs';
38
39 // Build the request data.
40 $data = json_encode(
41 array(
42 'ref' => $ref,
43 'sha' => $sha,
44 )
45 );
46
47 // Send the request.
48 $response = $this->client->post($this->fetchUrl($path), $data);
49
50 // Validate the response code.
51 if ($response->code != 201)
52 {
53 // Decode the error response and throw an exception.
54 $error = json_decode($response->body);
55 throw new DomainException($error->message, $response->code);
56 }
57
58 return json_decode($response->body);
59 }
60
61 /**
62 * Method to update a reference.
63 *
64 * @param string $user The name of the owner of the GitHub repository.
65 * @param string $repo The name of the GitHub repository.
66 * @param string $ref The reference to update.
67 * @param string $sha The SHA1 value to set the reference to.
68 * @param string $force Whether the update should be forced. Default to false.
69 *
70 * @deprecated use data->refs->edit()
71 *
72 * @return object
73 *
74 * @since 11.3
75 */
76 public function edit($user, $repo, $ref, $sha, $force = false)
77 {
78 // Build the request path.
79 $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref;
80
81 // Craete the data object.
82 $data = new stdClass;
83
84 // If a title is set add it to the data object.
85 if ($force)
86 {
87 $data->force = true;
88 }
89
90 $data->sha = $sha;
91
92 // Encode the request data.
93 $data = json_encode($data);
94
95 // Send the request.
96 $response = $this->client->patch($this->fetchUrl($path), $data);
97
98 // Validate the response code.
99 if ($response->code != 200)
100 {
101 // Decode the error response and throw an exception.
102 $error = json_decode($response->body);
103 throw new DomainException($error->message, $response->code);
104 }
105
106 return json_decode($response->body);
107 }
108
109 /**
110 * Method to get a reference.
111 *
112 * @param string $user The name of the owner of the GitHub repository.
113 * @param string $repo The name of the GitHub repository.
114 * @param string $ref The reference to get.
115 *
116 * @deprecated use data->refs->get()
117 *
118 * @return object
119 *
120 * @since 11.3
121 */
122 public function get($user, $repo, $ref)
123 {
124 // Build the request path.
125 $path = '/repos/' . $user . '/' . $repo . '/git/refs/' . $ref;
126
127 // Send the request.
128 $response = $this->client->get($this->fetchUrl($path));
129
130 // Validate the response code.
131 if ($response->code != 200)
132 {
133 // Decode the error response and throw an exception.
134 $error = json_decode($response->body);
135 throw new DomainException($error->message, $response->code);
136 }
137
138 return json_decode($response->body);
139 }
140
141 /**
142 * Method to list references for a repository.
143 *
144 * @param string $user The name of the owner of the GitHub repository.
145 * @param string $repo The name of the GitHub repository.
146 * @param string $namespace Optional sub-namespace to limit the returned references.
147 * @param integer $page Page to request
148 * @param integer $limit Number of results to return per page
149 *
150 * @deprecated use data->refs->getList()
151 *
152 * @return array
153 *
154 * @since 11.3
155 */
156 public function getList($user, $repo, $namespace = '', $page = 0, $limit = 0)
157 {
158 // Build the request path.
159 $path = '/repos/' . $user . '/' . $repo . '/git/refs' . $namespace;
160
161 // Send the request.
162 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
163
164 // Validate the response code.
165 if ($response->code != 200)
166 {
167 // Decode the error response and throw an exception.
168 $error = json_decode($response->body);
169 throw new DomainException($error->message, $response->code);
170 }
171
172 return json_decode($response->body);
173 }
174 }
175