diff --git a/doc/issue/labels.md b/doc/issue/labels.md index 797d9a50427..37aa0b052bb 100644 --- a/doc/issue/labels.md +++ b/doc/issue/labels.md @@ -12,6 +12,33 @@ $labels = $client->api('issue')->labels()->all('KnpLabs', 'php-github-api'); List all project labels by username and repo. Returns an array of project labels. +### Create a label + +```php +$labels = $client->api('issue')->labels()->create('KnpLabs', 'php-github-api', array( + 'name' => 'Bug', + 'color' => 'FFFFFF', +)); +``` + +Create a new label in the repository. + +### Update a label + +```php +$labels = $client->api('issue')->labels()->update('KnpLabs', 'php-github-api', 'Enhancement', 'Feature', 'FFFFFF'); +``` + +Update the label name and color. + +### Delete a label + +```php +$labels = $client->api('issue')->labels()->deleteLabel('KnpLabs', 'php-github-api', 'Bug'); +``` + +Delete a new label from the repository. + ### Add a label on an issue > Requires [authentication](../security.md). diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 5628201f50c..bdce1437186 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -4,6 +4,7 @@ use Github\Api\AbstractApi; use Github\Exception\InvalidArgumentException; +use Github\Exception\MissingArgumentException; /** * @link http://developer.github.com/v3/issues/labels/ @@ -32,6 +33,21 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } + public function deleteLabel($username, $repository, $label) + { + return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label)); + } + + public function update($username, $repository, $label, $newName, $color) + { + $params = array( + 'name' => $newName, + 'color' => $color, + ); + + return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params); + } + public function add($username, $repository, $issue, $labels) { if (is_string($labels)) { diff --git a/test/Github/Tests/Api/Issue/LabelsTest.php b/test/Github/Tests/Api/Issue/LabelsTest.php index 1bfa73c69ca..3a6b7009e5d 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -6,7 +6,6 @@ class LabelsTest extends TestCase { - /** * @test */ @@ -76,6 +75,39 @@ public function shouldCreateLabelWithColor() $this->assertEquals($expectedValue, $api->create('KnpLabs', 'php-github-api', $data)); } + /** + * @test + */ + public function shouldDeleteLabel() + { + $expectedValue = array('someOutput'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('repos/KnpLabs/php-github-api/labels/foo') + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->deleteLabel('KnpLabs', 'php-github-api', 'foo')); + } + + /** + * @test + */ + public function shouldUpdateLabel() + { + $expectedValue = array(array('name' => 'bar', 'color' => 'FFF')); + $data = array('name' => 'bar', 'color' => 'FFF'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('patch') + ->with('repos/KnpLabs/php-github-api/labels/foo', $data) + ->will($this->returnValue($expectedValue)); + + $this->assertEquals($expectedValue, $api->update('KnpLabs', 'php-github-api', 'foo', 'bar', 'FFF')); + } + /** * @test */