Skip to content

Commit b3b4db4

Browse files
violukeNyholm
authored andcommitted
Allow getting repo info by id, not just user and repo name (#579)
* Get repo details by id * Updating doc for showById * Adding note that this is an undocumented feature * Adding test for showById() * Stating undocumented in the docs too
1 parent 155bc01 commit b3b4db4

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

doc/repos.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,18 @@ $repos = $client->api('repo')->find('chess', array('language' => 'php', 'start_p
4444

4545
### Get extended information about a repository
4646

47+
Using the username of the repository owner and the repository name:
48+
4749
```php
4850
$repo = $client->api('repo')->show('KnpLabs', 'php-github-api')
4951
```
5052

53+
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)):
54+
55+
```php
56+
$repo = $client->api('repo')->showById(123456)
57+
```
58+
5159
Returns an array of information about the specified repository.
5260

5361
### Get the repositories of a specific user

lib/Github/Api/Repo.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,23 @@ public function show($username, $repository)
150150
{
151151
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository));
152152
}
153+
154+
/**
155+
* Get extended information about a repository by its id.
156+
* Note: at time of writing this is an undocumented feature but GitHub support have advised that it can be relied on.
157+
*
158+
* @link http://developer.github.com/v3/repos/
159+
* @link https://github.com/piotrmurach/github/issues/283
160+
* @link https://github.com/piotrmurach/github/issues/282
161+
*
162+
* @param int $id the id of the repository
163+
*
164+
* @return array information about the repository
165+
*/
166+
public function showById($id)
167+
{
168+
return $this->get('/repositories/'.rawurlencode($id));
169+
}
153170

154171
/**
155172
* Create repository.

test/Github/Tests/Api/RepoTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,22 @@ public function shouldShowRepository()
1919

2020
$this->assertEquals($expectedArray, $api->show('KnpLabs', 'php-github-api'));
2121
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function shouldShowRepositoryById()
27+
{
28+
$expectedArray = array('id' => 123456, 'name' => 'repoName');
29+
30+
$api = $this->getApiMock();
31+
$api->expects($this->once())
32+
->method('get')
33+
->with('/repositories/123456')
34+
->will($this->returnValue($expectedArray));
35+
36+
$this->assertEquals($expectedArray, $api->showById(123456));
37+
}
2238

2339
/**
2440
* @test

0 commit comments

Comments
 (0)