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 Pulls Comments class for the Joomla Platform.
14 *
15 * @documentation https://developer.github.com/v3/pulls/comments/
16 *
17 * @since 3.3 (CMS)
18 * @deprecated 4.0 Use the `joomla/github` package via Composer instead
19 */
20 class JGithubPackagePullsComments extends JGithubPackage
21 {
22 /**
23 * Method to create a comment on a pull request.
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 integer $pullId The pull request number.
28 * @param string $body The comment body text.
29 * @param string $commitId The SHA1 hash of the commit to comment on.
30 * @param string $filePath The Relative path of the file to comment on.
31 * @param string $position The line index in the diff to comment on.
32 *
33 * @throws DomainException
34 * @since 11.3
35 *
36 * @return object
37 */
38 public function create($user, $repo, $pullId, $body, $commitId, $filePath, $position)
39 {
40 // Build the request path.
41 $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments';
42
43 // Build the request data.
44 $data = json_encode(
45 array(
46 'body' => $body,
47 'commit_id' => $commitId,
48 'path' => $filePath,
49 'position' => $position,
50 )
51 );
52
53 // Send the request.
54 return $this->processResponse(
55 $this->client->post($this->fetchUrl($path), $data),
56 201
57 );
58 }
59
60 /**
61 * Method to create a comment in reply to another comment.
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 $pullId The pull request number.
66 * @param string $body The comment body text.
67 * @param integer $inReplyTo The id of the comment to reply to.
68 *
69 * @throws DomainException
70 * @since 11.3
71 *
72 * @return object
73 */
74 public function createReply($user, $repo, $pullId, $body, $inReplyTo)
75 {
76 // Build the request path.
77 $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments';
78
79 // Build the request data.
80 $data = json_encode(
81 array(
82 'body' => $body,
83 'in_reply_to' => (int) $inReplyTo,
84 )
85 );
86
87 // Send the request.
88 return $this->processResponse(
89 $this->client->post($this->fetchUrl($path), $data),
90 201
91 );
92 }
93
94 /**
95 * Method to delete a comment on a pull request.
96 *
97 * @param string $user The name of the owner of the GitHub repository.
98 * @param string $repo The name of the GitHub repository.
99 * @param integer $commentId The id of the comment to delete.
100 *
101 * @throws DomainException
102 * @since 11.3
103 *
104 * @return void
105 */
106 public function delete($user, $repo, $commentId)
107 {
108 // Build the request path.
109 $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId;
110
111 // Send the request.
112 $this->processResponse(
113 $this->client->delete($this->fetchUrl($path)),
114 204
115 );
116 }
117
118 /**
119 * Method to update a comment on a pull request.
120 *
121 * @param string $user The name of the owner of the GitHub repository.
122 * @param string $repo The name of the GitHub repository.
123 * @param integer $commentId The id of the comment to update.
124 * @param string $body The new body text for the comment.
125 *
126 * @throws DomainException
127 * @since 11.3
128 *
129 * @return object
130 */
131 public function edit($user, $repo, $commentId, $body)
132 {
133 // Build the request path.
134 $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId;
135
136 // Build the request data.
137 $data = json_encode(
138 array(
139 'body' => $body,
140 )
141 );
142
143 // Send the request.
144 return $this->processResponse(
145 $this->client->patch($this->fetchUrl($path), $data)
146 );
147 }
148
149 /**
150 * Method to get a specific comment on a pull request.
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 $commentId The comment id to get.
155 *
156 * @throws DomainException
157 * @since 11.3
158 *
159 * @return object
160 */
161 public function get($user, $repo, $commentId)
162 {
163 // Build the request path.
164 $path = '/repos/' . $user . '/' . $repo . '/pulls/comments/' . (int) $commentId;
165
166 // Send the request.
167 return $this->processResponse(
168 $this->client->get($this->fetchUrl($path))
169 );
170 }
171
172 /**
173 * Method to get the list of comments on a pull request.
174 *
175 * @param string $user The name of the owner of the GitHub repository.
176 * @param string $repo The name of the GitHub repository.
177 * @param integer $pullId The pull request number.
178 * @param integer $page The page number from which to get items.
179 * @param integer $limit The number of items on a page.
180 *
181 * @throws DomainException
182 * @since 11.3
183 *
184 * @return array
185 */
186 public function getList($user, $repo, $pullId, $page = 0, $limit = 0)
187 {
188 // Build the request path.
189 $path = '/repos/' . $user . '/' . $repo . '/pulls/' . (int) $pullId . '/comments';
190
191 // Send the request.
192 return $this->processResponse(
193 $this->client->get($this->fetchUrl($path, $page, $limit))
194 );
195 }
196 }
197