Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

JGithublabels management #1601

Merged
merged 12 commits into from
This page is out of date. Refresh to see the latest.
View
166 libraries/joomla/github/issues.php
@@ -108,6 +108,45 @@ public function createComment($user, $repo, $issueId, $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.3
+ */
+ 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.
*
* @param string $user The name of the owner of the GitHub repository.
@@ -136,6 +175,34 @@ 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);
+ }
+ }
+
+ /**
* Method to update an issue.
*
* @param string $user The name of the owner of the GitHub repository.
@@ -258,6 +325,46 @@ public function editComment($user, $repo, $commentId, $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.
*
* @param string $user The name of the owner of the GitHub repository.
@@ -350,6 +457,65 @@ public function getComments($user, $repo, $issueId, $page = 0, $limit = 0)
}
/**
+ * 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);
+ }
+
+ return json_decode($response->body);
+ }
+
+ /**
* Method to list an authenticated user's issues.
*
* @param string $filter The filter type: assigned, created, mentioned, subscribed.
View
228 tests/suites/unit/joomla/github/JGithubIssuesTest.php
@@ -174,6 +174,57 @@ public function testCreateCommentFailure()
}
/**
+ * Tests the createLabel method
+ *
+ * @return void
+ */
+ public function testCreateLabel()
+ {
+ $returnData = new stdClass;
+ $returnData->code = 201;
+ $returnData->body = $this->sampleString;
+
+ $issue = new stdClass;
+ $issue->name = 'My Insightful Label';
+ $issue->color = 'My Insightful Color';
+
+ $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', 'My Insightful Label', 'My Insightful Color'),
+ $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 = 'My Insightful Label';
+ $issue->color = 'My Insightful Color';
+
+ $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', 'My Insightful Label', 'My Insightful Color');
+ }
+
+ /**
* Tests the deleteComment method
*
* @return void
@@ -214,6 +265,46 @@ public function testDeleteCommentFailure()
}
/**
+ * 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/labels/254')
+ ->will($this->returnValue($returnData));
+
+ $this->object->deleteLabel('joomla', 'joomla-platform', 254);
+ }
+
+ /**
* Tests the edit method
*
* @return void
@@ -321,6 +412,57 @@ public function testEditCommentFailure()
}
/**
+ * 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 editLabel 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
*
* @return void
@@ -450,6 +592,92 @@ public function testGetCommentsFailure()
}
/**
+ * 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/labels/My Insightful Label')
+ ->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
*
* @return void
Something went wrong with that request. Please try again.