Skip to content

Work on issues #291

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Sep 25, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 66 additions & 16 deletions lib/Github/Api/Issue/Comments.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,40 +11,68 @@
*/
class Comments extends AbstractApi
{
/**
* Configure the body type.
*
* @link https://developer.github.com/v3/issues/comments/#custom-media-types
* @param string|null $bodyType
*/
public function configure($bodyType = null)
{
switch ($bodyType) {
case 'raw':
$header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version'));
break;

case 'text':
$header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version'));
break;

case 'html':
$header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version'));
break;

default:
$header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version'));
if (!in_array($bodyType, array('raw', 'text', 'html'))) {
$bodyType = 'full';
}

$this->client->setHeaders(array($header));
$this->client->setHeaders(array(
sprintf('Accept: application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType)
));
}

/**
* Get all comments for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
* @param string $username
* @param string $repository
* @param int $issue
* @param int $page
*
* @return array
*/
public function all($username, $repository, $issue, $page = 1)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', array(
'page' => $page
));
}

/**
* Get a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#get-a-single-comment
* @param string $username
* @param string $repository
* @param int $comment
*
* @return array
*/
public function show($username, $repository, $comment)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
}

/**
* Create a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#create-a-comment
* @param string $username
* @param string $repository
* @param int $issue
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
* @return array
*/
public function create($username, $repository, $issue, array $params)
{
if (!isset($params['body'])) {
Expand All @@ -54,6 +82,18 @@ public function create($username, $repository, $issue, array $params)
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/comments', $params);
}

/**
* Update a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#edit-a-comment
* @param string $username
* @param string $repository
* @param int $comment
* @param array $params
*
* @throws \Github\Exception\MissingArgumentException
* @return array
*/
public function update($username, $repository, $comment, array $params)
{
if (!isset($params['body'])) {
Expand All @@ -63,6 +103,16 @@ public function update($username, $repository, $comment, array $params)
return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment), $params);
}

/**
* Delete a comment for an issue.
*
* @link https://developer.github.com/v3/issues/comments/#delete-a-comment
* @param string $username
* @param string $repository
* @param int $comment
*
* @return array
*/
public function remove($username, $repository, $comment)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/comments/'.rawurlencode($comment));
Expand Down
27 changes: 23 additions & 4 deletions lib/Github/Api/Issue/Events.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,38 @@
*/
class Events extends AbstractApi
{
/**
* Get all events for an issue.
*
* @link https://developer.github.com/v3/issues/events/#list-events-for-an-issue
* @param string $username
* @param string $repository
* @param int|null $issue
* @param int $page
* @return array
*/
public function all($username, $repository, $issue = null, $page = 1)
{
if (null !== $issue) {
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events', array(
'page' => $page
));
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/events';
} else {
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events';
}

return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events', array(
return $this->get($path, array(
'page' => $page
));
}

/**
* Display an event for an issue.
*
* @link https://developer.github.com/v3/issues/events/#get-a-single-event
* @param $username
* @param $repository
* @param $event
* @return array
*/
public function show($username, $repository, $event)
{
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/events/'.rawurlencode($event));
Expand Down
95 changes: 92 additions & 3 deletions lib/Github/Api/Issue/Labels.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,38 @@
*/
class Labels extends AbstractApi
{
/**
* Get all labels for a repository or the labels for a specific issue.
*
* @link https://developer.github.com/v3/issues/labels/#list-labels-on-an-issue
* @param string $username
* @param string $repository
* @param int|null $issue
*
* @return array
*/
public function all($username, $repository, $issue = null)
{
if ($issue === null) {
return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels');
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels';
} else {
$path = 'repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels';
}

return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
return $this->get($path);
}

/**
* Create a label for a repository.
*
* @param string $username
* @param string $repository
* @param array $params
*
* @return array
*
* @throws \Github\Exception\MissingArgumentException
*/
public function create($username, $repository, array $params)
{
if (!isset($params['name'])) {
Expand All @@ -33,21 +56,55 @@ public function create($username, $repository, array $params)
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params);
}

/**
* Delete a label for a repository.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
* @param string $username
* @param string $repository
* @param string $label
*
* @return array
*/
public function deleteLabel($username, $repository, $label)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label));
}

/**
* Edit a label for a repository
*
* @param string $username
* @param string $repository
* @param string $label
* @param string $newName
* @param string $color
*
* @return array
*/
public function update($username, $repository, $label, $newName, $color)
{
$params = array(
'name' => $newName,
'name' => $newName,
'color' => $color,
);

return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels/'.rawurlencode($label), $params);
}

/**
* Add a label to an issue.
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
* @param string $username
* @param string $repository
* @param int $issue
* @param string $labels
*
* @return array
*
* @thorws \Github\Exception\InvalidArgumentException
*/
public function add($username, $repository, $issue, $labels)
{
if (is_string($labels)) {
Expand All @@ -59,16 +116,48 @@ public function add($username, $repository, $issue, $labels)
return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $labels);
}

/**
* Replace labels for an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
* @param string $username
* @param string $repository
* @param int $issue
* @param array $params
*
* @return array
*/
public function replace($username, $repository, $issue, array $params)
{
return $this->put('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels', $params);
}

/**
* Remove a label for an issue
*
* @link https://developer.github.com/v3/issues/labels/#remove-a-label-from-an-issue
* @param string $username
* @param string $repository
* @param string $issue
* @param string $label
*
* @return null
*/
public function remove($username, $repository, $issue, $label)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels/'.rawurlencode($label));
}

/**
* Remove all labels from an issue.
*
* @link https://developer.github.com/v3/issues/labels/#replace-all-labels-for-an-issue
* @param string $username
* @param string $repository
* @param string $issue
*
* @return null
*/
public function clear($username, $repository, $issue)
{
return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/issues/'.rawurlencode($issue).'/labels');
Expand Down
Loading