From 02d317c9b22ac77b3200528431939fce5a803b4f Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 28 Dec 2016 11:38:05 -0500 Subject: [PATCH 1/6] allow fetching prerelease data --- doc/repo/releases.md | 98 ++--- lib/Github/Api/Repository/Releases.php | 265 +++++++------- .../Tests/Api/Repository/ReleasesTest.php | 340 +++++++++--------- 3 files changed, 369 insertions(+), 334 deletions(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 31f5fa5e10d..a0370fad923 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -1,46 +1,52 @@ -## Repo / Releases API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) - -Provides information about releases for a repository. Wraps [GitHub Releases API](https://developer.github.com/v3/repos/releases/). - -### Get latest actual release - -```php -$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); -``` - -### List releases for a tag - -```php -$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); -``` - -### List all releases - -```php -$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); -``` - -### List one release - -```php -$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); -``` - -### Create a release -```php -$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1')); -``` - -### Edit a release -```php -$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name')); -``` - -### Remove a release - -This works, but isn't thoroughly tested, use at your own risk. - -```php -$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id); -``` +## Repo / Releases API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +Provides information about releases for a repository. Wraps [GitHub Releases API](https://developer.github.com/v3/repos/releases/). + +### Get latest actual release + +```php +$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); +``` + +### Get latest release (including prereleases) + +```php +$release = $client->api('repo')->releases()->latestIncludingPrereleases('twbs', 'bootstrap'); +``` + +### List releases for a tag + +```php +$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); +``` + +### List all releases + +```php +$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); +``` + +### List one release + +```php +$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); +``` + +### Create a release +```php +$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1')); +``` + +### Edit a release +```php +$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name')); +``` + +### Remove a release + +This works, but isn't thoroughly tested, use at your own risk. + +```php +$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id); +``` diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 4d59318fe07..495e0447220 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -1,126 +1,139 @@ - - * @author Evgeniy Guseletov - */ -class Releases extends AbstractApi -{ - /** - * Get the latest release. - * - * @param $username - * @param $repository - * - * @return array - */ - public function latest($username, $repository) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); - } - - /** - * List releases for a tag. - * - * @param $username - * @param $repository - * @param $tag - * - * @return array - */ - public function tag($username, $repository, $tag) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); - } - - /** - * List releases in selected repository. - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * - * @return array - */ - public function all($username, $repository, array $params = []) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); - } - - /** - * Get a release in selected repository. - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param int $id the id of the release - * - * @return array - */ - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); - } - - /** - * Create new release in selected repository. - * - * @param string $username - * @param string $repository - * @param array $params - * - * @throws MissingArgumentException - * - * @return array - */ - public function create($username, $repository, array $params) - { - if (!isset($params['tag_name'])) { - throw new MissingArgumentException('tag_name'); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); - } - - /** - * Edit release in selected repository. - * - * @param string $username - * @param string $repository - * @param int $id - * @param array $params - * - * @return array - */ - public function edit($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); - } - - /** - * Delete a release in selected repository (Not thoroughly tested!). - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param int $id the id of the release - * - * @return array - */ - public function remove($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); - } - - /** - * @return Assets - */ - public function assets() - { - return new Assets($this->client); - } -} + + * @author Evgeniy Guseletov + */ +class Releases extends AbstractApi +{ + /** + * Get the latest release. + * + * @param $username + * @param $repository + * + * @return array + */ + public function latest($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); + } + + /** + * Get the latest release including prereleases. + * + * @param $username + * @param $repository + * + * @return array + */ + public function latestIncludingPrereleases($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases')[0]; + } + + /** + * List releases for a tag. + * + * @param $username + * @param $repository + * @param $tag + * + * @return array + */ + public function tag($username, $repository, $tag) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); + } + + /** + * List releases in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * + * @return array + */ + public function all($username, $repository, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + } + + /** + * Get a release in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release + * + * @return array + */ + public function show($username, $repository, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * Create new release in selected repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @throws MissingArgumentException + * + * @return array + */ + public function create($username, $repository, array $params) + { + if (!isset($params['tag_name'])) { + throw new MissingArgumentException('tag_name'); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + } + + /** + * Edit release in selected repository. + * + * @param string $username + * @param string $repository + * @param int $id + * @param array $params + * + * @return array + */ + public function edit($username, $repository, $id, array $params) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); + } + + /** + * Delete a release in selected repository (Not thoroughly tested!). + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release + * + * @return array + */ + public function remove($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * @return Assets + */ + public function assets() + { + return new Assets($this->client); + } +} diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 64b164cb237..4174478a350 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -1,162 +1,178 @@ -getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/latest') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); - } - - /** - * @test - */ - public function shouldGetReleaseByTag() - { - $expectedValue = array('latest_release_data'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->tag( - 'KnpLabs', - 'php-github-api', - '5f078080e01e0365690920d618f12342d2c941c8' - )); - } - - /** - * @test - */ - public function shouldGetAllRepositoryReleases() - { - $expectedValue = array(array('release1data'), array('release2data')); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); - } - - /** - * @test - */ - public function shouldGetSingleRepositoryRelease() - { - $expectedValue = array('releaseData'); - $id = 331; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); - } - - /** - * @test - */ - public function shouldCreateRepositoryRelease() - { - $expectedValue = array('newReleaseData'); - $data = array('tag_name' => '1.1'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); - } - - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotCreateRepositoryReleaseWithoutTagName() - { - $data = array('not_a_tag_name' => '1.1'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); - - $api->create('KnpLabs', 'php-github-api', $data); - } - - /** - * @test - */ - public function shouldEditRepositoryRelease() - { - $expectedValue = array('updatedData'); - $id = 332; - $data = array('some' => 'thing'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); - } - - /** - * @test - */ - public function shouldRemoveRepositoryRelease() - { - $expectedValue = array('deleted'); - $id = 333; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); - } - - /** - * @test - */ - public function shouldGetAssetsApiObject() - { - $api = $this->getApiMock(); - - $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \Github\Api\Repository\Releases::class; - } -} +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/latest') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetLatestReleaseIncludingPrerelease() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetReleaseByTag() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->tag( + 'KnpLabs', + 'php-github-api', + '5f078080e01e0365690920d618f12342d2c941c8' + )); + } + + /** + * @test + */ + public function shouldGetAllRepositoryReleases() + { + $expectedValue = array(array('release1data'), array('release2data')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSingleRepositoryRelease() + { + $expectedValue = array('releaseData'); + $id = 331; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldCreateRepositoryRelease() + { + $expectedValue = array('newReleaseData'); + $data = array('tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateRepositoryReleaseWithoutTagName() + { + $data = array('not_a_tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', $data); + } + + /** + * @test + */ + public function shouldEditRepositoryRelease() + { + $expectedValue = array('updatedData'); + $id = 332; + $data = array('some' => 'thing'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); + } + + /** + * @test + */ + public function shouldRemoveRepositoryRelease() + { + $expectedValue = array('deleted'); + $id = 333; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldGetAssetsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Repository\Releases::class; + } +} From 81470c503c5a8a82575ffff75ad5cdcc33a92718 Mon Sep 17 00:00:00 2001 From: Charles Date: Wed, 28 Dec 2016 11:59:07 -0500 Subject: [PATCH 2/6] fix line endings --- doc/repo/releases.md | 104 ++--- lib/Github/Api/Repository/Releases.php | 278 +++++++------- .../Tests/Api/Repository/ReleasesTest.php | 356 +++++++++--------- 3 files changed, 369 insertions(+), 369 deletions(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index a0370fad923..e759526077d 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -1,52 +1,52 @@ -## Repo / Releases API -[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) - -Provides information about releases for a repository. Wraps [GitHub Releases API](https://developer.github.com/v3/repos/releases/). - -### Get latest actual release - -```php -$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); -``` - -### Get latest release (including prereleases) - -```php -$release = $client->api('repo')->releases()->latestIncludingPrereleases('twbs', 'bootstrap'); -``` - -### List releases for a tag - -```php -$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); -``` - -### List all releases - -```php -$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); -``` - -### List one release - -```php -$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); -``` - -### Create a release -```php -$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1')); -``` - -### Edit a release -```php -$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name')); -``` - -### Remove a release - -This works, but isn't thoroughly tested, use at your own risk. - -```php -$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id); -``` +## Repo / Releases API +[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md) + +Provides information about releases for a repository. Wraps [GitHub Releases API](https://developer.github.com/v3/repos/releases/). + +### Get latest actual release + +```php +$release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); +``` + +### Get latest release (including prereleases) + +```php +$release = $client->api('repo')->releases()->latestIncludingPrereleases('twbs', 'bootstrap'); +``` + +### List releases for a tag + +```php +$release = $client->api('repo')->releases()->all('twbs', 'bootstrap', 'd890eec'); +``` + +### List all releases + +```php +$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap'); +``` + +### List one release + +```php +$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id); +``` + +### Create a release +```php +$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1')); +``` + +### Edit a release +```php +$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name')); +``` + +### Remove a release + +This works, but isn't thoroughly tested, use at your own risk. + +```php +$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id); +``` diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index 495e0447220..e57bb831d0d 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -1,139 +1,139 @@ - - * @author Evgeniy Guseletov - */ -class Releases extends AbstractApi -{ - /** - * Get the latest release. - * - * @param $username - * @param $repository - * - * @return array - */ - public function latest($username, $repository) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); - } - - /** - * Get the latest release including prereleases. - * - * @param $username - * @param $repository - * - * @return array - */ - public function latestIncludingPrereleases($username, $repository) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases')[0]; - } - - /** - * List releases for a tag. - * - * @param $username - * @param $repository - * @param $tag - * - * @return array - */ - public function tag($username, $repository, $tag) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); - } - - /** - * List releases in selected repository. - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param array $params the additional parameters like milestone, assignees, labels, sort, direction - * - * @return array - */ - public function all($username, $repository, array $params = []) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); - } - - /** - * Get a release in selected repository. - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param int $id the id of the release - * - * @return array - */ - public function show($username, $repository, $id) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); - } - - /** - * Create new release in selected repository. - * - * @param string $username - * @param string $repository - * @param array $params - * - * @throws MissingArgumentException - * - * @return array - */ - public function create($username, $repository, array $params) - { - if (!isset($params['tag_name'])) { - throw new MissingArgumentException('tag_name'); - } - - return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); - } - - /** - * Edit release in selected repository. - * - * @param string $username - * @param string $repository - * @param int $id - * @param array $params - * - * @return array - */ - public function edit($username, $repository, $id, array $params) - { - return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); - } - - /** - * Delete a release in selected repository (Not thoroughly tested!). - * - * @param string $username the user who owns the repo - * @param string $repository the name of the repo - * @param int $id the id of the release - * - * @return array - */ - public function remove($username, $repository, $id) - { - return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); - } - - /** - * @return Assets - */ - public function assets() - { - return new Assets($this->client); - } -} + + * @author Evgeniy Guseletov + */ +class Releases extends AbstractApi +{ + /** + * Get the latest release. + * + * @param $username + * @param $repository + * + * @return array + */ + public function latest($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); + } + + /** + * Get the latest release including prereleases. + * + * @param $username + * @param $repository + * + * @return array + */ + public function latestIncludingPrereleases($username, $repository) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases')[0]; + } + + /** + * List releases for a tag. + * + * @param $username + * @param $repository + * @param $tag + * + * @return array + */ + public function tag($username, $repository, $tag) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/tags/'.rawurlencode($tag)); + } + + /** + * List releases in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param array $params the additional parameters like milestone, assignees, labels, sort, direction + * + * @return array + */ + public function all($username, $repository, array $params = []) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + } + + /** + * Get a release in selected repository. + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release + * + * @return array + */ + public function show($username, $repository, $id) + { + return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * Create new release in selected repository. + * + * @param string $username + * @param string $repository + * @param array $params + * + * @throws MissingArgumentException + * + * @return array + */ + public function create($username, $repository, array $params) + { + if (!isset($params['tag_name'])) { + throw new MissingArgumentException('tag_name'); + } + + return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params); + } + + /** + * Edit release in selected repository. + * + * @param string $username + * @param string $repository + * @param int $id + * @param array $params + * + * @return array + */ + public function edit($username, $repository, $id, array $params) + { + return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params); + } + + /** + * Delete a release in selected repository (Not thoroughly tested!). + * + * @param string $username the user who owns the repo + * @param string $repository the name of the repo + * @param int $id the id of the release + * + * @return array + */ + public function remove($username, $repository, $id) + { + return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id)); + } + + /** + * @return Assets + */ + public function assets() + { + return new Assets($this->client); + } +} diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 4174478a350..4cd74f4384a 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -1,178 +1,178 @@ -getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/latest') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); - } - - /** - * @test - */ - public function shouldGetLatestReleaseIncludingPrerelease() - { - $expectedValue = array('latest_release_data'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); - } - - /** - * @test - */ - public function shouldGetReleaseByTag() - { - $expectedValue = array('latest_release_data'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->tag( - 'KnpLabs', - 'php-github-api', - '5f078080e01e0365690920d618f12342d2c941c8' - )); - } - - /** - * @test - */ - public function shouldGetAllRepositoryReleases() - { - $expectedValue = array(array('release1data'), array('release2data')); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); - } - - /** - * @test - */ - public function shouldGetSingleRepositoryRelease() - { - $expectedValue = array('releaseData'); - $id = 331; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); - } - - /** - * @test - */ - public function shouldCreateRepositoryRelease() - { - $expectedValue = array('newReleaseData'); - $data = array('tag_name' => '1.1'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('post') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); - } - - /** - * @test - * @expectedException \Github\Exception\MissingArgumentException - */ - public function shouldNotCreateRepositoryReleaseWithoutTagName() - { - $data = array('not_a_tag_name' => '1.1'); - - $api = $this->getApiMock(); - $api->expects($this->never()) - ->method('post'); - - $api->create('KnpLabs', 'php-github-api', $data); - } - - /** - * @test - */ - public function shouldEditRepositoryRelease() - { - $expectedValue = array('updatedData'); - $id = 332; - $data = array('some' => 'thing'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('patch') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); - } - - /** - * @test - */ - public function shouldRemoveRepositoryRelease() - { - $expectedValue = array('deleted'); - $id = 333; - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('delete') - ->with('/repos/KnpLabs/php-github-api/releases/'.$id) - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); - } - - /** - * @test - */ - public function shouldGetAssetsApiObject() - { - $api = $this->getApiMock(); - - $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); - } - - /** - * @return string - */ - protected function getApiClass() - { - return \Github\Api\Repository\Releases::class; - } -} +getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/latest') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetLatestReleaseIncludingPrerelease() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetReleaseByTag() + { + $expectedValue = array('latest_release_data'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/tags/5f078080e01e0365690920d618f12342d2c941c8') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->tag( + 'KnpLabs', + 'php-github-api', + '5f078080e01e0365690920d618f12342d2c941c8' + )); + } + + /** + * @test + */ + public function shouldGetAllRepositoryReleases() + { + $expectedValue = array(array('release1data'), array('release2data')); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->all('KnpLabs', 'php-github-api')); + } + + /** + * @test + */ + public function shouldGetSingleRepositoryRelease() + { + $expectedValue = array('releaseData'); + $id = 331; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldCreateRepositoryRelease() + { + $expectedValue = array('newReleaseData'); + $data = array('tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('/repos/KnpLabs/php-github-api/releases') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); + } + + /** + * @test + * @expectedException \Github\Exception\MissingArgumentException + */ + public function shouldNotCreateRepositoryReleaseWithoutTagName() + { + $data = array('not_a_tag_name' => '1.1'); + + $api = $this->getApiMock(); + $api->expects($this->never()) + ->method('post'); + + $api->create('KnpLabs', 'php-github-api', $data); + } + + /** + * @test + */ + public function shouldEditRepositoryRelease() + { + $expectedValue = array('updatedData'); + $id = 332; + $data = array('some' => 'thing'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->edit('KnpLabs', 'php-github-api', $id, $data)); + } + + /** + * @test + */ + public function shouldRemoveRepositoryRelease() + { + $expectedValue = array('deleted'); + $id = 333; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/KnpLabs/php-github-api/releases/'.$id) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->remove('KnpLabs', 'php-github-api', $id)); + } + + /** + * @test + */ + public function shouldGetAssetsApiObject() + { + $api = $this->getApiMock(); + + $this->assertInstanceOf('Github\Api\Repository\Assets', $api->assets()); + } + + /** + * @return string + */ + protected function getApiClass() + { + return \Github\Api\Repository\Releases::class; + } +} From 49627289fbf6a0a8acc83e80319a0d5ca75fca96 Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 29 Dec 2016 10:55:48 -0500 Subject: [PATCH 3/6] use 0th element for test --- test/Github/Tests/Api/Repository/ReleasesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index 4cd74f4384a..b516dbda088 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -35,7 +35,7 @@ public function shouldGetLatestReleaseIncludingPrerelease() ->with('/repos/KnpLabs/php-github-api/releases') ->will($this->returnValue($expectedValue)); - $this->assertEquals($expectedValue, $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); + $this->assertEquals($expectedValue[0], $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); } /** From 33f78ffb14123fb4a8f8184d623839f665c72acf Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 29 Dec 2016 16:05:44 -0500 Subject: [PATCH 4/6] only update documentation --- doc/repo/releases.md | 8 ++++---- lib/Github/Api/Repository/Releases.php | 13 ------------- .../Github/Tests/Api/Repository/ReleasesTest.php | 16 ---------------- 3 files changed, 4 insertions(+), 33 deletions(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index e759526077d..81f8c22ff04 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -9,12 +9,12 @@ Provides information about releases for a repository. Wraps [GitHub Releases API $release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); ``` -### Get latest release (including prereleases) +The ```latest()``` method fetches only releases which are not marked "prerelease." -```php -$release = $client->api('repo')->releases()->latestIncludingPrereleases('twbs', 'bootstrap'); +To obtain the latest release *including prereleases*, select the first element in the "all releases" function: +``` +$release = $client->api('repo')->releases()->all('username', 'repo')[0]; ``` - ### List releases for a tag ```php diff --git a/lib/Github/Api/Repository/Releases.php b/lib/Github/Api/Repository/Releases.php index e57bb831d0d..4d59318fe07 100644 --- a/lib/Github/Api/Repository/Releases.php +++ b/lib/Github/Api/Repository/Releases.php @@ -25,19 +25,6 @@ public function latest($username, $repository) return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/latest'); } - /** - * Get the latest release including prereleases. - * - * @param $username - * @param $repository - * - * @return array - */ - public function latestIncludingPrereleases($username, $repository) - { - return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases')[0]; - } - /** * List releases for a tag. * diff --git a/test/Github/Tests/Api/Repository/ReleasesTest.php b/test/Github/Tests/Api/Repository/ReleasesTest.php index b516dbda088..64b164cb237 100644 --- a/test/Github/Tests/Api/Repository/ReleasesTest.php +++ b/test/Github/Tests/Api/Repository/ReleasesTest.php @@ -22,22 +22,6 @@ public function shouldGetLatestRelease() $this->assertEquals($expectedValue, $api->latest('KnpLabs', 'php-github-api')); } - /** - * @test - */ - public function shouldGetLatestReleaseIncludingPrerelease() - { - $expectedValue = array('latest_release_data'); - - $api = $this->getApiMock(); - $api->expects($this->once()) - ->method('get') - ->with('/repos/KnpLabs/php-github-api/releases') - ->will($this->returnValue($expectedValue)); - - $this->assertEquals($expectedValue[0], $api->latestIncludingPrereleases('KnpLabs', 'php-github-api')); - } - /** * @test */ From b3fd99e70c2dbb8c16d0b8668756d12234127d2c Mon Sep 17 00:00:00 2001 From: Charles Date: Thu, 29 Dec 2016 16:43:24 -0500 Subject: [PATCH 5/6] update docs by request. add draft auth detail --- doc/repo/releases.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 81f8c22ff04..6dea6344121 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -9,12 +9,15 @@ Provides information about releases for a repository. Wraps [GitHub Releases API $release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); ``` -The ```latest()``` method fetches only releases which are not marked "prerelease." +The `latest()` method fetches only releases which are not marked "prerelease" or "draft" -To obtain the latest release *including prereleases*, select the first element in the "all releases" function: -``` +To obtain the latest release *including* prereleases and drafts, select the first element in the "all releases" function: +```php $release = $client->api('repo')->releases()->all('username', 'repo')[0]; ``` + +Note: Draft releases are only visible to authenticated users who have push access to the repository. + ### List releases for a tag ```php From cf4ef1c42179b5efd51bf0f9410fb7325e4976ff Mon Sep 17 00:00:00 2001 From: Tobias Nyholm Date: Wed, 1 Feb 2017 16:57:15 +0100 Subject: [PATCH 6/6] fixed typo --- doc/repo/releases.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/repo/releases.md b/doc/repo/releases.md index 6dea6344121..b64468a8171 100644 --- a/doc/repo/releases.md +++ b/doc/repo/releases.md @@ -9,7 +9,7 @@ Provides information about releases for a repository. Wraps [GitHub Releases API $release = $client->api('repo')->releases()->latest('twbs', 'bootstrap'); ``` -The `latest()` method fetches only releases which are not marked "prerelease" or "draft" +The `latest()` method fetches only releases which are not marked "prerelease" or "draft". To obtain the latest release *including* prereleases and drafts, select the first element in the "all releases" function: ```php