Skip to content

Commit 7b50381

Browse files
committed
Merge pull request #319 from Soullivaneuh/repo-all
Repo::all method
2 parents 9ffaf25 + 130f962 commit 7b50381

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

doc/repos.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,20 @@
44
Searching repositories, getting repository information and managing repository information for authenticated users.
55
Wrap [GitHub Repo API](http://developer.github.com/v3/repos/). All methods are described on that page.
66

7+
### List all repositories
8+
9+
#### Simple call
10+
11+
```php
12+
$repos = $client->api('repo')->all();
13+
```
14+
15+
#### Start from a specific repository id
16+
17+
```php
18+
$repos = $client->api('repo')->all(1337);
19+
```
20+
721
### Search repos by keyword
822

923
#### Simple search

lib/Github/Api/Repo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,23 @@ public function find($keyword, array $params = array())
3939
return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params));
4040
}
4141

42+
/**
43+
* List all public repositories.
44+
*
45+
* @link https://developer.github.com/v3/repos/#list-all-public-repositories
46+
*
47+
* @param int|null $id The integer ID of the last Repository that you’ve seen.
48+
*
49+
* @return array list of users found
50+
*/
51+
public function all($id = null)
52+
{
53+
if (!is_int($id)) {
54+
return $this->get('repositories');
55+
}
56+
return $this->get('repositories?since=' . rawurldecode($id));
57+
}
58+
4259
/**
4360
* Get the last year of commit activity for a repository grouped by week.
4461
*

test/Github/Tests/Api/RepoTest.php

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,48 @@ public function shouldPaginateFoundRepositories()
5858
$this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2)));
5959
}
6060

61+
/**
62+
* @test
63+
*/
64+
public function shouldGetAllRepositories()
65+
{
66+
$expectedArray = array(
67+
array('id' => 1, 'name' => 'dummy project'),
68+
array('id' => 2, 'name' => 'awesome another project'),
69+
array('id' => 3, 'name' => 'fork of php'),
70+
array('id' => 4, 'name' => 'fork of php-cs'),
71+
);
72+
73+
$api = $this->getApiMock();
74+
$api->expects($this->once())
75+
->method('get')
76+
->with('repositories')
77+
->will($this->returnValue($expectedArray));
78+
79+
$this->assertEquals($expectedArray, $api->all());
80+
}
81+
82+
/**
83+
* @test
84+
*/
85+
public function shouldGetAllRepositoriesStartingIndex()
86+
{
87+
$expectedArray = array(
88+
array('id' => 1, 'name' => 'dummy project'),
89+
array('id' => 2, 'name' => 'awesome another project'),
90+
array('id' => 3, 'name' => 'fork of php'),
91+
array('id' => 4, 'name' => 'fork of php-cs'),
92+
);
93+
94+
$api = $this->getApiMock();
95+
$api->expects($this->once())
96+
->method('get')
97+
->with('repositories?since=2')
98+
->will($this->returnValue($expectedArray));
99+
100+
$this->assertEquals($expectedArray, $api->all(2));
101+
}
102+
61103
/**
62104
* @test
63105
*/

0 commit comments

Comments
 (0)