Skip to content

Repo::all method #319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 11, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions doc/repos.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@
Searching repositories, getting repository information and managing repository information for authenticated users.
Wrap [GitHub Repo API](http://developer.github.com/v3/repos/). All methods are described on that page.

### List all repositories

#### Simple call

```php
$repos = $client->api('repo')->all();
```

#### Start from a specific repository id

```php
$repos = $client->api('repo')->all(1337);
```

### Search repos by keyword

#### Simple search
Expand Down
17 changes: 17 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,23 @@ public function find($keyword, array $params = array())
return $this->get('legacy/repos/search/'.rawurlencode($keyword), array_merge(array('start_page' => 1), $params));
}

/**
* List all public repositories.
*
* @link https://developer.github.com/v3/repos/#list-all-public-repositories
*
* @param int|null $id The integer ID of the last Repository that you’ve seen.
*
* @return array list of users found
*/
public function all($id = null)
{
if (!is_int($id)) {
return $this->get('repositories');
}
return $this->get('repositories?since=' . rawurldecode($id));
}

/**
* Get the last year of commit activity for a repository grouped by week.
*
Expand Down
42 changes: 42 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,48 @@ public function shouldPaginateFoundRepositories()
$this->assertEquals($expectedArray, $api->find('php', array('start_page' => 2)));
}

/**
* @test
*/
public function shouldGetAllRepositories()
{
$expectedArray = array(
array('id' => 1, 'name' => 'dummy project'),
array('id' => 2, 'name' => 'awesome another project'),
array('id' => 3, 'name' => 'fork of php'),
array('id' => 4, 'name' => 'fork of php-cs'),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('repositories')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->all());
}

/**
* @test
*/
public function shouldGetAllRepositoriesStartingIndex()
{
$expectedArray = array(
array('id' => 1, 'name' => 'dummy project'),
array('id' => 2, 'name' => 'awesome another project'),
array('id' => 3, 'name' => 'fork of php'),
array('id' => 4, 'name' => 'fork of php-cs'),
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('repositories?since=2')
->will($this->returnValue($expectedArray));

$this->assertEquals($expectedArray, $api->all(2));
}

/**
* @test
*/
Expand Down