Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
"ext-curl": "*",
"kriswallsmith/buzz": ">=0.7"
},
"require-dev": {
"phpunit/phpunit": ">=3.6.0"
},
"autoload": {
"psr-0": { "Github\\": "lib/" }
},
Expand Down
2 changes: 2 additions & 0 deletions doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ APIs:
* [Pull Requests](pull_requests.md)
* [Comments](pull_request/comments.md)
* [Repositories](repos.md)
* [Releases](repo/releases.md)
* [Assets](repo/assets.md)
* [Users](users.md)

Additional features:
Expand Down
30 changes: 30 additions & 0 deletions doc/repo/assets.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
## Repo / Releases API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md)

### List all assets by release

```php
$assets = $client->api('repo')->releases()->assets()->all('twbs', 'bootstrap', $releaseId);
```

### List one asset

```php
$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId);
```

### Create an asset

This feature is not implemented because require usage of `uploads.github.com` subdomain.

### Edit an asset

```php
$asset = $client->api('repo')->releases()->assets()->edit('twbs', 'bootstrap', $assetId, array('name' => 'New name'));
```

### Remove an asset

```php
$asset = $client->api('repo')->releases()->assets()->remove('twbs', 'bootstrap', $assetId);
```
35 changes: 35 additions & 0 deletions doc/repo/releases.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
## Repo / Releases API
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md)

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


### 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);
```
12 changes: 12 additions & 0 deletions lib/Github/Api/Repo.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Github\Api\Repository\Contents;
use Github\Api\Repository\DeployKeys;
use Github\Api\Repository\Downloads;
use Github\Api\Repository\Releases;
use Github\Api\Repository\Forks;
use Github\Api\Repository\Hooks;
use Github\Api\Repository\Labels;
Expand Down Expand Up @@ -198,6 +199,17 @@ public function downloads()
return new Downloads($this->client);
}

/**
* Manage the releases of a repository (Currently Undocumented)
* @link http://developer.github.com/v3/repos/
*
* @return Releases
*/
public function releases()
{
return new Releases($this->client);
}

/**
* Manage the deploy keys of a repository
* @link http://developer.github.com/v3/repos/keys/
Expand Down
90 changes: 90 additions & 0 deletions lib/Github/Api/Repository/Assets.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;

/**
* @link http://developer.github.com/v3/repos/releases/
* @author Evgeniy Guseletov <[email protected]>
*/
class Assets extends AbstractApi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add application/vnd.github.manifold-preview header with configure

{
/**
* @deprecated Will be removed as soon as gh releases api gets stable
*/
public function configure()
{
$this->client->setHeaders(array(
'Accept: application/vnd.github.manifold-preview'
));
}

/**
* Get all release's assets in selected repository
* GET /repos/:owner/:repo/releases/:id/assets
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param integer $id the id of the release
*
* @return array
*/
public function all($username, $repository, $id)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets');
}

/**
* Get an asset in selected repository's release
* GET /repos/:owner/:repo/releases/assets/:id
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param integer $id the id of the asset
*
* @return array
*/
public function show($username, $repository, $id)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}

/**
* Edit an asset in selected repository's release
* PATCH /repos/:owner/:repo/releases/assets/:id
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param integer $id the id of the asset
* @param array $params request parameters
*
* @throws MissingArgumentException
*
* @return array
*/
public function edit($username, $repository, $id, array $params)
{
if (!isset($params['name'])) {
throw new MissingArgumentException('name');
}

return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params);
}

/**
* Delete an asset in selected repository's release
* DELETE /repos/:owner/:repo/releases/assets/:id
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param integer $id the id of the asset
*
* @return array
*/
public function remove($username, $repository, $id)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
}
}
108 changes: 108 additions & 0 deletions lib/Github/Api/Repository/Releases.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?php

namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Exception\MissingArgumentException;

/**
* @link http://developer.github.com/v3/repos/releases/
* @author Matthew Simo <[email protected]>
* @author Evgeniy Guseletov <[email protected]>
*/
class Releases extends AbstractApi
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add application/vnd.github.manifold-preview header with configure

{
/**
* @deprecated Will be removed as soon as gh releases api gets stable
*/
public function configure()
{
$this->client->setHeaders(array(
'Accept: application/vnd.github.manifold-preview'
));
}

/**
* List releases in selected repository
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
*
* @return array
*/
public function all($username, $repository)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases');
}

/**
* Get a release in selected repository
*
* @param string $username the user who owns the repo
* @param string $repository the name of the repo
* @param integer $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 integer $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 integer $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);
}
}
10 changes: 10 additions & 0 deletions test/Github/Tests/Api/RepoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -407,6 +407,16 @@ public function shouldGetStatusesApiObject()
$this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses());
}

/**
* @test
*/
public function shouldGetReleasesApiObject()
{
$api = $this->getApiMock();

$this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases());
}

protected function getApiClass()
{
return 'Github\Api\Repo';
Expand Down
Loading