Skip to content

Commit 4f3a34d

Browse files
committed
Merge pull request #275 from KnpLabs/feature/latest-release
Latest actual release + release by tag
2 parents 5f07808 + bd6f1a5 commit 4f3a34d

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

doc/repo/releases.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33

44
This Github API Endpoint is currently undocumented because it's new, but works just fine.
55

6+
### Get latest actual release
7+
8+
```php
9+
$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap');
10+
```
11+
12+
### List releases for a tag
13+
14+
```php
15+
$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec');
16+
```
617

718
### List all releases
819

lib/Github/Api/Repository/Releases.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,33 @@
1212
*/
1313
class Releases extends AbstractApi
1414
{
15+
/**
16+
* Get the latest release.
17+
*
18+
* @param $username
19+
* @param $repository
20+
*
21+
* @return array
22+
*/
23+
public function latest($username, $repository)
24+
{
25+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest');
26+
}
27+
28+
/**
29+
* List releases for a tag.
30+
*
31+
* @param $username
32+
* @param $repository
33+
* @param $tag
34+
*
35+
* @return array
36+
*/
37+
public function tag($username, $repository, $tag)
38+
{
39+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag));
40+
}
41+
1542
/**
1643
* List releases in selected repository.
1744
*

test/Github/Tests/Api/Repository/ReleasesTest.php

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,42 @@
66

77
class ReleasesTest extends TestCase
88
{
9+
/**
10+
* @test
11+
*/
12+
public function shouldGetLatestRelease()
13+
{
14+
$expectedValue = array('latest_release_data');
15+
16+
$api = $this->getApiMock();
17+
$api->expects($this->once())
18+
->method('get')
19+
->with('repos/KnpLabs/php-github-api/releases/latest')
20+
->will($this->returnValue($expectedValue));
21+
22+
$this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api'));
23+
}
24+
25+
/**
26+
* @test
27+
*/
28+
public function shouldGetReleaseByTag()
29+
{
30+
$expectedValue = array('latest_release_data');
31+
32+
$api = $this->getApiMock();
33+
$api->expects($this->once())
34+
->method('get')
35+
->with('repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8')
36+
->will($this->returnValue($expectedValue));
37+
38+
$this->assertEquals($expectedValue, $api->tag(
39+
'KnpLabs',
40+
'php-github-api',
41+
'5f078080e01e0365690920d618f12342d2c941c8'
42+
));
43+
}
44+
945
/**
1046
* @test
1147
*/

0 commit comments

Comments
 (0)