diff --git a/doc/repos.md b/doc/repos.md index 55ebe1326cd..7c7d83be5c5 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -44,10 +44,18 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_p ### Get extended information about a repository +Using the username of the repository owner and the repository name: + ```php $repo = $client->api('repo')->show('KnpLabs', 'php-github-api') ``` +Or by using the repository id (note that this is at time of writing an undocumented feature, see [here](https://github.com/piotrmurach/github/issues/283) and [here](https://github.com/piotrmurach/github/issues/282)): + +```php +$repo = $client->api('repo')->showById(123456) +``` + Returns an array of information about the specified repository. ### Get the repositories of a specific user diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b730158d67e..5dbe7b9444c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -150,6 +150,23 @@ public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } + + /** + * Get extended information about a repository by its id. + * Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on. + * + * @link http://developer.github.com/v3/repos/ + * @link https://github.com/piotrmurach/github/issues/283 + * @link https://github.com/piotrmurach/github/issues/282 + * + * @param int $id the id of the repository + * + * @return array information about the repository + */ + public function showById($id) + { + return $this->get('/repositories/'.rawurlencode($id)); + } /** * Create repository. diff --git a/test/Github/Tests/Api/RepoTest.php b/test/Github/Tests/Api/RepoTest.php index cc2e9c8e52c..beb68c415d3 100644 --- a/test/Github/Tests/Api/RepoTest.php +++ b/test/Github/Tests/Api/RepoTest.php @@ -19,6 +19,22 @@ public function shouldShowRepository() $this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api')); } + + /** + * @test + */ + public function shouldShowRepositoryById() + { + $expectedArray = array('id' => 123456, 'name' => 'repoName'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repositories/123456') + ->will($this->returnValue($expectedArray)); + + $this->assertEquals($expectedArray, $api->showById(123456)); + } /** * @test