Skip to content

Commit 437b1bb

Browse files
authored
Merge pull request #469 from acrobat/organisation-projects
Reworked projects api
2 parents a843793 + 017ec1b commit 437b1bb

File tree

17 files changed

+405
-272
lines changed

17 files changed

+405
-272
lines changed

doc/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ APIs:
1414
* [Organization](organization.md)
1515
* [Members](organization/members.md)
1616
* [Teams](organization/teams.md)
17+
* [Projects](project/projects.md)
18+
* [Columns](project/columns.md)
19+
* [Cards](project/cards.md)
1720
* [Pull Requests](pull_requests.md)
1821
* [Comments](pull_request/comments.md)
1922
* [Rate Limits](rate_limits.md)
2023
* [Repositories](repos.md)
2124
* [Contents](repo/contents.md)
2225
* [Deployments](repo/deployments.md)
23-
* [Projects](repo/projects.md)
24-
* [Columns](repo/columns.md)
25-
* [Cards](repo/cards.md)
2626
* [Releases](repo/releases.md)
2727
* [Assets](repo/assets.md)
2828
* [Stargazers](repo/stargazers.md)

doc/repo/cards.md renamed to doc/project/cards.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,54 @@
44
This api is currently only available to developers in Early Access. To access the API during the Early Access period,
55
you must provide a custom media type in the Accept header.
66

7+
Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project.
8+
All the example use the repository projects column card api but this also works form the organization api (`$client->api('org_projects')->columns()->cards()`)
9+
10+
711
```php
812
$client->api('repo')->projects()->columns()->cards()->configure();
913
```
1014

1115
### List all cards of a column
1216

1317
```php
14-
$cards = $client->api('repo')->projects()->columns()->cards()->all('twbs', 'bootstrap', $columnId);
18+
$cards = $client->api('repo')->projects()->columns()->cards()->all($columnId);
1519
```
1620

1721
### List one card
1822

1923
```php
20-
$card = $client->api('repo')->projects()->columns()->cards()->show('twbs', 'bootstrap', $cardId);
24+
$card = $client->api('repo')->projects()->columns()->cards()->show($cardId);
2125
```
2226

2327
### Create a card
2428

2529
> Requires [authentication](../security.md).
2630
2731
```php
28-
$card = $client->api('repo')->projects()->columns()->cards()->create('twbs', 'bootstrap', $columnId, array('content_type' => 'Issue', 'content_id' => '452'));
32+
$card = $client->api('repo')->projects()->columns()->cards()->create($columnId, array('content_type' => 'Issue', 'content_id' => '452'));
2933
```
3034

3135
### Edit a card
3236

3337
> Requires [authentication](../security.md).
3438
3539
```php
36-
$card = $client->api('repo')->project()->columns()->cards()->update('twbs', 'bootstrap', $cardId, array('note' => 'card note'));
40+
$card = $client->api('repo')->project()->columns()->cards()->update($cardId, array('note' => 'card note'));
3741
```
3842

3943
### Remove a card
4044

4145
> Requires [authentication](../security.md).
4246
4347
```php
44-
$card = $client->api('repo')->projects()->columns()->cards()->deleteCard('twbs', 'bootstrap', $cardId);
48+
$card = $client->api('repo')->projects()->columns()->cards()->deleteCard($cardId);
4549
```
4650

4751
### Move a card
4852

4953
> Requires [authentication](../security.md).
5054
5155
```php
52-
$card = $client->api('repo')->projects()->columns()->cards()->move('twbs', 'bootstrap', $cardId, array('position' => 'top));
56+
$card = $client->api('repo')->projects()->columns()->cards()->move($cardId, array('position' => 'top));
5357
```

doc/repo/columns.md renamed to doc/project/columns.md

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,50 +4,54 @@
44
This api is currently only available to developers in Early Access. To access the API during the Early Access period,
55
you must provide a custom media type in the Accept header.
66

7+
Both repositories and organisations have projects. The api is only different for getting all project or retrieving a single project.
8+
All the example use the repository projects column api but this also works form the organization api (`$client->api('org_projects')->columns()`)
9+
10+
711
```php
812
$client->api('repo')->projects()->columns()->configure();
913
```
1014

1115
### List all columns of a project
1216

1317
```php
14-
$columns = $client->api('repo')->projects()->columns()->all('twbs', 'bootstrap', $projectId);
18+
$columns = $client->api('repo')->projects()->columns()->all($projectId);
1519
```
1620

1721
### List one column
1822

1923
```php
20-
$column = $client->api('repo')->projects()->columns()->show('twbs', 'bootstrap', $columnId);
24+
$column = $client->api('repo')->projects()->columns()->show($columnId);
2125
```
2226

2327
### Create a column
2428

2529
> Requires [authentication](../security.md).
2630
2731
```php
28-
$column = $client->api('repo')->projects()->columns()->create('twbs', 'bootstrap', $projectId, array('name' => 'Column name'));
32+
$column = $client->api('repo')->projects()->columns()->create($projectId, array('name' => 'Column name'));
2933
```
3034

3135
### Edit a column
3236

3337
> Requires [authentication](../security.md).
3438
3539
```php
36-
$column = $client->api('repo')->project()->columns()->update('twbs', 'bootstrap', $columnId, array('name' => 'New name'));
40+
$column = $client->api('repo')->project()->columns()->update($columnId, array('name' => 'New name'));
3741
```
3842

3943
### Remove a column
4044

4145
> Requires [authentication](../security.md).
4246
4347
```php
44-
$column = $client->api('repo')->projects()->columns()->deleteColumn('twbs', 'bootstrap', $columnId);
48+
$column = $client->api('repo')->projects()->columns()->deleteColumn($columnId);
4549
```
4650

4751
### Move a column
4852

4953
> Requires [authentication](../security.md).
5054
5155
```php
52-
$column = $client->api('repo')->projects()->columns()->move('twbs', 'bootstrap', $columnId, array('position' => 'first));
56+
$column = $client->api('repo')->projects()->columns()->move($columnId, array('position' => 'first));
5357
```

doc/repo/projects.md renamed to doc/project/projects.md

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
## Repo / Projects API
2-
[Back to the "Repos API"](../repos.md) | [Back to the navigation](../README.md)
2+
[Back to the "Repos API"](../) | [Back to the navigation](../README.md)
33

44
This api is currently only available to developers in Early Access. To access the API during the Early Access period,
55
you must provide a custom media type in the Accept header.
66

7+
Both repositories and organisations have projects. The api is only different for gettings all or a single project.
8+
All the example use the repository projects api but this also works form the organization api (`$client->api('org_projects')`)
9+
710
```php
811
$client->api('repo')->projects()->configure();
912
```
@@ -12,12 +15,16 @@ $client->api('repo')->projects()->configure();
1215

1316
```php
1417
$projects = $client->api('repo')->projects()->all('twbs', 'bootstrap');
18+
19+
//or
20+
21+
$projects = $client->api('org_projects')->all('twbs');
1522
```
1623

1724
### List one project
1825

1926
```php
20-
$project = $client->api('repo')->projects()->show('twbs', 'bootstrap', $projectId);
27+
$project = $client->api('repo')->projects()->show($projectId);
2128
```
2229

2330
### Create a project
@@ -33,13 +40,13 @@ $project = $client->api('repo')->projects()->create('twbs', 'bootstrap', array('
3340
> Requires [authentication](../security.md).
3441
3542
```php
36-
$project = $client->api('repo')->project()->update('twbs', 'bootstrap', $projectId, array('name' => 'New name'));
43+
$project = $client->api('repo')->project()->update($projectId, array('name' => 'New name'));
3744
```
3845

3946
### Remove a project
4047

4148
> Requires [authentication](../security.md).
4249
4350
```php
44-
$project = $client->api('repo')->projects()->deleteProject('twbs', 'bootstrap', $projectId);
51+
$project = $client->api('repo')->projects()->deleteProject($projectId);
4552
```
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
namespace Github\Api\Organization;
4+
5+
use Github\Api\Project\AbstractProjectApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
class Projects extends AbstractProjectApi
9+
{
10+
public function all($organization, array $params = array())
11+
{
12+
return $this->get('/orgs/'.rawurlencode($organization).'/projects', array_merge(array('page' => 1), $params));
13+
}
14+
15+
public function create($organization, array $params)
16+
{
17+
if (!isset($params['name'])) {
18+
throw new MissingArgumentException(array('name'));
19+
}
20+
21+
return $this->post('/orgs/'.rawurlencode($organization).'/projects', $params);
22+
}
23+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace Github\Api\Project;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
7+
8+
abstract class AbstractProjectApi extends AbstractApi
9+
{
10+
use AcceptHeaderTrait;
11+
12+
/**
13+
* Configure the accept header for Early Access to the projects api
14+
*
15+
* @see https://developer.github.com/v3/repos/projects/#projects
16+
*/
17+
public function configure()
18+
{
19+
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
20+
}
21+
22+
public function show($id, array $params = array())
23+
{
24+
return $this->get('/projects/' . rawurlencode($id), array_merge(array('page' => 1), $params));
25+
}
26+
27+
public function update($id, array $params)
28+
{
29+
return $this->patch('/projects/'.rawurlencode($id), $params);
30+
}
31+
32+
public function deleteProject($id)
33+
{
34+
return $this->delete('/projects/'.rawurlencode($id));
35+
}
36+
37+
public function columns()
38+
{
39+
return new Columns($this->client);
40+
}
41+
}

lib/Github/Api/Project/Cards.php

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
<?php
2+
3+
namespace Github\Api\Project;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
7+
use Github\Exception\MissingArgumentException;
8+
9+
class Cards extends AbstractApi
10+
{
11+
use AcceptHeaderTrait;
12+
13+
/**
14+
* Configure the accept header for Early Access to the projects api
15+
*
16+
* @see https://developer.github.com/v3/repos/projects/#projects
17+
*/
18+
public function configure()
19+
{
20+
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
21+
}
22+
23+
public function all($columnId, array $params = array())
24+
{
25+
return $this->get('/projects/columns/' . rawurlencode($columnId) . '/cards', array_merge(array('page' => 1), $params));
26+
}
27+
28+
public function show($id)
29+
{
30+
return $this->get('/projects/columns/cards/'.rawurlencode($id));
31+
}
32+
33+
public function create($columnId, array $params)
34+
{
35+
return $this->post('/projects/columns/' . rawurlencode($columnId) . '/cards', $params);
36+
}
37+
38+
public function update($id, array $params)
39+
{
40+
return $this->patch('/projects/columns/cards/' . rawurlencode($id), $params);
41+
}
42+
43+
public function deleteCard($id)
44+
{
45+
return $this->delete('/projects/columns/cards/'.rawurlencode($id));
46+
}
47+
48+
public function move($id, array $params)
49+
{
50+
if (!isset($params['position'])) {
51+
throw new MissingArgumentException(array('position'));
52+
}
53+
54+
return $this->post('/projects/columns/cards/' . rawurlencode($id) . '/moves', $params);
55+
}
56+
}

lib/Github/Api/Project/Columns.php

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
<?php
2+
3+
namespace Github\Api\Project;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Api\AcceptHeaderTrait;
7+
use Github\Exception\MissingArgumentException;
8+
9+
class Columns extends AbstractApi
10+
{
11+
use AcceptHeaderTrait;
12+
13+
/**
14+
* Configure the accept header for Early Access to the projects api
15+
*
16+
* @see https://developer.github.com/v3/repos/projects/#projects
17+
*/
18+
public function configure()
19+
{
20+
$this->acceptHeaderValue = 'application/vnd.github.inertia-preview+json';
21+
}
22+
23+
public function all($projectId, array $params = array())
24+
{
25+
return $this->get('/projects/' . rawurlencode($projectId) . '/columns', array_merge(array('page' => 1), $params));
26+
}
27+
28+
public function show($id)
29+
{
30+
return $this->get('/projects/columns/'.rawurlencode($id));
31+
}
32+
33+
public function create($projectId, array $params)
34+
{
35+
if (!isset($params['name'])) {
36+
throw new MissingArgumentException(array('name'));
37+
}
38+
39+
return $this->post('/projects/' . rawurlencode($projectId) . '/columns', $params);
40+
}
41+
42+
public function update($id, array $params)
43+
{
44+
if (!isset($params['name'])) {
45+
throw new MissingArgumentException(array('name'));
46+
}
47+
48+
return $this->patch('/projects/columns/' . rawurlencode($id), $params);
49+
}
50+
51+
public function deleteColumn($id)
52+
{
53+
return $this->delete('/projects/columns/'.rawurlencode($id));
54+
}
55+
56+
public function move($id, array $params)
57+
{
58+
if (!isset($params['position'])) {
59+
throw new MissingArgumentException(array('position'));
60+
}
61+
62+
return $this->post('/projects/columns/' . rawurlencode($id) . '/moves', $params);
63+
}
64+
65+
public function cards()
66+
{
67+
return new Cards($this->client);
68+
}
69+
}

0 commit comments

Comments
 (0)