Skip to content

Commit c740117

Browse files
author
Evgeniy Guseletov
committed
Merge pull request #79 from KnpLabs/feature/releases-assets
Releases and assets
2 parents 682b8ce + 111ac77 commit c740117

File tree

10 files changed

+511
-0
lines changed

10 files changed

+511
-0
lines changed

composer.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121
"ext-curl": "*",
2222
"kriswallsmith/buzz": ">=0.7"
2323
},
24+
"require-dev": {
25+
"phpunit/phpunit": ">=3.6.0"
26+
},
2427
"autoload": {
2528
"psr-0": { "Github\\": "lib/" }
2629
},

doc/index.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ APIs:
1414
* [Pull Requests](pull_requests.md)
1515
* [Comments](pull_request/comments.md)
1616
* [Repositories](repos.md)
17+
* [Releases](repo/releases.md)
18+
* [Assets](repo/assets.md)
1719
* [Users](users.md)
1820

1921
Additional features:

doc/repo/assets.md

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
## Repo / Releases API
2+
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md)
3+
4+
### List all assets by release
5+
6+
```php
7+
$assets = $client->api('repo')->releases()->assets()->all('twbs', 'bootstrap', $releaseId);
8+
```
9+
10+
### List one asset
11+
12+
```php
13+
$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId);
14+
```
15+
16+
### Create an asset
17+
18+
This feature is not implemented because require usage of `uploads.github.com` subdomain.
19+
20+
### Edit an asset
21+
22+
```php
23+
$asset = $client->api('repo')->releases()->assets()->edit('twbs', 'bootstrap', $assetId, array('name' => 'New name'));
24+
```
25+
26+
### Remove an asset
27+
28+
```php
29+
$asset = $client->api('repo')->releases()->assets()->remove('twbs', 'bootstrap', $assetId);
30+
```

doc/repo/releases.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
## Repo / Releases API
2+
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../index.md)
3+
4+
This Github API Endpoint is currently undocumented because it's new, but works just fine.
5+
6+
7+
### List all releases
8+
9+
```php
10+
$releases = $client->api('repo')->releases()->all('twbs', 'bootstrap');
11+
```
12+
13+
### List one release
14+
15+
```php
16+
$release = $client->api('repo')->releases()->show('twbs', 'bootstrap', $id);
17+
```
18+
19+
### Create a release
20+
```php
21+
$release = $client->api('repo')->releases()->create('twbs', 'bootstrap', array('tag_name' => 'v1.1'));
22+
```
23+
24+
### Edit a release
25+
```php
26+
$release = $client->api('repo')->releases()->edit('twbs', 'bootstrap', $id, array('name' => 'New release name'));
27+
```
28+
29+
### Remove a release
30+
31+
This works, but isn't thoroughly tested, use at your own risk.
32+
33+
```php
34+
$response = $client->api('repo')->releases()->remove('twbs', 'bootstrap', $id);
35+
```

lib/Github/Api/Repo.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use Github\Api\Repository\Contents;
99
use Github\Api\Repository\DeployKeys;
1010
use Github\Api\Repository\Downloads;
11+
use Github\Api\Repository\Releases;
1112
use Github\Api\Repository\Forks;
1213
use Github\Api\Repository\Hooks;
1314
use Github\Api\Repository\Labels;
@@ -198,6 +199,17 @@ public function downloads()
198199
return new Downloads($this->client);
199200
}
200201

202+
/**
203+
* Manage the releases of a repository (Currently Undocumented)
204+
* @link http://developer.github.com/v3/repos/
205+
*
206+
* @return Releases
207+
*/
208+
public function releases()
209+
{
210+
return new Releases($this->client);
211+
}
212+
201213
/**
202214
* Manage the deploy keys of a repository
203215
* @link http://developer.github.com/v3/repos/keys/

lib/Github/Api/Repository/Assets.php

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
<?php
2+
3+
namespace Github\Api\Repository;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
/**
9+
* @link http://developer.github.com/v3/repos/releases/
10+
* @author Evgeniy Guseletov <[email protected]>
11+
*/
12+
class Assets extends AbstractApi
13+
{
14+
/**
15+
* @deprecated Will be removed as soon as gh releases api gets stable
16+
*/
17+
public function configure()
18+
{
19+
$this->client->setHeaders(array(
20+
'Accept: application/vnd.github.manifold-preview'
21+
));
22+
}
23+
24+
/**
25+
* Get all release's assets in selected repository
26+
* GET /repos/:owner/:repo/releases/:id/assets
27+
*
28+
* @param string $username the user who owns the repo
29+
* @param string $repository the name of the repo
30+
* @param integer $id the id of the release
31+
*
32+
* @return array
33+
*/
34+
public function all($username, $repository, $id)
35+
{
36+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id).'/assets');
37+
}
38+
39+
/**
40+
* Get an asset in selected repository's release
41+
* GET /repos/:owner/:repo/releases/assets/:id
42+
*
43+
* @param string $username the user who owns the repo
44+
* @param string $repository the name of the repo
45+
* @param integer $id the id of the asset
46+
*
47+
* @return array
48+
*/
49+
public function show($username, $repository, $id)
50+
{
51+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
52+
}
53+
54+
/**
55+
* Edit an asset in selected repository's release
56+
* PATCH /repos/:owner/:repo/releases/assets/:id
57+
*
58+
* @param string $username the user who owns the repo
59+
* @param string $repository the name of the repo
60+
* @param integer $id the id of the asset
61+
* @param array $params request parameters
62+
*
63+
* @throws MissingArgumentException
64+
*
65+
* @return array
66+
*/
67+
public function edit($username, $repository, $id, array $params)
68+
{
69+
if (!isset($params['name'])) {
70+
throw new MissingArgumentException('name');
71+
}
72+
73+
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id), $params);
74+
}
75+
76+
/**
77+
* Delete an asset in selected repository's release
78+
* DELETE /repos/:owner/:repo/releases/assets/:id
79+
*
80+
* @param string $username the user who owns the repo
81+
* @param string $repository the name of the repo
82+
* @param integer $id the id of the asset
83+
*
84+
* @return array
85+
*/
86+
public function remove($username, $repository, $id)
87+
{
88+
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.rawurlencode($id));
89+
}
90+
}
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
<?php
2+
3+
namespace Github\Api\Repository;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
/**
9+
* @link http://developer.github.com/v3/repos/releases/
10+
* @author Matthew Simo <[email protected]>
11+
* @author Evgeniy Guseletov <[email protected]>
12+
*/
13+
class Releases extends AbstractApi
14+
{
15+
/**
16+
* @deprecated Will be removed as soon as gh releases api gets stable
17+
*/
18+
public function configure()
19+
{
20+
$this->client->setHeaders(array(
21+
'Accept: application/vnd.github.manifold-preview'
22+
));
23+
}
24+
25+
/**
26+
* List releases in selected repository
27+
*
28+
* @param string $username the user who owns the repo
29+
* @param string $repository the name of the repo
30+
*
31+
* @return array
32+
*/
33+
public function all($username, $repository)
34+
{
35+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases');
36+
}
37+
38+
/**
39+
* Get a release in selected repository
40+
*
41+
* @param string $username the user who owns the repo
42+
* @param string $repository the name of the repo
43+
* @param integer $id the id of the release
44+
*
45+
* @return array
46+
*/
47+
public function show($username, $repository, $id)
48+
{
49+
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id));
50+
}
51+
52+
/**
53+
* Create new release in selected repository
54+
*
55+
* @param string $username
56+
* @param string $repository
57+
* @param array $params
58+
*
59+
* @throws MissingArgumentException
60+
*
61+
* @return array
62+
*/
63+
public function create($username, $repository, array $params)
64+
{
65+
if (!isset($params['tag_name'])) {
66+
throw new MissingArgumentException('tag_name');
67+
}
68+
69+
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases', $params);
70+
}
71+
72+
/**
73+
* Edit release in selected repository
74+
*
75+
* @param string $username
76+
* @param string $repository
77+
* @param integer $id
78+
* @param array $params
79+
*
80+
* @return array
81+
*/
82+
public function edit($username, $repository, $id, array $params)
83+
{
84+
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id), $params);
85+
}
86+
87+
/**
88+
* Delete a release in selected repository (Not thoroughly tested!)
89+
*
90+
* @param string $username the user who owns the repo
91+
* @param string $repository the name of the repo
92+
* @param integer $id the id of the release
93+
*
94+
* @return array
95+
*/
96+
public function remove($username, $repository, $id)
97+
{
98+
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/'.rawurlencode($id));
99+
}
100+
101+
/**
102+
* @return Assets
103+
*/
104+
public function assets()
105+
{
106+
return new Assets($this->client);
107+
}
108+
}

test/Github/Tests/Api/RepoTest.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,16 @@ public function shouldGetStatusesApiObject()
407407
$this->assertInstanceOf('Github\Api\Repository\Statuses', $api->statuses());
408408
}
409409

410+
/**
411+
* @test
412+
*/
413+
public function shouldGetReleasesApiObject()
414+
{
415+
$api = $this->getApiMock();
416+
417+
$this->assertInstanceOf('Github\Api\Repository\Releases', $api->releases());
418+
}
419+
410420
protected function getApiClass()
411421
{
412422
return 'Github\Api\Repo';

0 commit comments

Comments
 (0)