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

JGithub Improvements. Labels management #1124

Closed
wants to merge 14 commits into from
5 changes: 3 additions & 2 deletions libraries/joomla/github/http.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,9 @@ class JGithubHttp extends JHttp
*/
public function __construct(JRegistry $options = null, JHttpTransport $transport = null)
{
// Call the JHttp constructor to setup the object.
parent::__construct($options, $transport);
// Override the JHttp contructor to use JHttpTransportStream.
$this->options = isset($options) ? $options : new JRegistry;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you removing this? This increases the chance of breaking things when something is added to the JHttp constructor that is required.

$this->transport = isset($transport) ? $transport : new JHttpTransportStream($this->options);

// Make sure the user agent string is defined.
$this->options->def('userAgent', 'JGitHub/2.0');
Expand Down
168 changes: 168 additions & 0 deletions libraries/joomla/github/issues.php
Original file line number Diff line number Diff line change
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.1
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change these to 12.2.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And by that he means 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,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.1
*/
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.
*
Expand Down Expand Up @@ -257,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.1
*/
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 +458,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.1
*/
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.1
*/
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