Skip to content

Commit 4eb1e2e

Browse files
acrobatNyholm
authored andcommitted
Missing issues api endpoints (#533)
1 parent adf8914 commit 4eb1e2e

File tree

10 files changed

+345
-0
lines changed

10 files changed

+345
-0
lines changed

doc/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ APIs:
1212
* [Comments](gists/comments.md)
1313
* [Integrations](integrations.md)
1414
* [Issues](issues.md)
15+
* [Assignees](issue/assignees.md)
1516
* [Comments](issue/comments.md)
1617
* [Labels](issue/labels.md)
18+
* [Milestones](issue/milestones.md)
1719
* Miscellaneous
1820
* [Emojis](miscellaneous/emojis.md)
1921
* [Gitignore](miscellaneous/gitignore.md)

doc/issue/assignees.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
## Issues / Assignees API
2+
[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md)
3+
4+
Wraps [GitHub Issue Assignees API](https://developer.github.com/v3/issues/assignees/).
5+
6+
### List all available assignees
7+
8+
```php
9+
$assignees = $client->api('issue')->assignees()->listAvailable('KnpLabs', 'php-github-api');
10+
```
11+
12+
### Check if a user is an available assignee
13+
14+
```php
15+
$info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', 'test-user);
16+
```
17+
18+
### Add assignee
19+
20+
```php
21+
$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]);
22+
```
23+
24+
### Remove assignee
25+
26+
```php
27+
$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]);
28+
```

doc/issue/labels.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api');
1212
List all project labels by username and repo.
1313
Returns an array of project labels.
1414

15+
### Get a single label
16+
17+
```php
18+
$label = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api', 'label1');
19+
```
20+
1521
### Create a label
1622

1723
```php

doc/issues.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,3 +84,15 @@ $client->api('issue')->all('KnpLabs', 'php-github-api', array('labels' => 'label
8484
```
8585

8686
Returns an array of issues matching the given label.
87+
88+
### Lock an issue discussion
89+
90+
```php
91+
$client->api('issue')->lock('KnpLabs', 'php-github-api', 4);
92+
```
93+
94+
### Unlock an issue discussion
95+
96+
```php
97+
$client->api('issue')->unlock('KnpLabs', 'php-github-api', 4);
98+
```

lib/Github/Api/Issue.php

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Github\Api;
44

5+
use Github\Api\Issue\Assignees;
56
use Github\Api\Issue\Comments;
67
use Github\Api\Issue\Events;
78
use Github\Api\Issue\Labels;
@@ -132,6 +133,38 @@ public function update($username, $repository, $id, array $params)
132133
return $this->patch('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id), $params);
133134
}
134135

136+
/**
137+
* Lock an issue. Users with push access can lock an issue's conversation.
138+
*
139+
* @link https://developer.github.com/v3/issues/#lock-an-issue
140+
*
141+
* @param string $username
142+
* @param string $repository
143+
* @param string $id
144+
*
145+
* @return string
146+
*/
147+
public function lock($username, $repository, $id)
148+
{
149+
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
150+
}
151+
152+
/**
153+
* Unlock an issue. Users with push access can unlock an issue's conversation.
154+
*
155+
* @link https://developer.github.com/v3/issues/#lock-an-issue
156+
*
157+
* @param string $username
158+
* @param string $repository
159+
* @param string $id
160+
*
161+
* @return string
162+
*/
163+
public function unlock($username, $repository, $id)
164+
{
165+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
166+
}
167+
135168
/**
136169
* List an issue comments.
137170
*
@@ -179,4 +212,16 @@ public function milestones()
179212
{
180213
return new Milestones($this->client);
181214
}
215+
216+
/**
217+
* List all assignees.
218+
*
219+
* @link https://developer.github.com/v3/issues/assignees/
220+
*
221+
* @return Assignees
222+
*/
223+
public function assignees()
224+
{
225+
return new Assignees($this->client);
226+
}
182227
}

lib/Github/Api/Issue/Assignees.php

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
<?php
2+
3+
namespace Github\Api\Issue;
4+
5+
use Github\Api\AbstractApi;
6+
use Github\Exception\MissingArgumentException;
7+
8+
class Assignees extends AbstractApi
9+
{
10+
/**
11+
* List all the available assignees to which issues may be assigned.
12+
*
13+
* @param string $username
14+
* @param string $repository
15+
* @param array $parameters
16+
*
17+
* @return array
18+
*/
19+
public function listAvailable($username, $repository, array $parameters = array())
20+
{
21+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees', $parameters);
22+
}
23+
24+
/**
25+
* Check to see if a particular user is an assignee for a repository.
26+
*
27+
* @link https://developer.github.com/v3/issues/assignees/#check-assignee
28+
*
29+
* @param string $username
30+
* @param string $repository
31+
* @param string $assignee
32+
*
33+
* @return array
34+
*/
35+
public function check($username, $repository, $assignee)
36+
{
37+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/' . rawurlencode($assignee));
38+
}
39+
40+
/**
41+
* Add assignees to an Issue
42+
*
43+
* @link https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
44+
*
45+
* @param string $username
46+
* @param string $repository
47+
* @param string $issue
48+
* @param array $parameters
49+
*
50+
* @return string
51+
* @throws MissingArgumentException
52+
*/
53+
public function add($username, $repository, $issue, array $parameters)
54+
{
55+
if (!isset($parameters['assignees'])) {
56+
throw new MissingArgumentException('assignees');
57+
}
58+
59+
return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
60+
}
61+
62+
/**
63+
* Remove assignees from an Issue
64+
*
65+
* @link https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
66+
*
67+
* @param string $username
68+
* @param string $repository
69+
* @param string $issue
70+
* @param array $parameters
71+
*
72+
* @return string
73+
* @throws MissingArgumentException
74+
*/
75+
public function remove($username, $repository, $issue, array $parameters)
76+
{
77+
if (!isset($parameters['assignees'])) {
78+
throw new MissingArgumentException('assignees');
79+
}
80+
81+
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
82+
}
83+
}

lib/Github/Api/Issue/Labels.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,22 @@ public function all($username, $repository, $issue = null)
3333
return $this->get($path);
3434
}
3535

36+
/**
37+
* Get a single label.
38+
*
39+
* @link https://developer.github.com/v3/issues/labels/#get-a-single-label
40+
*
41+
* @param string $username
42+
* @param string $repository
43+
* @param string $label
44+
*
45+
* @return array
46+
*/
47+
public function show($username, $repository, $label)
48+
{
49+
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
50+
}
51+
3652
/**
3753
* Create a label for a repository.
3854
*
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
<?php
2+
3+
namespace Github\Tests\Api\Issue;
4+
5+
use Github\Api\Issue\Assignees;
6+
use Github\Tests\Api\TestCase;
7+
8+
class AssigneesTest extends TestCase
9+
{
10+
/**
11+
* @test
12+
*/
13+
public function shouldListAvailableAssignees()
14+
{
15+
$api = $this->getApiMock();
16+
$api->expects($this->once())
17+
->method('get')
18+
->with('/repos/knplabs/php-github-api/assignees');
19+
20+
$api->listAvailable('knplabs', 'php-github-api');
21+
}
22+
23+
/**
24+
* @test
25+
*/
26+
public function shouldCheckAssignee()
27+
{
28+
$api = $this->getApiMock();
29+
$api->expects($this->once())
30+
->method('get')
31+
->with('/repos/knplabs/php-github-api/assignees/test-user');
32+
33+
$api->check('knplabs', 'php-github-api', 'test-user');
34+
}
35+
36+
/**
37+
* @test
38+
* @expectedException \Github\Exception\MissingArgumentException
39+
*/
40+
public function shouldNotAddAssigneeMissingParameter()
41+
{
42+
$data = array();
43+
44+
$api = $this->getApiMock();
45+
$api->expects($this->never())
46+
->method('post');
47+
48+
$api->add('knplabs', 'php-github-api', 4, $data);
49+
}
50+
51+
/**
52+
* @test
53+
*/
54+
public function shouldAddAssignee()
55+
{
56+
$data = array(
57+
'assignees' => array('test-user')
58+
);
59+
60+
$api = $this->getApiMock();
61+
$api->expects($this->once())
62+
->method('post')
63+
->with('/repos/knplabs/php-github-api/issues/4/assignees', $data);
64+
65+
$api->add('knplabs', 'php-github-api', 4, $data);
66+
}
67+
68+
/**
69+
* @test
70+
* @expectedException \Github\Exception\MissingArgumentException
71+
*/
72+
public function shouldNotRemoveAssigneeMissingParameter()
73+
{
74+
$data = array();
75+
76+
$api = $this->getApiMock();
77+
$api->expects($this->never())
78+
->method('delete');
79+
80+
$api->remove('knplabs', 'php-github-api', 4, $data);
81+
}
82+
83+
/**
84+
* @test
85+
*/
86+
public function shouldRemoveAssignee()
87+
{
88+
$data = array(
89+
'assignees' => array('test-user')
90+
);
91+
92+
$api = $this->getApiMock();
93+
$api->expects($this->once())
94+
->method('delete')
95+
->with('/repos/knplabs/php-github-api/issues/4/assignees', $data);
96+
97+
$api->remove('knplabs', 'php-github-api', 4, $data);
98+
}
99+
100+
/**
101+
* @return string
102+
*/
103+
protected function getApiClass()
104+
{
105+
return Assignees::class;
106+
}
107+
}

test/Github/Tests/Api/Issue/LabelsTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,22 @@ public function shouldCreateLabel()
5858
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
5959
}
6060

61+
/**
62+
* @test
63+
*/
64+
public function shouldGetSingleLabel()
65+
{
66+
$expectedValue = array(array('name' => 'label1'));
67+
68+
$api = $this->getApiMock();
69+
$api->expects($this->once())
70+
->method('get')
71+
->with('/repos/KnpLabs/php-github-api/labels/label1')
72+
->will($this->returnValue($expectedValue));
73+
74+
$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'label1'));
75+
}
76+
6177
/**
6278
* @test
6379
*/

0 commit comments

Comments
 (0)