diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index ae6370fc660..ad6a95d633b 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -11,28 +11,34 @@ */ 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( @@ -40,11 +46,33 @@ public function all($username, $repository, $issue, $page = 1) )); } + /** + * 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'])) { @@ -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'])) { @@ -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)); diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 17bcef83921..1fa5dc502e3 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -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)); diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index bdce1437186..075597ed50f 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -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'])) { @@ -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)) { @@ -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'); diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 049e2b35a33..55ba6fed998 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -11,6 +11,16 @@ */ class Milestones extends AbstractApi { + /** + * Get all milestones for a repository. + * + * @link https://developer.github.com/v3/issues/milestones/#list-milestones-for-a-repository + * @param string $username + * @param string $repository + * @param array $params + * + * @return array + */ public function all($username, $repository, array $params = array()) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed', 'all'))) { @@ -23,14 +33,41 @@ public function all($username, $repository, array $params = array()) $params['direction'] = 'desc'; } - return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array('page' => 1, 'state' => 'open', 'sort' => 'due_date', 'direction' => 'desc'), $params)); + return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', array_merge(array( + 'page' => 1, + 'state' => 'open', + 'sort' => 'due_date', + 'direction' => 'desc' + ), $params)); } + /** + * Get a milestone for a repository. + * + * @link https://developer.github.com/v3/issues/milestones/#get-a-single-milestone + * @param string $username + * @param string $repository + * @param int $id + * + * @return array + */ public function show($username, $repository, $id) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } + /** + * Create a milestone for a repository. + * + * @link https://developer.github.com/v3/issues/milestones/#create-a-milestone + * @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['title'])) { @@ -43,6 +80,17 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } + /** + * Update a milestone for a repository. + * + * @link https://developer.github.com/v3/issues/milestones/#update-a-milestone + * @param string $username + * @param string $repository + * @param int $id + * @param array $params + * + * @return array + */ public function update($username, $repository, $id, array $params) { if (isset($params['state']) && !in_array($params['state'], array('open', 'closed'))) { @@ -52,11 +100,31 @@ public function update($username, $repository, $id, array $params) return $this->patch('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id), $params); } + /** + * Delete a milestone for a repository. + * + * @link https://developer.github.com/v3/issues/milestones/#delete-a-milestone + * @param string $username + * @param string $repository + * @param int $id + * + * @return null + */ public function remove($username, $repository, $id) { return $this->delete('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id)); } + /** + * Get the labels of a milestone + * + * @link https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone + * @param string $username + * @param string $repository + * @param int $id + * + * @return array + */ public function labels($username, $repository, $id) { return $this->get('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones/'.rawurlencode($id).'/labels');