diff --git a/doc/README.md b/doc/README.md index 04fcd7a3885..ba33a60c503 100644 --- a/doc/README.md +++ b/doc/README.md @@ -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) * Miscellaneous * [Emojis](miscellaneous/emojis.md) * [Gitignore](miscellaneous/gitignore.md) diff --git a/doc/issue/assignees.md b/doc/issue/assignees.md new file mode 100644 index 00000000000..035ea8ddcd7 --- /dev/null +++ b/doc/issue/assignees.md @@ -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]); +``` diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 2b35848bccb..828726f96ed 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -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 diff --git a/doc/issues.md b/doc/issues.md index e2804277d35..3f26bab5ad6 100644 --- a/doc/issues.md +++ b/doc/issues.md @@ -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); +``` diff --git a/lib/Github/Api/Issue.php b/lib/Github/Api/Issue.php index f1f41d92ed1..4c30783473d 100644 --- a/lib/Github/Api/Issue.php +++ b/lib/Github/Api/Issue.php @@ -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; @@ -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. * @@ -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); + } } diff --git a/lib/Github/Api/Issue/Assignees.php b/lib/Github/Api/Issue/Assignees.php new file mode 100644 index 00000000000..f304f7ab05a --- /dev/null +++ b/lib/Github/Api/Issue/Assignees.php @@ -0,0 +1,83 @@ +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); + } +} diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 8f27887acfb..fb0f52362e3 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -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. * diff --git a/test/Github/Tests/Api/Issue/AssigneesTest.php b/test/Github/Tests/Api/Issue/AssigneesTest.php new file mode 100644 index 00000000000..a3cfe0f6066 --- /dev/null +++ b/test/Github/Tests/Api/Issue/AssigneesTest.php @@ -0,0 +1,107 @@ +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; + } +} diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index e6be19d27c3..5be4e21254d 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -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 */ diff --git a/test/Github/Tests/Api/IssueTest.php b/test/Github/Tests/Api/IssueTest.php index 242a650a3e7..a8a40835b39 100644 --- a/test/Github/Tests/Api/IssueTest.php +++ b/test/Github/Tests/Api/IssueTest.php @@ -242,6 +242,36 @@ public function shouldGetMilestonesApiObject() $this->assertInstanceOf(\Github\Api\Issue\Milestones::class, $api->milestones()); } + /** + * @test + */ + public function shouldLockIssue() + { + $parameters = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('/repos/knplabs/php-github-api/issues/1/lock', $parameters); + + $api->lock('knplabs', 'php-github-api', '1'); + } + + /** + * @test + */ + public function shouldUnlockIssue() + { + $parameters = array(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('/repos/knplabs/php-github-api/issues/1/lock', $parameters); + + $api->unlock('knplabs', 'php-github-api', '1'); + } + /** * @return string */