Skip to content

Commit d72b200

Browse files
committed
Add possibility to list repositories for authenticated user
Fix downloads API initialization for repositories Add possibility to show and create repository commit statuses
1 parent 45d4849 commit d72b200

File tree

5 files changed

+141
-62
lines changed

5 files changed

+141
-62
lines changed

lib/Github/Api/CurrentUser.php

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,18 +47,36 @@ public function follow()
4747
return new Followers($this->client);
4848
}
4949

50-
public function issues(array $params = array())
51-
{
52-
return $this->get('issues', array_merge(array('page' => 1), $params));
53-
}
54-
5550
public function followers($page = 1)
5651
{
5752
return $this->get('user/followers', array(
5853
'page' => $page
5954
));
6055
}
6156

57+
/**
58+
* @link http://developer.github.com/v3/issues/#list-issues
59+
*
60+
* @param array $params
61+
* @param boolean $includeOrgIssues
62+
*
63+
* @return array
64+
*/
65+
public function issues(array $params = array(), $includeOrgIssues = true)
66+
{
67+
return $this->get($includeOrgIssues ? 'issues' : 'user/issues', array_merge(array('page' => 1), $params));
68+
}
69+
70+
/**
71+
* @link http://developer.github.com/v3/repos/#list-your-repositories
72+
*
73+
* @return array
74+
*/
75+
public function repositories()
76+
{
77+
return $this->get('users/repos');
78+
}
79+
6280
/**
6381
* @return Watchers
6482
*/

lib/Github/Api/Repo.php

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Github\Api\Repository\Forks;
1212
use Github\Api\Repository\Hooks;
1313
use Github\Api\Repository\Labels;
14+
use Github\Api\Repository\Statuses;
1415

1516
/**
1617
* Searching repositories, getting repository information
@@ -144,6 +145,17 @@ public function contents()
144145
return new Contents($this->client);
145146
}
146147

148+
/**
149+
* Manage the content of a repository
150+
* @link http://developer.github.com/v3/repos/downloads/
151+
*
152+
* @return Downloads
153+
*/
154+
public function downloads()
155+
{
156+
return new Downloads($this->client);
157+
}
158+
147159
/**
148160
* Manage the deploy keys of a repository
149161
* @link http://developer.github.com/v3/repos/keys/
@@ -189,31 +201,14 @@ public function labels()
189201
}
190202

191203
/**
192-
* @param string $username
193-
* @param string $repository
194-
* @param integer $page
204+
* Manage the statuses of a repository
205+
* @link http://developer.github.com/v3/repos/statuses/
195206
*
196-
* @return array
207+
* @return Statuses
197208
*/
198-
public function watchers($username, $repository, $page = 1)
209+
public function statuses()
199210
{
200-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/watchers', array(
201-
'page' => $page
202-
));
203-
}
204-
205-
/**
206-
* Get the tags of a repository
207-
* @link http://developer.github.com/v3/repos/
208-
*
209-
* @param string $username the user who owns the repository
210-
* @param string $repository the name of the repository
211-
*
212-
* @return array list of the repository tags
213-
*/
214-
public function tags($username, $repository)
215-
{
216-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/tags');
211+
return new Statuses($this->client);
217212
}
218213

219214
/**
@@ -236,6 +231,23 @@ public function branches($username, $repository, $branch = null)
236231
return $this->get($url);
237232
}
238233

234+
/**
235+
* Get the contributors of a repository
236+
* @link http://developer.github.com/v3/repos/
237+
*
238+
* @param string $username the user who owns the repository
239+
* @param string $repository the name of the repository
240+
* @param boolean $includingAnonymous by default, the list only shows GitHub users.
241+
* You can include non-users too by setting this to true
242+
* @return array list of the repo contributors
243+
*/
244+
public function contributors($username, $repository, $includingAnonymous = false)
245+
{
246+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/contributors', array(
247+
'anon' => $includingAnonymous ?: null
248+
));
249+
}
250+
239251
/**
240252
* Get the language breakdown of a repository
241253
* @link http://developer.github.com/v3/repos/
@@ -251,20 +263,17 @@ public function languages($username, $repository)
251263
}
252264

253265
/**
254-
* Get the contributors of a repository
266+
* Get the tags of a repository
255267
* @link http://developer.github.com/v3/repos/
256268
*
257-
* @param string $username the user who owns the repository
258-
* @param string $repository the name of the repository
259-
* @param boolean $includingAnonymous by default, the list only shows GitHub users.
260-
* You can include non-users too by setting this to true
261-
* @return array list of the repo contributors
269+
* @param string $username the user who owns the repository
270+
* @param string $repository the name of the repository
271+
*
272+
* @return array list of the repository tags
262273
*/
263-
public function contributors($username, $repository, $includingAnonymous = false)
274+
public function tags($username, $repository)
264275
{
265-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/contributors', array(
266-
'anon' => $includingAnonymous ?: null
267-
));
276+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/tags');
268277
}
269278

270279
/**
@@ -282,16 +291,16 @@ public function teams($username, $repository)
282291
}
283292

284293
/**
285-
* Get the downloads for selected repository
286-
* @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository
287-
*
288-
* @param string $username the user who owns the repository
289-
* @param string $repository the name of the repository
294+
* @param string $username
295+
* @param string $repository
296+
* @param integer $page
290297
*
291298
* @return array
292299
*/
293-
public function downloads($username, $repository)
300+
public function watchers($username, $repository, $page = 1)
294301
{
295-
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/downloads');
302+
return $this->get('repos/'.urlencode($username).'/'.urlencode($repository).'/watchers', array(
303+
'page' => $page
304+
));
296305
}
297306
}

lib/Github/Api/Repository/Downloads.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ class Downloads extends AbstractApi
1212
{
1313
/**
1414
* List downloads in selected repository
15-
* @link http://developer.github.com/v3/repos/downloads/
15+
* @link http://developer.github.com/v3/repos/downloads/#list-downloads-for-a-repository
1616
*
1717
* @param string $username the user who owns the repo
1818
* @param string $repository the name of the repo
@@ -26,7 +26,7 @@ public function all($username, $repository)
2626

2727
/**
2828
* Get a download in selected repository
29-
* @link http://developer.github.com/v3/repos/downloads/
29+
* @link http://developer.github.com/v3/repos/downloads/#get-a-single-download
3030
*
3131
* @param string $username the user who owns the repo
3232
* @param string $repository the name of the repo
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
<?php
2+
3+
namespace Github\Api\Repository;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
/**
9+
* @link http://developer.github.com/v3/repos/statuses/
10+
* @author Joseph Bielawski <stloyd@gmail.com>
11+
*/
12+
class Statuses extends AbstractApi
13+
{
14+
/**
15+
* @link http://developer.github.com/v3/repos/statuses/#list-statuses-for-a-specific-sha
16+
*
17+
* @param string $username
18+
* @param string $repository
19+
* @param string $sha
20+
*
21+
* @return array
22+
*/
23+
public function show($username, $repository, $sha)
24+
{
25+
return $this->get('/repos/'.urlencode($username).'/'.urlencode($repository).'/statuses/'.urlencode($sha));
26+
}
27+
28+
/**
29+
* @link http://developer.github.com/v3/repos/statuses/#create-a-status
30+
*
31+
* @param string $username
32+
* @param string $repository
33+
* @param string $sha
34+
* @param array $params
35+
*
36+
* @return array
37+
*
38+
* @throws MissingArgumentException
39+
*/
40+
public function create($username, $repository, $sha, array $params = array())
41+
{
42+
if (!isset($params['state'])) {
43+
throw new MissingArgumentException('state');
44+
}
45+
46+
return $this->post('repos/'.urlencode($username).'/'.urlencode($repository).'/statuses'.urlencode($sha), $params);
47+
}
48+
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -207,22 +207,6 @@ public function shouldGetRepositoryTeams()
207207
$this->assertEquals($expectedArray, $api->teams('KnpLabs', 'php-github-api'));
208208
}
209209

210-
/**
211-
* @test
212-
*/
213-
public function shouldGetRepositoryDownloads()
214-
{
215-
$expectedArray = array('down1', 'down2');
216-
217-
$api = $this->getApiMock();
218-
$api->expects($this->once())
219-
->method('get')
220-
->with('repos/KnpLabs/php-github-api/downloads')
221-
->will($this->returnValue($expectedArray));
222-
223-
$this->assertEquals($expectedArray, $api->downloads('KnpLabs', 'php-github-api'));
224-
}
225-
226210
/**
227211
* @test
228212
*/
@@ -335,6 +319,16 @@ public function shouldGetDeployKeysApiObject()
335319
$this->assertInstanceOf('Github\Api\Repository\DeployKeys', $api->keys());
336320
}
337321

322+
/**
323+
* @test
324+
*/
325+
public function shouldGetDownloadsApiObject()
326+
{
327+
$api = $this->getApiMock();
328+
329+
$this->assertInstanceOf('Github\Api\Repository\Downloads', $api->downloads());
330+
}
331+
338332
/**
339333
* @test
340334
*/
@@ -365,6 +359,16 @@ public function shouldGetLabelsApiObject()
365359
$this->assertInstanceOf('Github\Api\Repository\Labels', $api->labels());
366360
}
367361

362+
/**
363+
* @test
364+
*/
365+
public function shouldGetStatusesApiObject()
366+
{
367+
$api = $this->getApiMock();
368+
369+
$this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses());
370+
}
371+
368372
protected function getApiClass()
369373
{
370374
return 'Github\Api\Repo';

0 commit comments

Comments
 (0)