diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..3ce5adbbd --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +.idea +vendor diff --git a/composer.json b/composer.json index 5002c8af5..1c4e1c96c 100644 --- a/composer.json +++ b/composer.json @@ -1,31 +1,39 @@ { - "name": "m4tthumphrey/php-gitlab-api", - "type": "library", - "description": "GitLab API client", - "homepage": "https://github.com/m4tthumphrey/php-gitlab-api", - "keywords": ["gitlab", "api"], - "license": "MIT", - "authors": [ - { - "name": "Matt Humphrey", - "homepage": "http://m4tt.io/" - }, - { - "name": "KnpLabs Team", - "homepage": "http://knplabs.com/" - }, - { - "name": "Thibault Duplessis", - "email": "thibault.duplessis@gmail.com", - "homepage": "http://ornicar.github.com/" - } - ], - "require": { - "php": ">=5.3.2", - "ext-curl": "*", - "kriswallsmith/buzz": ">=0.7" - }, - "autoload": { - "psr-0": { "Gitlab\\": "lib/" } - } + "name": "m4tthumphrey/php-gitlab-api", + "type": "library", + "description": "GitLab API client", + "homepage": "https://github.com/m4tthumphrey/php-gitlab-api", + "keywords": [ + "gitlab", + "api" + ], + "license": "MIT", + "authors": [ + { + "name": "Matt Humphrey", + "homepage": "http://m4tt.io/" + }, + { + "name": "KnpLabs Team", + "homepage": "http://knplabs.com/" + }, + { + "name": "Thibault Duplessis", + "email": "thibault.duplessis@gmail.com", + "homepage": "http://ornicar.github.com/" + } + ], + "require": { + "php": ">=5.3.2", + "ext-curl": "*", + "kriswallsmith/buzz": ">=0.7" + }, + "autoload": { + "psr-0": {"Gitlab\\": "lib/"} + }, + "extra":{ + "branch-alias":{ + "dev-master": "7.7.x-dev" + } + } } diff --git a/lib/Gitlab/Api/AbstractApi.php b/lib/Gitlab/Api/AbstractApi.php index 63632a3f9..7aca98400 100644 --- a/lib/Gitlab/Api/AbstractApi.php +++ b/lib/Gitlab/Api/AbstractApi.php @@ -84,4 +84,9 @@ protected function delete($path, array $parameters = array(), $requestHeaders = return $response->getContent(); } + + protected function getProjectPath($project_id) + { + return 'projects/'.urlencode($project_id).'/'; + } } diff --git a/lib/Gitlab/Api/Commits.php b/lib/Gitlab/Api/Commits.php new file mode 100644 index 000000000..d9a388a4b --- /dev/null +++ b/lib/Gitlab/Api/Commits.php @@ -0,0 +1,28 @@ +getPath($project_id); + $params = array_merge(array( + 'page' => $page, + 'per_page' => $per_page + ), $params); + + return $this->get($path, $params); + } + + public function show($project_id, $commitHash) + { + $path = $this->getPath($project_id); + return $this->get("$path/$commitHash"); + } + + private function getPath($project_id) + { + return $this->getProjectPath($project_id) . 'repository/commits'; + } +} diff --git a/lib/Gitlab/Api/MergeRequests.php b/lib/Gitlab/Api/MergeRequests.php index 99a67a9da..108354a3c 100644 --- a/lib/Gitlab/Api/MergeRequests.php +++ b/lib/Gitlab/Api/MergeRequests.php @@ -9,24 +9,24 @@ class MergeRequests extends AbstractApi const STATE_OPENED = 'opened'; const STATE_CLOSED = 'closed'; - public function all($project_id, $page = 1, $per_page = self::PER_PAGE) + public function all($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = 'created_at', $sort = 'desc') { - return $this->getMrList($project_id, $page, $per_page, self::STATE_ALL); + return $this->getMrList($project_id, $page, $per_page, $order_by, $sort, self::STATE_ALL); } - public function merged($project_id, $page = 1, $per_page = self::PER_PAGE) + public function merged($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = 'created_at', $sort = 'desc') { - return $this->getMrList($project_id, $page, $per_page, self::STATE_MERGED); + return $this->getMrList($project_id, $page, $per_page, $order_by, $sort, self::STATE_MERGED); } - public function opened($project_id, $page = 1, $per_page = self::PER_PAGE) + public function opened($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = 'created_at', $sort = 'desc') { - return $this->getMrList($project_id, $page, $per_page, self::STATE_OPENED); + return $this->getMrList($project_id, $page, $per_page, $order_by, $sort, self::STATE_OPENED); } - public function closed($project_id, $page = 1, $per_page = self::PER_PAGE) + public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = 'created_at', $sort = 'desc') { - return $this->getMrList($project_id, $page, $per_page, self::STATE_CLOSED); + return $this->getMrList($project_id, $page, $per_page, $order_by, $sort, self::STATE_CLOSED); } public function show($project_id, $mr_id) @@ -72,12 +72,14 @@ public function addComment($project_id, $mr_id, $note) )); } - protected function getMrList($project_id, $page, $per_page, $state = self::STATE_ALL) + protected function getMrList($project_id, $page, $per_page, $order_by = 'created_at', $sort = 'desc', $state = self::STATE_ALL) { return $this->get('projects/'.urlencode($project_id).'/merge_requests', array( 'page' => $page, 'per_page' => $per_page, - 'state' => $state + 'state' => $state, + 'order_by' => $order_by, + 'sort' => $sort, )); } } diff --git a/lib/Gitlab/Client.php b/lib/Gitlab/Client.php index 7ec03dedc..df824136b 100644 --- a/lib/Gitlab/Client.php +++ b/lib/Gitlab/Client.php @@ -29,6 +29,7 @@ * @property-read \Gitlab\Api\SystemHooks $hooks * @property-read \Gitlab\Api\SystemHooks $system_hooks * @property-read \Gitlab\Api\Users $users + * @property-read \Gitlab\Api\Commits $commits */ class Client { @@ -133,6 +134,10 @@ public function api($name) $api = new Api\Users($this); break; + case 'commits': + $api = new Api\Commits($this); + break; + default: throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"'); }