Skip to content
This repository has been archived by the owner on Nov 26, 2017. It is now read-only.

Commit

Permalink
Merge pull request #1601 from nprasath002/JGithubLabels
Browse files Browse the repository at this point in the history
JGithublabels management
  • Loading branch information
ianmacl committed Oct 13, 2012
2 parents 92b45de + 7d7d890 commit fa8d342
Show file tree
Hide file tree
Showing 2 changed files with 394 additions and 0 deletions.
166 changes: 166 additions & 0 deletions libraries/joomla/github/issues.php
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down Expand Up @@ -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.
*
Expand Down

0 comments on commit fa8d342

Please sign in to comment.