From 612eedbb2cbc0b29362f7e668943afe230f9ee1f Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Wed, 10 Oct 2012 11:32:01 +0530 Subject: [PATCH 01/11] Method to create new label --- libraries/joomla/github/issues.php | 39 ++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index b844779cff..1a1c636dd1 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -107,6 +107,45 @@ public function createComment($user, $repo, $issueId, $body) return json_decode($response->body); } + /** + * Method to create a label on a repo. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The label name. + * @param string $color The label color. + * + * @return object + * + * @since 12.1 + */ + public function createLabel($user, $repo, $name, $color) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels'; + + // Build the request data. + $data = json_encode( + array( + 'name' => $name, + 'color' => $color + ) + ); + + // Send the request. + $response = $this->client->post($this->fetchUrl($path), $data); + + // Validate the response code. + if ($response->code != 201) + { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + throw new DomainException($error->message, $response->code); + } + + return json_decode($response->body); + } + /** * Method to delete a comment on an issue. * From 9ca61cff661876ee89055032c30e9c6bc6b99d6f Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Wed, 10 Oct 2012 11:35:45 +0530 Subject: [PATCH 02/11] method to delete a label --- libraries/joomla/github/issues.php | 32 +++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index 1a1c636dd1..6f46b2c55c 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -117,7 +117,7 @@ public function createComment($user, $repo, $issueId, $body) * * @return object * - * @since 12.1 + * @since 12.3 */ public function createLabel($user, $repo, $name, $color) { @@ -174,6 +174,36 @@ public function deleteComment($user, $repo, $commentId) } } + /** + * Method to delete a label on a repo. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $label The label name. + * + * @return object + * + * @since 12.3 + */ + public function deleteLabel($user, $repo, $label) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; + + // Send the request. + $response = $this->client->delete($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code != 204) + { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + throw new DomainException($error->message, $response->code); + } + + return json_decode($response->body); + } + /** * Method to update an issue. * From c20e6e4e936c0f15a37a317c12fde90037af1bd9 Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Wed, 10 Oct 2012 11:39:29 +0530 Subject: [PATCH 03/11] method to edit a label --- libraries/joomla/github/issues.php | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index 6f46b2c55c..1dd0dfcd13 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -326,6 +326,46 @@ public function editComment($user, $repo, $commentId, $body) return json_decode($response->body); } + /** + * Method to update a label on a repo. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $label The label name. + * @param string $name The label name. + * @param string $color The label color. + * + * @return object + * + * @since 12.3 + */ + public function editLabel($user, $repo, $label, $name, $color) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels/' . $label; + + // Build the request data. + $data = json_encode( + array( + 'name' => $name, + 'color' => $color + ) + ); + + // Send the request. + $response = $this->client->patch($this->fetchUrl($path), $data); + + // Validate the response code. + if ($response->code != 200) + { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + throw new DomainException($error->message, $response->code); + } + + return json_decode($response->body); + } + /** * Method to get a single issue. * From 5d854710c0c17f8805076eb7842a7622be021e54 Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Wed, 10 Oct 2012 11:42:42 +0530 Subject: [PATCH 04/11] method to get labels --- libraries/joomla/github/issues.php | 57 ++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index 1dd0dfcd13..25e2dc6e90 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -458,6 +458,63 @@ public function getComments($user, $repo, $issueId, $page = 0, $limit = 0) return json_decode($response->body); } + /** + * Method to get a specific label on a repo. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * @param string $name The label name to get. + * + * @return object + * + * @since 12.3 + */ + public function getLabel($user, $repo, $name) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels/' . $name; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code != 200) + { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + throw new DomainException($error->message, $response->code); + } + + return json_decode($response->body); + } + + /** + * Method to get the list of labels on a repo. + * + * @param string $user The name of the owner of the GitHub repository. + * @param string $repo The name of the GitHub repository. + * + * @return array + * + * @since 12.3 + */ + public function getLabels($user, $repo) + { + // Build the request path. + $path = '/repos/' . $user . '/' . $repo . '/labels'; + + // Send the request. + $response = $this->client->get($this->fetchUrl($path)); + + // Validate the response code. + if ($response->code != 200) + { + // Decode the error response and throw an exception. + $error = json_decode($response->body); + throw new DomainException($error->message, $response->code); + } + } + /** * Method to list an authenticated user's issues. * From 04b9d65eca4dc7211045818d0ebc33748ca0080d Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:05:45 +0530 Subject: [PATCH 05/11] unit tests for creating label --- .../unit/joomla/github/JGithubIssuesTest.php | 51 +++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index 98b1b83659..1a838cee65 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -173,6 +173,57 @@ public function testCreateCommentFailure() $this->object->createComment('joomla', 'joomla-platform', 523, 'My Insightful Comment'); } + /** + * Tests the createLabel method + * + * @return void + */ + public function testCreateLabel() + { + $returnData = new stdClass; + $returnData->code = 201; + $returnData->body = $this->sampleString; + + $issue = new stdClass; + $issue->name = 'Label'; + $issue->color = 'blue'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) + ->will($this->returnValue($returnData)); + + $this->assertThat( + $this->object->createLabel('joomla', 'joomla-platform', 'Label', 'blue'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the createLabel method - failure + * + * @expectedException DomainException + * + * @return void + */ + public function testCreateLabelFailure() + { + $returnData = new stdClass; + $returnData->code = 501; + $returnData->body = $this->errorString; + + $issue = new stdClass; + $issue->name = 'Label'; + $issue->color = 'green'; + + $this->client->expects($this->once()) + ->method('post') + ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) + ->will($this->returnValue($returnData)); + + $this->object->createLabel('joomla', 'joomla-platform', 'Label', 'blue'); + } + /** * Tests the deleteComment method * From bb11c8997fa446f72fe526c241dbce51a9e2d5b6 Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:09:46 +0530 Subject: [PATCH 06/11] unit tests for deleting label --- .../unit/joomla/github/JGithubIssuesTest.php | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index 1a838cee65..53a0bbc4eb 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -264,6 +264,46 @@ public function testDeleteCommentFailure() $this->object->deleteComment('joomla', 'joomla-platform', 254); } + /** + * Tests the deleteLabel method + * + * @return void + */ + public function testDeleteLabel() + { + $returnData = new stdClass; + $returnData->code = 204; + $returnData->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/labels/254') + ->will($this->returnValue($returnData)); + + $this->object->deleteLabel('joomla', 'joomla-platform', 254); + } + + /** + * Tests the deleteLabel method - failure + * + * @expectedException DomainException + * + * @return void + */ + public function testDeleteLabelFailure() + { + $returnData = new stdClass; + $returnData->code = 504; + $returnData->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('delete') + ->with('/repos/joomla/joomla-platform/issues/comments/254') + ->will($this->returnValue($returnData)); + + $this->object->deleteLabel('joomla', 'joomla-platform', 254); + } + /** * Tests the edit method * From 7dba0df231f11d546fe04f2ca2c652828557182e Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:17:10 +0530 Subject: [PATCH 07/11] unit tests for edit Label --- .../unit/joomla/github/JGithubIssuesTest.php | 59 +++++++++++++++++-- 1 file changed, 55 insertions(+), 4 deletions(-) diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index 53a0bbc4eb..902a9f7e51 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -185,8 +185,8 @@ public function testCreateLabel() $returnData->body = $this->sampleString; $issue = new stdClass; - $issue->name = 'Label'; - $issue->color = 'blue'; + $issue->name = 'My Insightful Label'; + $issue->color = 'My Insightful Color'; $this->client->expects($this->once()) ->method('post') @@ -213,8 +213,8 @@ public function testCreateLabelFailure() $returnData->body = $this->errorString; $issue = new stdClass; - $issue->name = 'Label'; - $issue->color = 'green'; + $issue->name = 'My Insightful Label'; + $issue->color = 'My Insightful Color'; $this->client->expects($this->once()) ->method('post') @@ -411,6 +411,57 @@ public function testEditCommentFailure() $this->object->editComment('joomla', 'joomla-platform', 523, 'This comment is now even more insightful'); } + /** + * Tests the editLabel method + * + * @return void + */ + public function testEditLabel() + { + $returnData = new stdClass; + $returnData->code = 200; + $returnData->body = $this->sampleString; + + $issue = new stdClass; + $issue->name = 'This label is now even more insightful'; + $issue->color = 'This color is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) + ->will($this->returnValue($returnData)); + + $this->assertThat( + $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the editComment method - failure + * + * @expectedException DomainException + * + * @return void + */ + public function testEditLabelFailure() + { + $returnData = new stdClass; + $returnData->code = 500; + $returnData->body = $this->errorString; + + $issue = new stdClass; + $issue->name = 'This label is now even more insightful'; + $issue->color = 'This color is now even more insightful'; + + $this->client->expects($this->once()) + ->method('patch') + ->with('/repos/joomla/joomla-platform/labels/523', json_encode($issue)) + ->will($this->returnValue($returnData)); + + $this->object->editLabel('joomla', 'joomla-platform', 523, 'This label is now even more insightful', 'This color is now even more insightful'); + } + /** * Tests the get method * From 534b55b207e0e8480b7e32c918784d8713c1ceef Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:27:08 +0530 Subject: [PATCH 08/11] unit test for getting labels --- .../unit/joomla/github/JGithubIssuesTest.php | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index 902a9f7e51..bc6c8c9efa 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -591,6 +591,92 @@ public function testGetCommentsFailure() $this->object->getComments('joomla', 'joomla-platform', 523); } + /** + * Tests the getLabel method + * + * @return void + */ + public function testGetLabel() + { + $returnData = new stdClass; + $returnData->code = 200; + $returnData->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') + ->will($this->returnValue($returnData)); + + $this->assertThat( + $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getLabel method - failure + * + * @expectedException DomainException + * + * @return void + */ + public function testGetLabelFailure() + { + $returnData = new stdClass; + $returnData->code = 500; + $returnData->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/issues/comments/523') + ->will($this->returnValue($returnData)); + + $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'); + } + + /** + * Tests the getLabels method + * + * @return void + */ + public function testGetLabels() + { + $returnData = new stdClass; + $returnData->code = 200; + $returnData->body = $this->sampleString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels') + ->will($this->returnValue($returnData)); + + $this->assertThat( + $this->object->getLabels('joomla', 'joomla-platform'), + $this->equalTo(json_decode($this->sampleString)) + ); + } + + /** + * Tests the getLabels method - failure + * + * @expectedException DomainException + * + * @return void + */ + public function testGetLabelsFailure() + { + $returnData = new stdClass; + $returnData->code = 500; + $returnData->body = $this->errorString; + + $this->client->expects($this->once()) + ->method('get') + ->with('/repos/joomla/joomla-platform/labels') + ->will($this->returnValue($returnData)); + + $this->object->getLabels('joomla', 'joomla-platform'); + } + /** * Tests the getList method * From a01bad6da508237651993f644bcd96e452685429 Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:30:18 +0530 Subject: [PATCH 09/11] Fixing a type in docs --- tests/suites/unit/joomla/github/JGithubIssuesTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index bc6c8c9efa..958276b7e4 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -438,7 +438,7 @@ public function testEditLabel() } /** - * Tests the editComment method - failure + * Tests the editLabel method - failure * * @expectedException DomainException * From adb008e4a17edcbf3b202ced2d630cd4776dc2cf Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:40:56 +0530 Subject: [PATCH 10/11] adding return values and fixing unittests --- libraries/joomla/github/issues.php | 5 +++-- tests/suites/unit/joomla/github/JGithubIssuesTest.php | 8 ++++---- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index 25e2dc6e90..fec0efa021 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -200,8 +200,6 @@ public function deleteLabel($user, $repo, $label) $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } - - return json_decode($response->body); } /** @@ -513,6 +511,9 @@ public function getLabels($user, $repo) $error = json_decode($response->body); throw new DomainException($error->message, $response->code); } + + + return json_decode($response->body); } /** diff --git a/tests/suites/unit/joomla/github/JGithubIssuesTest.php b/tests/suites/unit/joomla/github/JGithubIssuesTest.php index 958276b7e4..ef010c698a 100755 --- a/tests/suites/unit/joomla/github/JGithubIssuesTest.php +++ b/tests/suites/unit/joomla/github/JGithubIssuesTest.php @@ -194,7 +194,7 @@ public function testCreateLabel() ->will($this->returnValue($returnData)); $this->assertThat( - $this->object->createLabel('joomla', 'joomla-platform', 'Label', 'blue'), + $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'), $this->equalTo(json_decode($this->sampleString)) ); } @@ -221,7 +221,7 @@ public function testCreateLabelFailure() ->with('/repos/joomla/joomla-platform/labels', json_encode($issue)) ->will($this->returnValue($returnData)); - $this->object->createLabel('joomla', 'joomla-platform', 'Label', 'blue'); + $this->object->createLabel('joomla', 'joomla-platform', 'My Insightful Label', 'My Insightful Color'); } /** @@ -298,7 +298,7 @@ public function testDeleteLabelFailure() $this->client->expects($this->once()) ->method('delete') - ->with('/repos/joomla/joomla-platform/issues/comments/254') + ->with('/repos/joomla/joomla-platform/labels/254') ->will($this->returnValue($returnData)); $this->object->deleteLabel('joomla', 'joomla-platform', 254); @@ -628,7 +628,7 @@ public function testGetLabelFailure() $this->client->expects($this->once()) ->method('get') - ->with('/repos/joomla/joomla-platform/issues/comments/523') + ->with('/repos/joomla/joomla-platform/labels/My Insightful Label') ->will($this->returnValue($returnData)); $this->object->getLabel('joomla', 'joomla-platform', 'My Insightful Label'); From 7d7d8906193c24aa4e5bb614864bad7224db01d4 Mon Sep 17 00:00:00 2001 From: Prasath Nadarajah Date: Sat, 13 Oct 2012 22:41:57 +0530 Subject: [PATCH 11/11] fixing a codesniffer issue. --- libraries/joomla/github/issues.php | 1 - 1 file changed, 1 deletion(-) diff --git a/libraries/joomla/github/issues.php b/libraries/joomla/github/issues.php index fec0efa021..1f98898cdf 100644 --- a/libraries/joomla/github/issues.php +++ b/libraries/joomla/github/issues.php @@ -512,7 +512,6 @@ public function getLabels($user, $repo) throw new DomainException($error->message, $response->code); } - return json_decode($response->body); }