Skip to content

Commit a694ffe

Browse files
committed
Moved commit and issues to new API
1 parent f4c7210 commit a694ffe

File tree

2 files changed

+76
-71
lines changed

2 files changed

+76
-71
lines changed

lib/Github/Api/Commit.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ public function getFileCommits($username, $repo, $branch, $path)
5252
* @param string $username the username
5353
* @param string $repo the repo
5454
* @param string $sha the commit sha
55+
* @return array data from commit
5556
*/
5657
public function getCommit($username, $repo, $sha)
5758
{
@@ -64,13 +65,12 @@ public function getCommit($username, $repo, $sha)
6465
* @param string $username
6566
* @param string $repoName
6667
* @param string $branchName
67-
* @return string
68+
* @return null|string
6869
*/
6970
private function getBranchSha($username, $repoName, $branchName)
7071
{
7172
$branchInfo = $this->get('repos/'.urlencode($username).'/'.urlencode($repoName).'/git/trees/'.urlencode($branchName));
72-
if (isset($branchInfo['sha'])) {
73-
return $branchInfo['sha'];
74-
}
73+
74+
return isset($branchInfo['sha']) ? $branchInfo['sha'] : null;
7575
}
7676
}

lib/Github/Api/Issue.php

Lines changed: 72 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Issue extends Api
1313
{
1414
/**
1515
* List issues by username, repo and state
16-
* http://develop.github.com/p/issues.html#list_a_projects_issues
16+
* @link http://developer.github.com/v3/issues/
1717
*
1818
* @param string $username the username
1919
* @param string $repo the repo
@@ -22,9 +22,7 @@ class Issue extends Api
2222
*/
2323
public function getList($username, $repo, $state = 'open')
2424
{
25-
$response = $this->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state));
26-
27-
return $response['issues'];
25+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues?state='.urlencode($state));
2826
}
2927

3028
/**
@@ -39,9 +37,7 @@ public function getList($username, $repo, $state = 'open')
3937
*/
4038
public function search($username, $repo, $state, $searchTerm)
4139
{
42-
$response = $this->get('issues/search/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($state).'/'.urlencode($searchTerm));
43-
44-
return $response['issues'];
40+
throw new \BadMethodCallException('Method cannot be implemented using new api version');
4541
}
4642

4743
/**
@@ -54,46 +50,40 @@ public function search($username, $repo, $state, $searchTerm)
5450
*/
5551
public function searchLabel($username, $repo, $label)
5652
{
57-
$response = $this->get('issues/list/'.urlencode($username).'/'.urlencode($repo).'/label/'.urlencode($label));
58-
59-
return $response['issues'];
53+
throw new \BadMethodCallException('Method cannot be implemented using new api version');
6054
}
6155

6256
/**
6357
* Get extended information about an issue by its username, repo and number
64-
* http://develop.github.com/p/issues.html#view_an_issue
58+
* @link http://developer.github.com/v3/issues/
6559
*
6660
* @param string $username the username
6761
* @param string $repo the repo
68-
* @param string $issueNumber the issue number
62+
* @param string $number the issue number
6963
* @return array information about the issue
7064
*/
71-
public function show($username, $repo, $issueNumber)
65+
public function show($username, $repo, $number)
7266
{
73-
$response = $this->get('issues/show/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
74-
75-
return $response['issue'];
67+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number));
7668
}
7769

7870
/**
7971
* Create a new issue for the given username and repo.
8072
* The issue is assigned to the authenticated user. Requires authentication.
81-
* http://develop.github.com/p/issues.html#open_and_close_issues
73+
* @link http://developer.github.com/v3/issues/
8274
*
8375
* @param string $username the username
8476
* @param string $repo the repo
85-
* @param string $issueTitle the new issue title
86-
* @param string $issueBody the new issue body
77+
* @param string $title the new issue title
78+
* @param string $body the new issue body
8779
* @return array information about the issue
8880
*/
89-
public function open($username, $repo, $issueTitle, $issueBody)
81+
public function open($username, $repo, $title, $body)
9082
{
91-
$response = $this->post('issues/open/'.urlencode($username).'/'.urlencode($repo), array(
92-
'title' => $issueTitle,
93-
'body' => $issueBody
83+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues', array(
84+
'title' => $title,
85+
'body' => $body
9486
));
95-
96-
return $response['issue'];
9787
}
9888

9989
/**
@@ -102,14 +92,12 @@ public function open($username, $repo, $issueTitle, $issueBody)
10292
*
10393
* @param string $username the username
10494
* @param string $repo the repo
105-
* @param string $issueNumber the issue number
95+
* @param string $number the issue number
10696
* @return array information about the issue
10797
*/
108-
public function close($username, $repo, $issueNumber)
98+
public function close($username, $repo, $number)
10999
{
110-
$response = $this->post('issues/close/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
111-
112-
return $response['issue'];
100+
return $this->update($username, $repo, $number, array('state' => 'closed'));
113101
}
114102

115103
/**
@@ -118,16 +106,14 @@ public function close($username, $repo, $issueNumber)
118106
*
119107
* @param string $username the username
120108
* @param string $repo the repo
121-
* @param string $issueNumber the issue number
109+
* @param string $number the issue number
122110
* @param array $data key=>value user attributes to update.
123111
* key can be title or body
124112
* @return array information about the issue
125113
*/
126-
public function update($username, $repo, $issueNumber, array $data)
114+
public function update($username, $repo, $number, array $data)
127115
{
128-
$response = $this->post('issues/edit/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), $data);
129-
130-
return $response['issue'];
116+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number), $data);
131117
}
132118

133119
/**
@@ -136,14 +122,12 @@ public function update($username, $repo, $issueNumber, array $data)
136122
*
137123
* @param string $username the username
138124
* @param string $repo the repo
139-
* @param string $issueNumber the issue number
125+
* @param string $number the issue number
140126
* @return array informations about the issue
141127
*/
142-
public function reOpen($username, $repo, $issueNumber)
128+
public function reOpen($username, $repo, $number)
143129
{
144-
$response = $this->post('issues/reopen/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
145-
146-
return $response['issue'];
130+
return $this->update($username, $repo, $number, array('state' => 'open'));
147131
}
148132

149133
/**
@@ -152,81 +136,102 @@ public function reOpen($username, $repo, $issueNumber)
152136
*
153137
* @param string $username the username
154138
* @param string $repo the repo
155-
* @param string $issueNumber the issue number
139+
* @param string $number the issue number
156140
* @return array list of issue comments
157141
*/
158-
public function getComments($username, $repo, $issueNumber)
142+
public function getComments($username, $repo, $number)
159143
{
160-
$response = $this->get('issues/comments/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber));
144+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments');
145+
}
161146

162-
return $response['comments'];
147+
/**
148+
* Get an issue comments by username, repo, issue number and comment id
149+
* @link http://developer.github.com/v3/issues/comments/
150+
*
151+
* @param string $username the username
152+
* @param string $repo the repo
153+
* @param string $number the issue number
154+
* @param string $id the comment id
155+
* @return array list of issue comments
156+
*/
157+
public function getComment($username, $repo, $number, $id)
158+
{
159+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments/'.urlencode($id));
163160
}
164161

165162
/**
166163
* Add a comment to the issue by username, repo and issue number
167-
* http://develop.github.com/p/issues.html#comment_on_issues
164+
* @link http://developer.github.com/v3/issues/comments/
168165
*
169166
* @param string $username the username
170167
* @param string $repo the repo
171-
* @param string $issueNumber the issue number
172-
* @param string $comment the comment body
168+
* @param string $number the issue number
169+
* @param string $body the comment body
173170
* @return array the created comment
174171
*/
175-
public function addComment($username, $repo, $issueNumber, $commentBody)
172+
public function addComment($username, $repo, $number, $body)
176173
{
177-
$response = $this->post('issues/comment/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($issueNumber), array(
178-
'comment' => $commentBody
174+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/issues/'.urlencode($number).'/comments', array(
175+
'body' => $body
179176
));
180-
181-
return $response['comment'];
182177
}
183178

184179
/**
185180
* List all project labels by username and repo
186-
* http://develop.github.com/p/issues.html#listing_labels
181+
* @link http://developer.github.com/v3/issues/labels/
187182
*
188183
* @param string $username the username
189184
* @param string $repo the repo
190185
* @return array list of project labels
191186
*/
192187
public function getLabels($username, $repo)
193188
{
194-
$response = $this->get('issues/labels/'.urlencode($username).'/'.urlencode($repo));
189+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/labels');
190+
}
195191

196-
return $response['labels'];
192+
/**
193+
* Get project label by username and repo
194+
* @link http://developer.github.com/v3/issues/labels/
195+
*
196+
* @param string $username the username
197+
* @param string $repo the repo
198+
* @param string $name the label name
199+
* @return array list of project labels
200+
*/
201+
public function getLabel($username, $repo, $name)
202+
{
203+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/labels/'.urlencode($name));
197204
}
198205

199206
/**
200207
* Add a label to the issue by username, repo and issue number. Requires authentication.
201-
* http://develop.github.com/p/issues.html#add_and_remove_labels
208+
* @link http://developer.github.com/v3/issues/labels/
202209
*
203210
* @param string $username the username
204211
* @param string $repo the repo
205-
* @param string $issueNumber the issue number
206212
* @param string $labelName the label name
213+
* @param string $labelColor the label color
207214
* @return array list of issue labels
208215
*/
209-
public function addLabel($username, $repo, $labelName, $issueNumber)
216+
public function addLabel($username, $repo, $labelName, $labelColor)
210217
{
211-
$response = $this->post('issues/label/add/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
212-
213-
return $response['labels'];
218+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/labels', array(
219+
'name' => $labelName,
220+
'color' => $labelColor
221+
));
214222
}
215223

216224
/**
217225
* Remove a label from the issue by username, repo, issue number and label name. Requires authentication.
218-
* http://develop.github.com/p/issues.html#add_and_remove_labels
226+
* @link http://developer.github.com/v3/issues/labels/
219227
*
220228
* @param string $username the username
221229
* @param string $repo the repo
222-
* @param string $issueNumber the issue number
223230
* @param string $labelName the label name
224231
* @return array list of issue labels
225232
*/
226-
public function removeLabel($username, $repo, $labelName, $issueNumber)
233+
public function removeLabel($username, $repo, $labelName)
227234
{
228-
$response = $this->post('issues/label/remove/'.urlencode($username).'/'.urlencode($repo).'/'.urlencode($labelName).'/'.urlencode($issueNumber));
229-
230-
return $response['labels'];
235+
return $this->delete('repos/'.urlencode($username).'/'.urlencode($repo).'/labels/'.urlencode($labelName));
231236
}
232237
}

0 commit comments

Comments
 (0)