From d6a23e3d406abae67bcbb324709d7c7b3885f8f1 Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Sat, 6 May 2017 16:51:27 +0100 Subject: [PATCH 1/5] Get repo details by id --- lib/Github/Api/Repo.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index b730158d67e..fa619ca5c6b 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -150,6 +150,20 @@ public function show($username, $repository) { return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository)); } + + /** + * Get extended information about a repository by its id. + * + * @link http://developer.github.com/v3/repos/ + * + * @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. From b968895066e8fb8c2ec22c4c4dfe7c324f3a9689 Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Sat, 6 May 2017 16:53:20 +0100 Subject: [PATCH 2/5] Updating doc for showById --- doc/repos.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/doc/repos.md b/doc/repos.md index 55ebe1326cd..9a287bbe6d0 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -48,6 +48,12 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_p $repo = $client->api('repo')->show('KnpLabs', 'php-github-api') ``` +or + +```php +$repo = $client->api('repo')->showById(123456) +``` + Returns an array of information about the specified repository. ### Get the repositories of a specific user From d8501bd31d337aa147155180deae6055b6c1c943 Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Sat, 6 May 2017 17:02:21 +0100 Subject: [PATCH 3/5] Adding note that this is an undocumented feature --- lib/Github/Api/Repo.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/Github/Api/Repo.php b/lib/Github/Api/Repo.php index fa619ca5c6b..5dbe7b9444c 100644 --- a/lib/Github/Api/Repo.php +++ b/lib/Github/Api/Repo.php @@ -153,8 +153,11 @@ public function show($username, $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 * From 2b328e246460fc8f337c9d61f89be3d2d72efdaa Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Sat, 6 May 2017 17:10:14 +0100 Subject: [PATCH 4/5] Adding test for showById() --- test/Github/Tests/Api/RepoTest.php | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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 From 43479597e3e6e02930f6dbc9af6096be3421b34c Mon Sep 17 00:00:00 2001 From: Luke Cousins Date: Sat, 6 May 2017 17:24:44 +0100 Subject: [PATCH 5/5] Stating undocumented in the docs too --- doc/repos.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/doc/repos.md b/doc/repos.md index 9a287bbe6d0..7c7d83be5c5 100644 --- a/doc/repos.md +++ b/doc/repos.md @@ -44,11 +44,13 @@ $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 +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)