From bad69912222420d4db666a17b9aa72f164f28842 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:08:12 +1300 Subject: [PATCH 1/4] Fixed missing import --- lib/Github/Api/Issue/Labels.php | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 5628201f50c..7481d2bdc18 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/ From 4b8a05a6785b66a6b66edbb2b105121b24c62a2b Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:15:08 +1300 Subject: [PATCH 2/4] Added support for deleting a label --- lib/Github/Api/Issue/Labels.php | 5 +++++ test/Github/Tests/Api/Issue/LabelsTest.php | 17 ++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index 7481d2bdc18..d04e536860d 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -33,6 +33,11 @@ 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 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..da749f5c213 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,22 @@ 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 */ From f31725ff0c97b7491fb0e33f97094aa6a170b6ea Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:18:50 +1300 Subject: [PATCH 3/4] Added support for updating a label --- lib/Github/Api/Issue/Labels.php | 10 ++++++++++ test/Github/Tests/Api/Issue/LabelsTest.php | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index d04e536860d..bdce1437186 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -38,6 +38,16 @@ 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 da749f5c213..3a6b7009e5d 100644 --- a/test/Github/Tests/Api/Issue/LabelsTest.php +++ b/test/Github/Tests/Api/Issue/LabelsTest.php @@ -91,6 +91,23 @@ public function shouldDeleteLabel() $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 */ From 70f16ecde69c5636eab3f9ca0e79a918b3c57a42 Mon Sep 17 00:00:00 2001 From: Matthieu Napoli Date: Fri, 27 Feb 2015 15:22:53 +1300 Subject: [PATCH 4/4] Added documentation for managing labels. --- doc/issue/labels.md | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) 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).