From 7a8417b4891ef63e2912a0c6cb306fb84c8f56d0 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 3 Jul 2015 19:28:03 +0200 Subject: [PATCH 1/4] Work on milestones --- lib/Github/Api/Issue/Comments.php | 60 +++++++++++++++++-- lib/Github/Api/Issue/Events.php | 25 ++++++-- lib/Github/Api/Issue/Labels.php | 89 ++++++++++++++++++++++++++++- lib/Github/Api/Issue/Milestones.php | 64 ++++++++++++++++++++- 4 files changed, 225 insertions(+), 13 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index ae6370fc660..cf6b7ac32f6 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -11,28 +11,42 @@ */ class Comments extends AbstractApi { + /** + * Configure the body type. + * + * @param string $bodyType + */ public function configure($bodyType = null) { switch ($bodyType) { case 'raw': - $header = sprintf('Accept: application/vnd.github.%s.raw+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.raw+json';; break; case 'text': - $header = sprintf('Accept: application/vnd.github.%s.text+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.text+json'; break; case 'html': - $header = sprintf('Accept: application/vnd.github.%s.html+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.html+json'; break; default: - $header = sprintf('Accept: application/vnd.github.%s.full+json', $this->client->getOption('api_version')); + $header = 'Accept: application/vnd.github.%s.full+json'; } - $this->client->setHeaders(array($header)); + $this->client->setHeaders(array(sprintf($header, $this->client->getOption('api_version')))); } + /** + * Get all comments for an issue. + * + * @param string g$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 +54,29 @@ public function all($username, $repository, $issue, $page = 1) )); } + /** + * Get a comment for an issue. + * + * @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. + * + * @param string $username + * @param string $repository + * @param int $issue + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ public function create($username, $repository, $issue, array $params) { if (!isset($params['body'])) { @@ -54,6 +86,16 @@ 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. + * + * @param string $username + * @param string $repository + * @param int $comment + * @param array $params + * @return array + * @throws \Github\Exception\MissingArgumentException + */ public function update($username, $repository, $comment, array $params) { if (!isset($params['body'])) { @@ -63,6 +105,14 @@ 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. + * + * @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..33387908759 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -10,19 +10,36 @@ */ class Events extends AbstractApi { + /** + * Get all 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. + * + * @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..d65e2fb97f0 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -12,15 +12,37 @@ */ class Labels extends AbstractApi { + /** + * Get all labels for a repository or the labels for a specific 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 +55,53 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/labels', $params); } + /** + * Delete a label for a repository. + * + * @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. + * + * @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 +113,45 @@ 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. + * + * @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 + * + * @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. + * + * @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..87a2df52eb8 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -11,6 +11,15 @@ */ class Milestones extends AbstractApi { + /** + * Get all 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 +32,39 @@ 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. + * + * @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. + * + * @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 +77,16 @@ public function create($username, $repository, array $params) return $this->post('repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/milestones', $params); } + /** + * Update a milestone for a repository. + * + * @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 +96,29 @@ 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. + * + * @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 + * + * @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'); From 0dbf9e792551507fa8afdf9c573ad9d62bf5d526 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 09:14:55 +0200 Subject: [PATCH 2/4] Some fixes --- lib/Github/Api/Issue/Comments.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index cf6b7ac32f6..87ce579f970 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -14,13 +14,13 @@ class Comments extends AbstractApi /** * Configure the body type. * - * @param string $bodyType + * @param string|null $bodyType */ public function configure($bodyType = null) { switch ($bodyType) { case 'raw': - $header = 'Accept: application/vnd.github.%s.raw+json';; + $header = 'Accept: application/vnd.github.%s.raw+json'; break; case 'text': @@ -41,10 +41,11 @@ public function configure($bodyType = null) /** * Get all comments for an issue. * - * @param string g$username + * @param string $username * @param string $repository * @param int $issue * @param int $page + * * @return array */ public function all($username, $repository, $issue, $page = 1) @@ -60,6 +61,7 @@ public function all($username, $repository, $issue, $page = 1) * @param string $username * @param string $repository * @param int $comment + * * @return array */ public function show($username, $repository, $comment) @@ -74,8 +76,9 @@ public function show($username, $repository, $comment) * @param string $repository * @param int $issue * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * @return array */ public function create($username, $repository, $issue, array $params) { @@ -93,8 +96,9 @@ public function create($username, $repository, $issue, array $params) * @param string $repository * @param int $comment * @param array $params - * @return array + * * @throws \Github\Exception\MissingArgumentException + * @return array */ public function update($username, $repository, $comment, array $params) { @@ -111,6 +115,7 @@ public function update($username, $repository, $comment, array $params) * @param string $username * @param string $repository * @param int $comment + * * @return array */ public function remove($username, $repository, $comment) From d6690ee93b50a417f6dc76cda29e9b608d93b517 Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 09:28:25 +0200 Subject: [PATCH 3/4] Refactor setHeaders --- lib/Github/Api/Issue/Comments.php | 21 +++++---------------- 1 file changed, 5 insertions(+), 16 deletions(-) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 87ce579f970..8789bec439a 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -18,24 +18,13 @@ class Comments extends AbstractApi */ public function configure($bodyType = null) { - switch ($bodyType) { - case 'raw': - $header = 'Accept: application/vnd.github.%s.raw+json'; - break; - - case 'text': - $header = 'Accept: application/vnd.github.%s.text+json'; - break; - - case 'html': - $header = 'Accept: application/vnd.github.%s.html+json'; - break; - - default: - $header = 'Accept: application/vnd.github.%s.full+json'; + if (!in_array($bodyType, array('raw', 'text', 'html'))) { + $bodyType = 'full'; } - $this->client->setHeaders(array(sprintf($header, $this->client->getOption('api_version')))); + $this->client->setHeaders(array( + sprintf('Accept: application/vnd.github.%s.%s+json', $this->client->getOption('api_version'), $bodyType) + )); } /** From 26b738ce67e4cb891ea4fc069a2e894835c4b38d Mon Sep 17 00:00:00 2001 From: Lucas Michot Date: Fri, 25 Sep 2015 10:00:31 +0200 Subject: [PATCH 4/4] Add API @link --- lib/Github/Api/Issue/Comments.php | 6 ++++++ lib/Github/Api/Issue/Events.php | 2 ++ lib/Github/Api/Issue/Labels.php | 6 ++++++ lib/Github/Api/Issue/Milestones.php | 6 ++++++ 4 files changed, 20 insertions(+) diff --git a/lib/Github/Api/Issue/Comments.php b/lib/Github/Api/Issue/Comments.php index 8789bec439a..ad6a95d633b 100644 --- a/lib/Github/Api/Issue/Comments.php +++ b/lib/Github/Api/Issue/Comments.php @@ -14,6 +14,7 @@ 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) @@ -30,6 +31,7 @@ public function configure($bodyType = null) /** * 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 @@ -47,6 +49,7 @@ 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 @@ -61,6 +64,7 @@ public function show($username, $repository, $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 @@ -81,6 +85,7 @@ public function create($username, $repository, $issue, array $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 @@ -101,6 +106,7 @@ public function update($username, $repository, $comment, array $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 diff --git a/lib/Github/Api/Issue/Events.php b/lib/Github/Api/Issue/Events.php index 33387908759..1fa5dc502e3 100644 --- a/lib/Github/Api/Issue/Events.php +++ b/lib/Github/Api/Issue/Events.php @@ -13,6 +13,7 @@ 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 @@ -35,6 +36,7 @@ public function all($username, $repository, $issue = null, $page = 1) /** * Display an event for an issue. * + * @link https://developer.github.com/v3/issues/events/#get-a-single-event * @param $username * @param $repository * @param $event diff --git a/lib/Github/Api/Issue/Labels.php b/lib/Github/Api/Issue/Labels.php index d65e2fb97f0..075597ed50f 100644 --- a/lib/Github/Api/Issue/Labels.php +++ b/lib/Github/Api/Issue/Labels.php @@ -15,6 +15,7 @@ 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 @@ -58,6 +59,7 @@ public function create($username, $repository, array $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 @@ -93,6 +95,7 @@ public function update($username, $repository, $label, $newName, $color) /** * 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 @@ -116,6 +119,7 @@ public function add($username, $repository, $issue, $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 @@ -131,6 +135,7 @@ public function replace($username, $repository, $issue, array $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 @@ -146,6 +151,7 @@ public function remove($username, $repository, $issue, $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 diff --git a/lib/Github/Api/Issue/Milestones.php b/lib/Github/Api/Issue/Milestones.php index 87a2df52eb8..55ba6fed998 100644 --- a/lib/Github/Api/Issue/Milestones.php +++ b/lib/Github/Api/Issue/Milestones.php @@ -14,6 +14,7 @@ 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 @@ -43,6 +44,7 @@ public function all($username, $repository, array $params = array()) /** * 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 @@ -57,6 +59,7 @@ public function show($username, $repository, $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 @@ -80,6 +83,7 @@ public function create($username, $repository, array $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 @@ -99,6 +103,7 @@ public function update($username, $repository, $id, array $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 @@ -113,6 +118,7 @@ public function remove($username, $repository, $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