Skip to content

Missing issues api endpoints #533

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ APIs:
* [Comments](gists/comments.md)
* [Integrations](integrations.md)
* [Issues](issues.md)
* [Assignees](issue/assignees.md)
* [Comments](issue/comments.md)
* [Labels](issue/labels.md)
* [Milestones](issue/milestones.md)
* [Organization](organization.md)
* [Members](organization/members.md)
* [Teams](organization/teams.md)
Expand Down
28 changes: 28 additions & 0 deletions doc/issue/assignees.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## Issues / Assignees API
[Back to the "Issues API"](../issues.md) | [Back to the navigation](../README.md)

Wraps [GitHub Issue Assignees API](https://developer.github.com/v3/issues/assignees/).

### List all available assignees

```php
$assignees = $client->api('issue')->assignees()->listAvailable('KnpLabs', 'php-github-api');
```

### Check if a user is an available assignee

```php
$info = $client->api('issue')->assignees()->check('KnpLabs', 'php-github-api', 'test-user);
```

### Add assignee

```php
$client->api('issue')->assignees()->add('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]);
```

### Remove assignee

```php
$client->api('issue')->assignees()->remove('KnpLabs', 'php-github-api', 4, ['assignees' => 'test-user]);
```
6 changes: 6 additions & 0 deletions doc/issue/labels.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api');
List all project labels by username and repo.
Returns an array of project labels.

### Get a single label

```php
$label = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api', 'label1');
```

### Create a label

```php
Expand Down
12 changes: 12 additions & 0 deletions doc/issues.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,3 +84,15 @@ $client->api('issue')->all('KnpLabs', 'php-github-api', array('labels' => 'label
```

Returns an array of issues matching the given label.

### Lock an issue discussion

```php
$client->api('issue')->lock('KnpLabs', 'php-github-api', 4);
```

### Unlock an issue discussion

```php
$client->api('issue')->unlock('KnpLabs', 'php-github-api', 4);
```
45 changes: 45 additions & 0 deletions lib/Github/Api/Issue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Github\Api;

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

/**
* Lock an issue. Users with push access can lock an issue's conversation.
*
* @link https://developer.github.com/v3/issues/#lock-an-issue
*
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
public function lock($username, $repository, $id)
{
return $this->put('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
}

/**
* Unlock an issue. Users with push access can unlock an issue's conversation.
*
* @link https://developer.github.com/v3/issues/#lock-an-issue
*
* @param string $username
* @param string $repository
* @param string $id
*
* @return string
*/
public function unlock($username, $repository, $id)
{
return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($id).'/lock');
}

/**
* List an issue comments.
*
Expand Down Expand Up @@ -179,4 +212,16 @@ public function milestones()
{
return new Milestones($this->client);
}

/**
* List all assignees.
*
* @link https://developer.github.com/v3/issues/assignees/
*
* @return Assignees
*/
public function assignees()
{
return new Assignees($this->client);
}
}
83 changes: 83 additions & 0 deletions lib/Github/Api/Issue/Assignees.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Github\Api\Issue;

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

class Assignees extends AbstractApi
{
/**
* List all the available assignees to which issues may be assigned.
*
* @param string $username
* @param string $repository
* @param array $parameters
*
* @return array
*/
public function listAvailable($username, $repository, array $parameters = array())
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees', $parameters);
}

/**
* Check to see if a particular user is an assignee for a repository.
*
* @link https://developer.github.com/v3/issues/assignees/#check-assignee
*
* @param string $username
* @param string $repository
* @param string $assignee
*
* @return array
*/
public function check($username, $repository, $assignee)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/assignees/' . rawurlencode($assignee));
}

/**
* Add assignees to an Issue
*
* @link https://developer.github.com/v3/issues/assignees/#add-assignees-to-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
* @param array $parameters
*
* @return string
* @throws MissingArgumentException
*/
public function add($username, $repository, $issue, array $parameters)
{
if (!isset($parameters['assignees'])) {
throw new MissingArgumentException('assignees');
}

return $this->post('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
}

/**
* Remove assignees from an Issue
*
* @link https://developer.github.com/v3/issues/assignees/#remove-assignees-from-an-issue
*
* @param string $username
* @param string $repository
* @param string $issue
* @param array $parameters
*
* @return string
* @throws MissingArgumentException
*/
public function remove($username, $repository, $issue, array $parameters)
{
if (!isset($parameters['assignees'])) {
throw new MissingArgumentException('assignees');
}

return $this->delete('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/assignees', $parameters);
}
}
16 changes: 16 additions & 0 deletions lib/Github/Api/Issue/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,22 @@ public function all($username, $repository, $issue = null)
return $this->get($path);
}

/**
* Get a single label.
*
* @link https://developer.github.com/v3/issues/labels/#get-a-single-label
*
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function show($username, $repository, $label)
{
return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}

/**
* Create a label for a repository.
*
Expand Down
107 changes: 107 additions & 0 deletions test/Github/Tests/Api/Issue/AssigneesTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
<?php

namespace Github\Tests\Api\Issue;

use Github\Api\Issue\Assignees;
use Github\Tests\Api\TestCase;

class AssigneesTest extends TestCase
{
/**
* @test
*/
public function shouldListAvailableAssignees()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/knplabs/php-github-api/assignees');

$api->listAvailable('knplabs', 'php-github-api');
}

/**
* @test
*/
public function shouldCheckAssignee()
{
$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/knplabs/php-github-api/assignees/test-user');

$api->check('knplabs', 'php-github-api', 'test-user');
}

/**
* @test
* @expectedException \Github\Exception\MissingArgumentException
*/
public function shouldNotAddAssigneeMissingParameter()
{
$data = array();

$api = $this->getApiMock();
$api->expects($this->never())
->method('post');

$api->add('knplabs', 'php-github-api', 4, $data);
}

/**
* @test
*/
public function shouldAddAssignee()
{
$data = array(
'assignees' => array('test-user')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('/repos/knplabs/php-github-api/issues/4/assignees', $data);

$api->add('knplabs', 'php-github-api', 4, $data);
}

/**
* @test
* @expectedException \Github\Exception\MissingArgumentException
*/
public function shouldNotRemoveAssigneeMissingParameter()
{
$data = array();

$api = $this->getApiMock();
$api->expects($this->never())
->method('delete');

$api->remove('knplabs', 'php-github-api', 4, $data);
}

/**
* @test
*/
public function shouldRemoveAssignee()
{
$data = array(
'assignees' => array('test-user')
);

$api = $this->getApiMock();
$api->expects($this->once())
->method('delete')
->with('/repos/knplabs/php-github-api/issues/4/assignees', $data);

$api->remove('knplabs', 'php-github-api', 4, $data);
}

/**
* @return string
*/
protected function getApiClass()
{
return Assignees::class;
}
}
16 changes: 16 additions & 0 deletions test/Github/Tests/Api/Issue/LabelsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public function shouldCreateLabel()
$this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data));
}

/**
* @test
*/
public function shouldGetSingleLabel()
{
$expectedValue = array(array('name' => 'label1'));

$api = $this->getApiMock();
$api->expects($this->once())
->method('get')
->with('/repos/KnpLabs/php-github-api/labels/label1')
->will($this->returnValue($expectedValue));

$this->assertEquals($expectedValue, $api->show('KnpLabs', 'php-github-api', 'label1'));
}

/**
* @test
*/
Expand Down
Loading