This repository has been archived by the owner. It is now read-only.

JGithublabels management #1601

Merged
merged 12 commits into from Oct 13, 2012
@@ -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.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.
*
@@ -135,6 +174,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.
*
@@ -257,6 +324,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.
*
@@ -349,6 +456,65 @@ 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);
+ }
+
+ return json_decode($response->body);
+ }
+
/**
* Method to list an authenticated user's issues.
*
Oops, something went wrong.