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 Milestones class for the Joomla Platform.
14 *
15 * @since 12.3
16 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
17 */
18 class JGithubMilestones extends JGithubObject
19 {
20 /**
21 * Method to get the list of milestones for a repo.
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 $state The milestone state to retrieved. Open (default) or closed.
26 * @param string $sort Sort can be due_date (default) or completeness.
27 * @param string $direction Direction is asc or desc (default).
28 * @param integer $page The page number from which to get items.
29 * @param integer $limit The number of items on a page.
30 *
31 * @deprecated use issues->milestones->getList()
32 *
33 * @return array
34 *
35 * @since 12.3
36 */
37 public function getList($user, $repo, $state = 'open', $sort = 'due_date', $direction = 'desc', $page = 0, $limit = 0)
38 {
39 // Build the request path.
40 $path = '/repos/' . $user . '/' . $repo . '/milestones?';
41
42 $path .= 'state=' . $state;
43 $path .= '&sort=' . $sort;
44 $path .= '&direction=' . $direction;
45
46 // Send the request.
47 $response = $this->client->get($this->fetchUrl($path, $page, $limit));
48
49 // Validate the response code.
50 if ($response->code != 200)
51 {
52 // Decode the error response and throw an exception.
53 $error = json_decode($response->body);
54 throw new DomainException($error->message, $response->code);
55 }
56
57 return json_decode($response->body);
58 }
59
60 /**
61 * Method to get a specific milestone.
62 *
63 * @param string $user The name of the owner of the GitHub repository.
64 * @param string $repo The name of the GitHub repository.
65 * @param integer $milestoneId The milestone id to get.
66 *
67 * @deprecated use issues->milestones->get()
68 *
69 * @return object
70 *
71 * @since 12.3
72 */
73 public function get($user, $repo, $milestoneId)
74 {
75 // Build the request path.
76 $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
77
78 // Send the request.
79 $response = $this->client->get($this->fetchUrl($path));
80
81 // Validate the response code.
82 if ($response->code != 200)
83 {
84 // Decode the error response and throw an exception.
85 $error = json_decode($response->body);
86 throw new DomainException($error->message, $response->code);
87 }
88
89 return json_decode($response->body);
90 }
91
92 /**
93 * Method to create a milestone for a repository.
94 *
95 * @param string $user The name of the owner of the GitHub repository.
96 * @param string $repo The name of the GitHub repository.
97 * @param integer $title The title of the milestone.
98 * @param string $state Can be open (default) or closed.
99 * @param string $description Optional description for milestone.
100 * @param string $due_on Optional ISO 8601 time.
101 *
102 * @deprecated use issues->milestones->create()
103 *
104 * @return object
105 *
106 * @since 12.3
107 */
108 public function create($user, $repo, $title, $state = null, $description = null, $due_on = null)
109 {
110 // Build the request path.
111 $path = '/repos/' . $user . '/' . $repo . '/milestones';
112
113 // Build the request data.
114 $data = array(
115 'title' => $title,
116 );
117
118 if (!is_null($state))
119 {
120 $data['state'] = $state;
121 }
122
123 if (!is_null($description))
124 {
125 $data['description'] = $description;
126 }
127
128 if (!is_null($due_on))
129 {
130 $data['due_on'] = $due_on;
131 }
132
133 $data = json_encode($data);
134
135 // Send the request.
136 $response = $this->client->post($this->fetchUrl($path), $data);
137
138 // Validate the response code.
139 if ($response->code != 201)
140 {
141 // Decode the error response and throw an exception.
142 $error = json_decode($response->body);
143 throw new DomainException($error->message, $response->code);
144 }
145
146 return json_decode($response->body);
147 }
148
149 /**
150 * Method to update a milestone.
151 *
152 * @param string $user The name of the owner of the GitHub repository.
153 * @param string $repo The name of the GitHub repository.
154 * @param integer $milestoneId The id of the comment to update.
155 * @param integer $title Optional title of the milestone.
156 * @param string $state Can be open (default) or closed.
157 * @param string $description Optional description for milestone.
158 * @param string $due_on Optional ISO 8601 time.
159 *
160 * @deprecated use issues->milestones->edit()
161 *
162 * @return object
163 *
164 * @since 12.3
165 */
166 public function edit($user, $repo, $milestoneId, $title = null, $state = null, $description = null, $due_on = null)
167 {
168 // Build the request path.
169 $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
170
171 // Build the request data.
172 $data = array();
173
174 if (!is_null($title))
175 {
176 $data['title'] = $title;
177 }
178
179 if (!is_null($state))
180 {
181 $data['state'] = $state;
182 }
183
184 if (!is_null($description))
185 {
186 $data['description'] = $description;
187 }
188
189 if (!is_null($due_on))
190 {
191 $data['due_on'] = $due_on;
192 }
193
194 $data = json_encode($data);
195
196 // Send the request.
197 $response = $this->client->patch($this->fetchUrl($path), $data);
198
199 // Validate the response code.
200 if ($response->code != 200)
201 {
202 // Decode the error response and throw an exception.
203 $error = json_decode($response->body);
204 throw new DomainException($error->message, $response->code);
205 }
206
207 return json_decode($response->body);
208 }
209
210 /**
211 * Method to delete a milestone.
212 *
213 * @param string $user The name of the owner of the GitHub repository.
214 * @param string $repo The name of the GitHub repository.
215 * @param integer $milestoneId The id of the milestone to delete.
216 *
217 * @deprecated use issues->milestones->delete()
218 *
219 * @return void
220 *
221 * @since 12.3
222 */
223 public function delete($user, $repo, $milestoneId)
224 {
225 // Build the request path.
226 $path = '/repos/' . $user . '/' . $repo . '/milestones/' . (int) $milestoneId;
227
228 // Send the request.
229 $response = $this->client->delete($this->fetchUrl($path));
230
231 // Validate the response code.
232 if ($response->code != 204)
233 {
234 // Decode the error response and throw an exception.
235 $error = json_decode($response->body);
236 throw new DomainException($error->message, $response->code);
237 }
238 }
239 }
240