Skip to content

Commit 681c7d0

Browse files
committed
Fix repository calls with new API v3
1 parent 9701bac commit 681c7d0

File tree

1 file changed

+71
-63
lines changed

1 file changed

+71
-63
lines changed

lib/Github/Api/Repo.php

Lines changed: 71 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,7 @@ class Repo extends Api
2323
*/
2424
public function search($query, $language = '', $startPage = 1)
2525
{
26-
//todo old api
27-
$response = $this->get('repos/search/'.urlencode($query), array(
28-
'language' => strtolower($language),
29-
'start_page' => $startPage
30-
));
31-
32-
return $response['repositories'];
26+
throw new \BadMethodCallException('Method cannot be implemented using new api version');
3327
}
3428

3529
/**
@@ -44,7 +38,7 @@ public function getPushableRepos()
4438

4539
/**
4640
* Get the repositories of a user
47-
* http://develop.github.com/p/repo.html
41+
* @link http://developer.github.com/v3/repos/
4842
*
4943
* @param string $username the username
5044
* @return array list of the user repos
@@ -56,6 +50,7 @@ public function getUserRepos($username)
5650

5751
/**
5852
* Get extended information about a repository by its username and repo name
53+
* @link http://developer.github.com/v3/repos/
5954
*
6055
* @param string $username the user who owns the repo
6156
* @param string $repo the name of the repo
@@ -67,7 +62,8 @@ public function show($username, $repo)
6762
}
6863

6964
/**
70-
* create repo
65+
* Create repo
66+
* @link http://developer.github.com/v3/repos/
7167
*
7268
* @param string $name name of the repository
7369
* @param string $description repo description
@@ -86,7 +82,7 @@ public function create($name, $description = '', $homepage = '', $public = true)
8682
}
8783

8884
/**
89-
* delete repo
85+
* Delete repo
9086
*
9187
* @param string $name name of the repository
9288
* @param string $token delete token
@@ -116,6 +112,7 @@ public function delete($name, $token = null, $force = false)
116112

117113
/**
118114
* Set information of a repository
115+
* @link http://developer.github.com/v3/repos/
119116
*
120117
* @param string $username the user who owns the repo
121118
* @param string $repo the name of the repo
@@ -128,7 +125,8 @@ public function setRepoInfo($username, $repo, $values)
128125
}
129126

130127
/**
131-
* Set the visibility of a repostory to public
128+
* Set the visibility of a repository to public
129+
* @link http://developer.github.com/v3/repos/
132130
*
133131
* @param string $username the user who owns the repo
134132
* @param string $repo the name of the repo
@@ -140,7 +138,8 @@ public function setPublic($username, $repo)
140138
}
141139

142140
/**
143-
* Set the visibility of a repostory to private
141+
* Set the visibility of a repository to private
142+
* @link http://developer.github.com/v3/repos/
144143
*
145144
* @param string $username the user who owns the repo
146145
* @param string $repo the name of the repo
@@ -153,6 +152,7 @@ public function setPrivate($username, $repo)
153152

154153
/**
155154
* Get the list of deploy keys for a repository
155+
* @link http://developer.github.com/v3/repos/keys/
156156
*
157157
* @param string $username the user who owns the repo
158158
* @param string $repo the name of the repo
@@ -165,6 +165,7 @@ public function getDeployKeys($username, $repo)
165165

166166
/**
167167
* Add a deploy key for a repository
168+
* @link http://developer.github.com/v3/repos/keys/
168169
*
169170
* @param string $username the user who owns the repo
170171
* @param string $repo the name of the repo
@@ -182,6 +183,7 @@ public function addDeployKey($username, $repo, $title, $key)
182183

183184
/**
184185
* Delete a deploy key from a repository
186+
* @link http://developer.github.com/v3/repos/keys/
185187
*
186188
* @param string $username the user who owns the repo
187189
* @param string $repo the name of the repo
@@ -195,136 +197,135 @@ public function removeDeployKey($username, $repo, $id)
195197

196198
/**
197199
* Get the collaborators of a repository
200+
* @link http://developer.github.com/v3/repos/collaborators/
198201
*
199202
* @param string $username the user who owns the repo
200203
* @param string $repo the name of the repo
201204
* @return array list of the repo collaborators
202205
*/
203206
public function getRepoCollaborators($username, $repo)
204207
{
205-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/collaborators');
208+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/collaborators');
209+
}
206210

207-
return $response['collaborators'];
211+
/**
212+
* Get the collaborator of a repository
213+
* @link http://developer.github.com/v3/repos/collaborators/
214+
*
215+
* @param string $username the user who owns the repo
216+
* @param string $repo the name of the repo
217+
* @param string $user the user which we seek
218+
* @return array list of the repo collaborators
219+
*/
220+
public function getRepoCollaborator($username, $repo, $user)
221+
{
222+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/collaborators/'.urlencode($user));
208223
}
209224

210225
/**
211226
* Add a collaborator to a repository
212-
* http://develop.github.com/p/repo.html
227+
* @link http://developer.github.com/v3/repos/collaborators/
213228
*
229+
* @param string $username the user who owns the repo
214230
* @param string $repo the name of the repo
215-
* @param string $username the user who should be added as a collaborator
231+
* @param string $user the user who should be added as a collaborator
216232
* @return array list of the repo collaborators
217233
*/
218-
public function addRepoCollaborator($repo, $username)
234+
public function addRepoCollaborator($username, $repo, $user)
219235
{
220-
$response = $this->post('repos/collaborators/'.urlencode($repo).'/add/'.urlencode($username));
221-
222-
return $response['collaborators'];
236+
return $this->put('repos/'.urlencode($username).'/'.urlencode($repo).'/collaborators/'.urlencode($user));
223237
}
224238

225239
/**
226240
* Delete a collaborator from a repository
227-
* http://develop.github.com/p/repo.html
241+
* @link http://developer.github.com/v3/repos/collaborators/
228242
*
243+
* @param string $username the user who owns the repo
229244
* @param string $repo the name of the repo
230-
* @param string $username the user who should be removed as a collaborator
245+
* @param string $user the user who should be removed as a collaborator
231246
* @return array list of the repo collaborators
232247
*/
233-
public function removeRepoCollaborator($repo, $username)
248+
public function removeRepoCollaborator($repo, $username, $user)
234249
{
235-
$response = $this->post('repos/collaborators/'.urlencode($repo).'/remove/'.urlencode($username));
236-
237-
return $response['collaborators'];
250+
return $this->delete('repos/'.urlencode($username).'/'.urlencode($repo).'/collaborators/'.urlencode($user));
238251
}
239252

240253
/**
241254
* Make the authenticated user watch a repository
242-
* http://develop.github.com/p/repo.html
255+
* @link http://developer.github.com/v3/repos/watching/
243256
*
244257
* @param string $username the user who owns the repo
245258
* @param string $repo the name of the repo
246259
* @return array informations about the repo
247260
*/
248261
public function watch($username, $repo)
249262
{
250-
$response = $this->get('repos/watch/'.urlencode($username).'/'.urlencode($repo));
251-
252-
return $response['repository'];
263+
return $this->put('user/watched/'.urlencode($username).'/'.urlencode($repo));
253264
}
254265

255266
/**
256267
* Make the authenticated user unwatch a repository
257-
* http://develop.github.com/p/repo.html
268+
* @link http://developer.github.com/v3/repos/watching/
258269
*
259270
* @param string $username the user who owns the repo
260271
* @param string $repo the name of the repo
261272
* @return array informations about the repo
262273
*/
263274
public function unwatch($username, $repo)
264275
{
265-
$response = $this->get('repos/unwatch/'.urlencode($username).'/'.urlencode($repo));
266-
267-
return $response['repository'];
276+
return $this->delete('user/watched/'.urlencode($username).'/'.urlencode($repo));
268277
}
269278

270279
/**
271280
* Make the authenticated user fork a repository
272-
* http://develop.github.com/p/repo.html
281+
* @link http://developer.github.com/v3/repos/forks/
273282
*
274283
* @param string $username the user who owns the repo
275284
* @param string $repo the name of the repo
276285
* @return array informations about the newly forked repo
277286
*/
278287
public function fork($username, $repo)
279288
{
280-
$response = $this->get('repos/fork/'.urlencode($username).'/'.urlencode($repo));
281-
282-
return $response['repository'];
289+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repo).'/forks');
283290
}
284291

285292
/**
286293
* Get the tags of a repository
287-
* http://develop.github.com/p/repo.html
294+
* @link http://developer.github.com/v3/repos/
288295
*
289296
* @param string $username the user who owns the repo
290297
* @param string $repo the name of the repo
291298
* @return array list of the repo tags
292299
*/
293300
public function getRepoTags($username, $repo)
294301
{
295-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/tags');
296-
297-
return $response['tags'];
302+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/tags');
298303
}
299304

300305
/**
301306
* Get the branches of a repository
302-
* http://develop.github.com/p/repo.html
307+
* @link http://developer.github.com/v3/repos/
303308
*
304309
* @param string $username the username
305310
* @param string $repo the name of the repo
306311
* @return array list of the repo branches
307312
*/
308313
public function getRepoBranches($username, $repo)
309314
{
310-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/branches');
311-
312-
return $response['branches'];
315+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/branches');
313316
}
314317

315318
/**
316319
* Get the watchers of a repository
317-
* http://develop.github.com/p/repo.html
320+
* @link http://developer.github.com/v3/repos/watching/
318321
*
319322
* @param string $username the user who owns the repo
320323
* @param string $repo the name of the repo
321324
* @return array list of the repo watchers
322325
*/
323326
public function getRepoWatchers($username, $repo)
324327
{
325-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/watchers');
326-
327-
return $response['watchers'];
328+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/watchers');
328329
}
329330

330331
/**
@@ -337,44 +338,51 @@ public function getRepoWatchers($username, $repo)
337338
*/
338339
public function getRepoNetwork($username, $repo)
339340
{
340-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/network');
341-
342-
return $response['network'];
341+
throw new \BadMethodCallException('Method cannot be implemented using new api version');
343342
}
344343

345344
/**
346345
* Get the language breakdown of a repository
347-
* http://develop.github.com/p/repo.html
346+
* @link http://developer.github.com/v3/repos/
348347
*
349348
* @param string $username the user who owns the repo
350349
* @param string $repo the name of the repo
351350
* @return array list of the languages
352351
*/
353352
public function getRepoLanguages($username, $repo)
354353
{
355-
$response = $this->get('repos/show/'.urlencode($username).'/'.urlencode($repo).'/languages');
356-
357-
return $response['languages'];
354+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/languages');
358355
}
359356

360357
/**
361358
* Get the contributors of a repository
362-
* http://develop.github.com/p/repo.html
359+
* @link http://developer.github.com/v3/repos/
363360
*
364361
* @param string $username the user who owns the repo
365362
* @param string $repo the name of the repo
366-
* @param boolean $includingNonGithubUsers by default, the list only shows GitHub users. You can include non-users too by setting this to true
363+
* @param boolean $includingAnonymous by default, the list only shows GitHub users. You can include non-users too by setting this to true
367364
* @return array list of the repo contributors
368365
*/
369-
public function getRepoContributors($username, $repo, $includingNonGithubUsers = false)
366+
public function getRepoContributors($username, $repo, $includingAnonymous = false)
370367
{
371368
$url = 'repos/'.urlencode($username).'/'.urlencode($repo).'/contributors';
372-
if ($includingNonGithubUsers) {
369+
if ($includingAnonymous) {
373370
$url .= '?anon=1';
374371
}
375-
$response = $this->get($url);
376372

377-
return $response;
373+
return $this->get($url);
378374
}
379375

376+
/**
377+
* Get the teams of a repository
378+
* @link http://developer.github.com/v3/repos/
379+
*
380+
* @param string $username the user who owns the repo
381+
* @param string $repo the name of the repo
382+
* @return array list of the languages
383+
*/
384+
public function getRepoTeams($username, $repo)
385+
{
386+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repo).'/teams');
387+
}
380388
}

0 commit comments

Comments
 (0)