diff --git a/.gitignore b/.gitignore index 5215248460e0b7504c481e6b3277e02c57a47033..d2f90606b7cab52e0fd135ab054c53888e97bb4c 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,5 @@ trac-to-gitlab.phar -vendor/ \ No newline at end of file +!vendor/ + +vendor/* +!vendor/m4tthumphrey/ diff --git a/composer.json b/composer.json index 9a75e44aaec401a93c740892c82f8e31959c18cc..883b3355b93ebf2deb5e0612452f66c0dc1a88d0 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": ">=5.3.0", "ext-mbstring": "*", "ext-json": "*", - "m4tthumphrey/php-gitlab-api": "7.13.0", + //"m4tthumphrey/php-gitlab-api": "7.13.0", "fguillot/json-rpc": "1.0.0", "ulrichsg/getopt-php": "2.3.0" }, diff --git a/migrate.php b/migrate.php index 83ba6aaf05abdfa05778d396de014f84677d99a2..78449d54e092bc2a1cd5b24fcbf6d3e2187c0842 100755 --- a/migrate.php +++ b/migrate.php @@ -16,7 +16,7 @@ $getopt = new Getopt(array( // Both are optional, but at least must be present: array('c', 'component', Getopt::OPTIONAL_ARGUMENT, 'Migrate open tickets of a specific Trac component'), array('q', 'query', Getopt::OPTIONAL_ARGUMENT, 'Migrate all tickets matching this Trac query (e.g. "id=1234" or "status=!closed&owner=dachaz")'), - + // Trully optional array('m', 'map', Getopt::OPTIONAL_ARGUMENT, 'Map of trac usernames to git usernames in the following format "tracUserA=gitUserX,tracUserB=gitUserY"'), array('a', 'admin', Getopt::NO_ARGUMENT, 'Indicates that the GitLab token is from an admin user and as such tries to migrate the ticket reporter as well. If the reporter is not part of the provided GitLab project, the reporter will be set to the Admin user owning the token.'), @@ -57,7 +57,7 @@ try { if (!is_null($getopt->getOption('component'))) { $migration->migrateComponent($getopt->getOption('component'), $getopt->getOption('project')); } - // If we have a custom query, migrate it + // If we have a custom query, migrate it if (!is_null($getopt->getOption('query'))) { $migration->migrateQuery($getopt->getOption('query'), $getopt->getOption('project')); } @@ -93,4 +93,4 @@ function getVersion() { return $json['version']; } -?> \ No newline at end of file +?> diff --git a/src/GitLab.php b/src/GitLab.php index 621edd5fc79fb3f1486cbb845e7c2c7eb2d620ca..88f23ea0536b4847a3d553f150f27f668f3c3a22 100644 --- a/src/GitLab.php +++ b/src/GitLab.php @@ -35,7 +35,7 @@ class GitLab /** - * Tries to fetch all the users from GitLab. Will get at most + * Tries to fetch all the users from GitLab. Will get at most * (USER_FETCH_PAGE_SIZE * USER_FETCH_MAX_PAGES) users. Returns * a map of {username => userInfoObject} * @@ -63,19 +63,20 @@ class GitLab * @param mixed $projectId Numeric project id (e.g. 17) or the unique string identifier (e.g. 'dachaz/trac-to-gitlab') * @param string $title Title of the new issue * @param string $description Description of the new issue + * @param string $createdAt Custom creation date * @param int $assigneeId Numeric user id of the user asigned to the issue. Can be null. * @param int $authorId Numeric user id of the user who created the issue. Only used in admin mode. Can be null. * @param array $labels Array of string labels to be attached to the issue. Analoguous to trac keywords. * @return Gitlab\Model\Issue */ - public function createIssue($projectId, $title, $description, $assigneeId, $authorId, $labels) { + public function createIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels) { try { // Try to add, potentially as an admin (SUDO authorId) - $issue = $this->doCreateIssue($projectId, $title, $description, $assigneeId, $authorId, $labels, $this->isAdmin); + $issue = $this->doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $this->isAdmin); } catch (\Gitlab\Exception\RuntimeException $e) { // If adding has failed because of SUDO (author does not have access to the project), create an issue without SUDO (as the Admin user whose token is configured) if ($this->isAdmin) { - $issue = $this->doCreateIssue($projectId, $title, $description, $assigneeId, $authorId, $labels, false); + $issue = $this->doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, false); } else { // If adding has failed for some other reason, propagate the exception back throw $e; @@ -109,13 +110,17 @@ class GitLab return $note; } + public function createAttachment($projectId, $file) { + } + // Actually creates the issue - private function doCreateIssue($projectId, $title, $description, $assigneeId, $authorId, $labels, $isAdmin) { + private function doCreateIssue($projectId, $title, $description, $createdAt, $assigneeId, $authorId, $labels, $isAdmin) { $issueProperties = array( 'title' => $title, 'description' => $description, 'assignee_id' => $assigneeId, - 'labels' => $labels + 'labels' => $labels, + 'created_at' => $createdAt ); if ($isAdmin) { $issueProperties['sudo'] = $authorId; @@ -142,4 +147,4 @@ class GitLab return $this->url; } } -?> \ No newline at end of file +?> diff --git a/src/Migration.php b/src/Migration.php index aafab8ac60caed5dfa53c31bcdd26b742bc97cfb..6659e5d3543b1fd7f482072c3294c258d04cb51b 100644 --- a/src/Migration.php +++ b/src/Migration.php @@ -17,7 +17,7 @@ class Migration private $userMapping; // Cache private $gitLabUsers; - + /** * Constructor * @@ -85,7 +85,7 @@ class Migration $this->gitLabUsers = $this->gitLab->listUsers(); } - + /** * Performs the actual migration. * @@ -105,13 +105,18 @@ class Migration $assigneeId = is_array($gitLabAssignee) ? $gitLabAssignee['id'] : null; $creatorId = is_array($gitLabCreator) ? $gitLabCreator['id'] : null; $labels = $ticket[3]['keywords']; - - $issue = $this->gitLab->createIssue($gitLabProject, $title, $description, $assigneeId, $creatorId, $labels); + $dateCreated = $ticket[3]['time']['__jsonclass__'][1]; + $dateUpdated = $ticket[3]['_ts']; + + $attachments = $this->trac->getAttachments($originalTicketId); + print_r($attachments); + + $issue = $this->gitLab->createIssue($gitLabProject, $title, $description, $dateCreated, $assigneeId, $creatorId, $labels); echo 'Created a GitLab issue #' . $issue['iid'] . ' for Trac ticket #' . $originalTicketId . ' : ' . $this->gitLab->getUrl() . '/' . $gitLabProject . '/issues/' . $issue['iid'] . "\n"; // If there are comments on the ticket, create notes on the issue - if (is_array($ticket[4]) && count($ticket[4])) { + /*if (is_array($ticket[4]) && count($ticket[4])) { foreach($ticket[4] as $comment) { $commentAuthor = $this->getGitLabUser($comment['author']); $commentAuthorId = is_array($commentAuthor) ? $commentAuthor['id'] : null; @@ -119,7 +124,7 @@ class Migration $note = $this->gitLab->createNote($gitLabProject, $issue['id'], $commentText, $commentAuthorId); } echo "\tAlso created " . count($ticket[4]) . " note(s)\n"; - } + }*/ } } @@ -211,4 +216,4 @@ class Migration } -?> \ No newline at end of file +?> diff --git a/src/Trac.php b/src/Trac.php index 02e2bb6b85bcfd29e981afc0e005da88752c83da..f263dee47c78464e6fe4245ac5bdbce3e2bbac57 100644 --- a/src/Trac.php +++ b/src/Trac.php @@ -13,7 +13,7 @@ class Trac { private $client; private $url; - + /** * Constructor * @@ -63,6 +63,22 @@ class Trac return $this->client->execute('ticket.get', array($id)); } + public function getAttachments($id) { + $result = []; + $attachments = $this->client->execute('ticket.listAttachments', [$id]); + + foreach ($attachments as $attachment) { + $result[] = [ + 'filename' => $attachment[0], + 'content' => $this->client->execute('ticket.getAttachment', [$id, $attachment[0]]), + 'author' => $attachment[4] + ]; + + } + + return $result; + } + /** * Returns an array of comments on an individual ticket. * Each individual comment is itself an associative array of [time, author, text] @@ -93,4 +109,4 @@ class Trac return $this->url; } } -?> \ No newline at end of file +?> diff --git a/vendor/m4tthumphrey/php-gitlab-api/.travis.yml b/vendor/m4tthumphrey/php-gitlab-api/.travis.yml new file mode 100644 index 0000000000000000000000000000000000000000..17367d5ba6c166ba50df64873f21710e0128296b --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/.travis.yml @@ -0,0 +1,15 @@ +language: php + +php: + - 5.3.3 + - 5.3 + - 5.4 + - 5.5 + - 5.6 + +before_script: + - travis_retry composer self-update + - travis_retry composer install --no-interaction --prefer-source + +script: + - vendor/bin/phpunit --verbose --coverage-text diff --git a/vendor/m4tthumphrey/php-gitlab-api/README.md b/vendor/m4tthumphrey/php-gitlab-api/README.md new file mode 100644 index 0000000000000000000000000000000000000000..157474446d98b127386dc2b7da8e30e7d26af079 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/README.md @@ -0,0 +1,98 @@ +A PHP wrapper for use with the [Gitlab API](https://github.com/gitlabhq/gitlabhq/tree/master/doc/api). +============== + +[](https://travis-ci.org/m4tthumphrey/php-gitlab-api) + +Based on [php-github-api](https://github.com/m4tthumphrey/php-github-api) and code from [KnpLabs](https://github.com/KnpLabs/php-github-api). + +Installation +------------ +Install Composer + +``` +$ curl -sS https://getcomposer.org/installer | php +$ sudo mv composer.phar /usr/local/bin/composer +``` + +Add the following to your require block in composer.json config. Note: be careful when using the `dev-master` tag as this may have unexpected results depending on your version of Gitlab. See the Versioning section below for more information. + +``` +"m4tthumphrey/php-gitlab-api": "dev-master" +``` + +Include Composer's autoloader: + + +```php +require_once dirname(__DIR__).'/vendor/autoload.php'; +``` + +Versioning +---------- + +From the 6.0 stable release of Gitlab, I shall now be matching the client version with the Gitlab version. For example when Gitlab 6.1 is released I will release version 6.1.0 of the API client. If I need to make future updates to the client before the next API version is released. I will simply use a 3th build version. For example `6.1.1`, `6.1.2` etc. It is recommended that you keep your composer file up to date depending on what version of Gitlab you are currently running. So if you are using 6.0, you should required `6.0.*`; 6.1 should be `6.1.*` etc etc. + +General API Usage +----------------- + +```php +$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here +$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here + +$project = $client->api('projects')->create('My Project', array( + 'description' => 'This is a project', + 'issues_enabled' => false +)); + +``` + +Model Usage +----------- + +You can also use the library in an object oriented manner. + +```php +$client = new \Gitlab\Client('http://git.yourdomain.com/api/v3/'); // change here +$client->authenticate('your_gitlab_token_here', \Gitlab\Client::AUTH_URL_TOKEN); // change here +``` + +Creating a new project + +```php +$project = \Gitlab\Model\Project::create($client, 'My Project', array( + 'description' => 'This is my project', + 'issues_enabled' => false +)); + +$project->addHook('http://mydomain.com/hook/push/1'); +``` + +Creating a new issue + +```php +$project = new \Gitlab\Model\Project(1, $client); +$issue = $project->createIssue('This does not work..', array( + 'description' => 'This doesnt work properly. Please fix', + 'assignee_id' => 2 +)); +``` + +Closing that issue + +```php +$issue->close(); +``` + +You get the idea! Take a look around and please feel free to report any bugs. + +Framework Integrations +---------------------- +- **Symfony** - https://github.com/Zeichen32/GitLabApiBundle +- **Laravel** - https://github.com/vinkla/gitlab + +If you have integrated GitLab into a popular PHP framework let us know! + +Contributing +------------ + +There are many parts of Gitlab that I have not added to this as it was originally created for personal use, hence the lack of tests. Feel free to fork and add new functionality and tests, I'll gladly accept decent pull requests. diff --git a/vendor/m4tthumphrey/php-gitlab-api/composer.json b/vendor/m4tthumphrey/php-gitlab-api/composer.json new file mode 100644 index 0000000000000000000000000000000000000000..7a18f08754f47b41ec39183ec8c7cc1afeb8842d --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/composer.json @@ -0,0 +1,34 @@ +{ + "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" + }, + "require-dev": { + "phpunit/phpunit": "~4.5" + }, + "autoload": { + "psr-0": { "Gitlab\\": "lib/" } + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/AbstractApi.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/AbstractApi.php new file mode 100644 index 0000000000000000000000000000000000000000..71b91e0c5cb0bbf6e0757497dfdbbe39b7aaa332 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/AbstractApi.php @@ -0,0 +1,127 @@ +<?php namespace Gitlab\Api; + +use Gitlab\Client; + +/** + * Abstract class for Api classes + * + * @author Joseph Bielawski <stloyd@gmail.com> + * @author Matt Humphrey <matt@m4tt.co> + */ +abstract class AbstractApi +{ + /** + * Default entries per page + */ + const PER_PAGE = 20; + + /** + * The client + * + * @var Client + */ + protected $client; + + /** + * @param Client $client + */ + public function __construct(Client $client) + { + $this->client = $client; + } + + /** + * @return $this + * @codeCoverageIgnore + */ + public function configure() + { + return $this; + } + + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return mixed + */ + protected function get($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); + + return $response->getContent(); + } + + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return mixed + */ + protected function post($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->post($path, $parameters, $requestHeaders); + + return $response->getContent(); + } + + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return mixed + */ + protected function patch($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders); + + return $response->getContent(); + } + + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return mixed + */ + protected function put($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->put($path, $parameters, $requestHeaders); + + return $response->getContent(); + } + + /** + * @param string $path + * @param array $parameters + * @param array $requestHeaders + * @return mixed + */ + protected function delete($path, array $parameters = array(), $requestHeaders = array()) + { + $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); + + return $response->getContent(); + } + + /** + * @param int $id + * @param string $path + * @return string + */ + protected function getProjectPath($id, $path) + { + return 'projects/'.$this->encodePath($id).'/'.$path; + } + + /** + * @param string $path + * @return string + */ + protected function encodePath($path) + { + $path = rawurlencode($path); + + return str_replace('.', '%2E', $path); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Groups.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Groups.php new file mode 100644 index 0000000000000000000000000000000000000000..551034f9aaba7e7b2507d0060e13a7b84bc2ba0d --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Groups.php @@ -0,0 +1,125 @@ +<?php namespace Gitlab\Api; + +class Groups extends AbstractApi +{ + /** + * @param int $page + * @param int $per_page + * @return mixed + */ + public function all($page = 1, $per_page = self::PER_PAGE) + { + return $this->get('groups', array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param string $query + * @param int $page + * @param int $per_page + * @return mixed + */ + public function search($query, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get('groups?search='.$this->encodePath($query), array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $id + * @return mixed + */ + public function show($id) + { + return $this->get('groups/'.$this->encodePath($id)); + } + + /** + * @param string $name + * @param string $path + * @param string $description + * @return mixed + */ + public function create($name, $path, $description = null) + { + return $this->post('groups', array( + 'name' => $name, + 'path' => $path, + 'description' => $description + )); + } + + /** + * @param int $group_id + * @return mixed + */ + public function remove($group_id) + { + return $this->delete('groups/'.$this->encodePath($group_id)); + } + + /** + * @param int $group_id + * @param int $project_id + * @return mixed + */ + public function transfer($group_id, $project_id) + { + return $this->post('groups/'.$this->encodePath($group_id).'/projects/'.$this->encodePath($project_id)); + } + + /** + * @param int $id + * @param int $page + * @param int $per_page + * @return mixed + */ + public function members($id, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get('groups/'.$this->encodePath($id).'/members', array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $group_id + * @param int $user_id + * @param int $access_level + * @return mixed + */ + public function addMember($group_id, $user_id, $access_level) + { + return $this->post('groups/'.$this->encodePath($group_id).'/members', array( + 'user_id' => $user_id, + 'access_level' => $access_level + )); + } + + /** + * @param int $group_id + * @param int $user_id + * @param int $access_level + * @return mixed + */ + public function saveMember($group_id, $user_id, $access_level) + { + return $this->put('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id), array( + 'access_level' => $access_level + )); + } + + /** + * @param int $group_id + * @param int $user_id + * @return mixed + */ + public function removeMember($group_id, $user_id) + { + return $this->delete('groups/'.$this->encodePath($group_id).'/members/'.$this->encodePath($user_id)); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Issues.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Issues.php new file mode 100644 index 0000000000000000000000000000000000000000..86dd78b4bc98f9601626912670d5cbb95b671e93 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Issues.php @@ -0,0 +1,108 @@ +<?php namespace Gitlab\Api; + +class Issues extends AbstractApi +{ + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param array $params + * @return mixed + */ + public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, array $params = array()) + { + $path = $project_id === null ? 'issues' : $this->getProjectPath($project_id, 'issues'); + + $params = array_intersect_key($params, array('labels' => '', 'state' => '', 'sort' => '', 'order_by' => '')); + $params = array_merge(array( + 'page' => $page, + 'per_page' => $per_page + ), $params); + + return $this->get($path, $params); + } + + /** + * @param int $project_id + * @param int $issue_id + * @return mixed + */ + public function show($project_id, $issue_id) + { + return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id))); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function create($project_id, array $params) + { + return $this->post($this->getProjectPath($project_id, 'issues'), $params); + } + + /** + * @param int $project_id + * @param int $issue_id + * @param array $params + * @return mixed + */ + public function update($project_id, $issue_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)), $params); + } + + /** + * @param int $project_id + * @param int $issue_id + * @return mixed + */ + public function showComments($project_id, $issue_id) + { + return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes'); + } + + /** + * @param int $project_id + * @param int $issue_id + * @param int $note_id + * @return mixed + */ + public function showComment($project_id, $issue_id, $note_id) + { + return $this->get($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id)).'/notes/'.$this->encodePath($note_id)); + } + + /** + * @param int $project_id + * @param int $issue_id + * @param string|array $body + * @return mixed + */ + public function addComment($project_id, $issue_id, $body) + { + // backwards compatibility + if (is_array($body)) { + $params = $body; + } else { + $params = array('body' => $body); + } + + return $this->post($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes'), $params); + } + + /** + * @param int $project_id + * @param int $issue_id + * @param int $note_id + * @param string $body + * @return mixed + */ + public function updateComment($project_id, $issue_id, $note_id, $body) + { + return $this->put($this->getProjectPath($project_id, 'issues/'.$this->encodePath($issue_id).'/notes/'.$this->encodePath($note_id)), array( + 'body' => $body + )); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/MergeRequests.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/MergeRequests.php new file mode 100644 index 0000000000000000000000000000000000000000..d7ef4c156cb132f27675ddb9c45930a0f5a8880d --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/MergeRequests.php @@ -0,0 +1,177 @@ +<?php namespace Gitlab\Api; + +class MergeRequests extends AbstractApi +{ + const STATE_ALL = 'all'; + const STATE_MERGED = 'merged'; + const STATE_OPENED = 'opened'; + const STATE_CLOSED = 'closed'; + + const ORDER_BY = 'created_at'; + const SORT = 'asc'; + + /** + * @param int $project_id + * @param string $state + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function getList($project_id, $state = self::STATE_ALL, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->get($this->getProjectPath($project_id, 'merge_requests'), array( + 'page' => $page, + 'per_page' => $per_page, + 'state' => $state, + 'order_by' => $order_by, + 'sort' => $sort + )); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function all($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->getList($project_id, self::STATE_ALL, $page, $per_page, $order_by, $sort); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function merged($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->getList($project_id, self::STATE_MERGED, $page, $per_page, $order_by, $sort); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function opened($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->getList($project_id, self::STATE_OPENED, $page, $per_page, $order_by, $sort); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function closed($project_id, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->getList($project_id, self::STATE_CLOSED, $page, $per_page, $order_by, $sort); + } + + /** + * @param int $project_id + * @param int $mr_id + * @return mixed + */ + public function show($project_id, $mr_id) + { + return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id))); + } + + /** + * @param int $project_id + * @param string $source + * @param string $target + * @param string $title + * @param int $assignee + * @param int $target_project_id + * @param string $description + * @return mixed + */ + public function create($project_id, $source, $target, $title, $assignee = null, $target_project_id = null, $description = null) + { + return $this->post($this->getProjectPath($project_id, 'merge_requests'), array( + 'source_branch' => $source, + 'target_branch' => $target, + 'title' => $title, + 'assignee_id' => $assignee, + 'target_project_id' => $target_project_id, + 'description' => $description + )); + } + + /** + * @param int $project_id + * @param int $mr_id + * @param array $params + * @return mixed + */ + public function update($project_id, $mr_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id)), $params); + } + + /** + * @param int $project_id + * @param int $mr_id + * @param string $message + * @return mixed + */ + public function merge($project_id, $mr_id, $message = null) + { + if (is_array($message)) { + $params = $message; + } else { + $params = array('merge_commit_message' => $message); + } + + return $this->put($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/merge'), $params); + } + + /** + * @param int $project_id + * @param int $mr_id + * @return mixed + */ + public function showComments($project_id, $mr_id) + { + return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments')); + } + + /** + * @param int $project_id + * @param int $mr_id + * @param int $note + * @return mixed + */ + public function addComment($project_id, $mr_id, $note) + { + return $this->post($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/comments'), array( + 'note' => $note + )); + } + + /** + * @param int $project_id + * @param int $mr_id + * @return mixed + */ + public function changes($project_id, $mr_id) + { + return $this->get($this->getProjectPath($project_id, 'merge_request/'.$this->encodePath($mr_id).'/changes')); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Milestones.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Milestones.php new file mode 100644 index 0000000000000000000000000000000000000000..3b15281834e07651e1a2cb6d75504beaf78629ac --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Milestones.php @@ -0,0 +1,59 @@ +<?php namespace Gitlab\Api; + +class Milestones extends AbstractApi +{ + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @return mixed + */ + public function all($project_id, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get($this->getProjectPath($project_id, 'milestones'), array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $project_id + * @param int $milestone_id + * @return mixed + */ + public function show($project_id, $milestone_id) + { + return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id))); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function create($project_id, array $params) + { + return $this->post($this->getProjectPath($project_id, 'milestones'), $params); + } + + /** + * @param int $project_id + * @param int $milestone_id + * @param array $params + * @return mixed + */ + public function update($project_id, $milestone_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id)), $params); + } + + /** + * @param int $project_id + * @param int $milestone_id + * @return mixed + */ + public function issues($project_id, $milestone_id) + { + return $this->get($this->getProjectPath($project_id, 'milestones/'.$this->encodePath($milestone_id).'/issues')); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/ProjectNamespaces.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/ProjectNamespaces.php new file mode 100644 index 0000000000000000000000000000000000000000..480fa79c88097df77b99386a32e408f67552f070 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/ProjectNamespaces.php @@ -0,0 +1,32 @@ +<?php namespace Gitlab\Api; + +class ProjectNamespaces extends AbstractApi +{ + /** + * @param int $page + * @param int $per_page + * @return mixed + */ + public function all($page = 1, $per_page = self::PER_PAGE) + { + return $this->get('namespaces', array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param string $terms + * @param int $page + * @param int $per_page + * @return mixed + */ + public function search($terms, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get('namespaces', array( + 'search' => $terms, + 'page' => $page, + 'per_page' => $per_page + )); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Projects.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Projects.php new file mode 100644 index 0000000000000000000000000000000000000000..45104d5083e50319726c290748b44a519a551928 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Projects.php @@ -0,0 +1,388 @@ +<?php namespace Gitlab\Api; + +class Projects extends AbstractApi +{ + const ORDER_BY = 'created_at'; + const SORT = 'asc'; + + /** + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function all($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->get('projects/all', array( + 'page' => $page, + 'per_page' => $per_page, + 'order_by' => $order_by, + 'sort' => $sort + )); + } + + /** + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function accessible($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->get('projects', array( + 'page' => $page, + 'per_page' => $per_page, + 'order_by' => $order_by, + 'sort' => $sort + )); + } + + /** + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function owned($page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->get('projects/owned', array( + 'page' => $page, + 'per_page' => $per_page, + 'order_by' => $order_by, + 'sort' => $sort + )); + } + + /** + * @param string $query + * @param int $page + * @param int $per_page + * @param string $order_by + * @param string $sort + * @return mixed + */ + public function search($query, $page = 1, $per_page = self::PER_PAGE, $order_by = self::ORDER_BY, $sort = self::SORT) + { + return $this->get('projects/search/'.$this->encodePath($query), array( + 'page' => $page, + 'per_page' => $per_page, + 'order_by' => $order_by, + 'sort' => $sort + )); + } + + /** + * @param int $project_id + * @return mixed + */ + public function show($project_id) + { + return $this->get('projects/'.$this->encodePath($project_id)); + } + + /** + * @param string $name + * @param array $params + * @return mixed + */ + public function create($name, array $params = array()) + { + $params['name'] = $name; + + return $this->post('projects', $params); + } + + /** + * @param int $user_id + * @param string $name + * @param array $params + * @return mixed + */ + public function createForUser($user_id, $name, array $params = array()) + { + $params['name'] = $name; + + return $this->post('projects/user/'.$this->encodePath($user_id), $params); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function update($project_id, array $params) + { + return $this->put('projects/'.$this->encodePath($project_id), $params); + } + + /** + * @param int $project_id + * @return mixed + */ + public function remove($project_id) + { + return $this->delete('projects/'.$this->encodePath($project_id)); + } + + /** + * @param int $project_id + * @param string $username_query + * @return mixed + */ + public function members($project_id, $username_query = null) + { + return $this->get($this->getProjectPath($project_id, 'members'), array( + 'query' => $username_query + )); + } + + /** + * @param int $project_id + * @param int $user_id + * @return mixed + */ + public function member($project_id, $user_id) + { + return $this->get($this->getProjectPath($project_id, 'members/'.$this->encodePath($user_id))); + } + + /** + * @param int $project_id + * @param int $user_id + * @param int $access_level + * @return mixed + */ + public function addMember($project_id, $user_id, $access_level) + { + return $this->post($this->getProjectPath($project_id, 'members'), array( + 'user_id' => $user_id, + 'access_level' => $access_level + )); + } + + /** + * @param int $project_id + * @param int $user_id + * @param int $access_level + * @return mixed + */ + public function saveMember($project_id, $user_id, $access_level) + { + return $this->put($this->getProjectPath($project_id, 'members/'.urldecode($user_id)), array( + 'access_level' => $access_level + )); + } + + /** + * @param int $project_id + * @param int $user_id + * @return mixed + */ + public function removeMember($project_id, $user_id) + { + return $this->delete($this->getProjectPath($project_id, 'members/'.urldecode($user_id))); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @return mixed + */ + public function hooks($project_id, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get($this->getProjectPath($project_id, 'hooks'), array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $project_id + * @param int $hook_id + * @return mixed + */ + public function hook($project_id, $hook_id) + { + return $this->get($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id))); + } + + /** + * @param int $project_id + * @param string $url + * @param array $params + * @return mixed + */ + public function addHook($project_id, $url, array $params = array()) + { + if (empty($params)) { + $params = array('push_events' => true); + } + + $params['url'] = $url; + + return $this->post($this->getProjectPath($project_id, 'hooks'), $params); + } + + /** + * @param int $project_id + * @param int $hook_id + * @param array $params + * @return mixed + */ + public function updateHook($project_id, $hook_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id)), $params); + } + + /** + * @param int $project_id + * @param int $hook_id + * @return mixed + */ + public function removeHook($project_id, $hook_id) + { + return $this->delete($this->getProjectPath($project_id, 'hooks/'.$this->encodePath($hook_id))); + } + + /** + * @param int $project_id + * @return mixed + */ + public function keys($project_id) + { + return $this->get($this->getProjectPath($project_id, 'keys')); + } + + /** + * @param int $project_id + * @param int $key_id + * @return mixed + */ + public function key($project_id, $key_id) + { + return $this->get($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id))); + } + + /** + * @param int $project_id + * @param string $title + * @param string $key + * @return mixed + */ + public function addKey($project_id, $title, $key) + { + return $this->post($this->getProjectPath($project_id, 'keys'), array( + 'title' => $title, + 'key' => $key + )); + } + + /** + * @param int $project_id + * @param int $key_id + * @return mixed + */ + public function removeKey($project_id, $key_id) + { + return $this->delete($this->getProjectPath($project_id, 'keys/'.$this->encodePath($key_id))); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @return mixed + */ + public function events($project_id, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get($this->getProjectPath($project_id, 'events'), array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $project_id + * @return mixed + */ + public function labels($project_id) + { + return $this->get($this->getProjectPath($project_id, 'labels')); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function addLabel($project_id, array $params) + { + return $this->post($this->getProjectPath($project_id, 'labels'), $params); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function updateLabel($project_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'labels'), $params); + } + + /** + * @param int $project_id + * @param string $name + * @return mixed + */ + public function removeLabel($project_id, $name) + { + return $this->delete($this->getProjectPath($project_id, 'labels'), array( + 'name' => $name + )); + } + + /** + * @param int $project_id + * @param int $forked_project_id + * @return mixed + */ + public function createForkRelation($project_id, $forked_project_id) + { + return $this->post($this->getProjectPath($project_id, 'fork/'.$this->encodePath($forked_project_id))); + } + + /** + * @param int $project_id + * @return mixed + */ + public function removeForkRelation($project_id) + { + return $this->delete($this->getProjectPath($project_id, 'fork')); + } + + /** + * @param int $project_id + * @param string $service_name + * @param array $params + * @return mixed + */ + public function setService($project_id, $service_name, array $params = array()) + { + return $this->put($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name)), $params); + } + + /** + * @param int $project_id + * @param string $service_name + * @return mixed + */ + public function removeService($project_id, $service_name) + { + return $this->delete($this->getProjectPath($project_id, 'services/'.$this->encodePath($service_name))); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Repositories.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Repositories.php new file mode 100644 index 0000000000000000000000000000000000000000..83e91eff52ab9efee45e14b104b922f766e37a9c --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Repositories.php @@ -0,0 +1,284 @@ +<?php namespace Gitlab\Api; + +class Repositories extends AbstractApi +{ + /** + * @param int $project_id + * @return mixed + */ + public function branches($project_id) + { + return $this->get($this->getProjectPath($project_id, 'repository/branches')); + } + + /** + * @param int $project_id + * @param int $branch_id + * @return mixed + */ + public function branch($project_id, $branch_id) + { + return $this->get($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_id))); + } + + /** + * @param int $project_id + * @param string $branch_name + * @param string $ref + * @return mixed + */ + public function createBranch($project_id, $branch_name, $ref) + { + return $this->post($this->getProjectPath($project_id, 'repository/branches'), array( + 'branch_name' => $branch_name, + 'ref' => $ref + )); + } + + /** + * @param int $project_id + * @param string $branch_name + * @return mixed + */ + public function deleteBranch($project_id, $branch_name) + { + return $this->delete($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name))); + } + + /** + * @param int $project_id + * @param string $branch_name + * @return mixed + */ + public function protectBranch($project_id, $branch_name) + { + return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/protect')); + } + + /** + * @param int $project_id + * @param string $branch_name + * @return mixed + */ + public function unprotectBranch($project_id, $branch_name) + { + return $this->put($this->getProjectPath($project_id, 'repository/branches/'.$this->encodeBranch($branch_name).'/unprotect')); + } + + /** + * @param int $project_id + * @return mixed + */ + public function tags($project_id) + { + return $this->get($this->getProjectPath($project_id, 'repository/tags')); + } + + /** + * @param int $project_id + * @param string $name + * @param string $ref + * @param string $message + * @return mixed + */ + public function createTag($project_id, $name, $ref, $message = null) + { + return $this->post($this->getProjectPath($project_id, 'repository/tags'), array( + 'tag_name' => $name, + 'ref' => $ref, + 'message' => $message + )); + } + + /** + * @param int $project_id + * @param int $page + * @param int $per_page + * @param null $ref_name + * @return mixed + */ + public function commits($project_id, $page = 0, $per_page = self::PER_PAGE, $ref_name = null) + { + return $this->get($this->getProjectPath($project_id, 'repository/commits'), array( + 'page' => $page, + 'per_page' => $per_page, + 'ref_name' => $ref_name + )); + } + + /** + * @param int $project_id + * @param $sha + * @return mixed + */ + public function commit($project_id, $sha) + { + return $this->get($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha))); + } + + /** + * @param int $project_id + * @param string $sha + * @param int $page + * @param int $per_page + * @return mixed + */ + public function commitComments($project_id, $sha, $page = 0, $per_page = self::PER_PAGE) + { + return $this->get($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha).'/comments'), array( + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $project_id + * @param string $sha + * @param string $note + * @param array $params + * @return mixed + */ + public function createCommitComment($project_id, $sha, $note, array $params = array()) + { + $params['note'] = $note; + + return $this->post($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha).'/comments'), $params); + } + + /** + * @param int $project_id + * @param string $fromShaOrMaster + * @param string $toShaOrMaster + * @return mixed + */ + public function compare($project_id, $fromShaOrMaster, $toShaOrMaster) + { + return $this->get($this->getProjectPath( + $project_id, + 'repository/compare?from='.$this->encodeBranch($fromShaOrMaster).'&to='.$this->encodeBranch($toShaOrMaster) + )); + } + + /** + * @param int $project_id + * @param string $sha + * @return string + */ + public function diff($project_id, $sha) + { + return $this->get($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha).'/diff')); + } + + /** + * @param int $project_id + * @param array $params + * @return mixed + */ + public function tree($project_id, array $params = array()) + { + return $this->get($this->getProjectPath($project_id, 'repository/tree'), $params); + } + + /** + * @param int $project_id + * @param string $sha + * @param string $filepath + * @return mixed + */ + public function blob($project_id, $sha, $filepath) + { + return $this->get($this->getProjectPath($project_id, 'repository/commits/'.$this->encodePath($sha).'/blob'), array( + 'filepath' => $filepath + )); + } + + /** + * @param int $project_id + * @param string $file_path + * @param string $ref + * @return mixed + */ + public function getFile($project_id, $file_path, $ref) + { + return $this->get($this->getProjectPath($project_id, 'repository/files'), array( + 'file_path' => $file_path, + 'ref' => $ref + )); + } + + /** + * @param int $project_id + * @param string $file_path + * @param string $content + * @param string $branch_name + * @param string $commit_message + * @param string $encoding + * @return mixed + */ + public function createFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null) + { + return $this->post($this->getProjectPath($project_id, 'repository/files'), array( + 'file_path' => $file_path, + 'branch_name' => $branch_name, + 'content' => $content, + 'commit_message' => $commit_message, + 'encoding' => $encoding + )); + } + + /** + * @param int $project_id + * @param string $file_path + * @param string $content + * @param string $branch_name + * @param string $commit_message + * @param string $encoding + * @return mixed + */ + public function updateFile($project_id, $file_path, $content, $branch_name, $commit_message, $encoding = null) + { + return $this->put($this->getProjectPath($project_id, 'repository/files'), array( + 'file_path' => $file_path, + 'branch_name' => $branch_name, + 'content' => $content, + 'commit_message' => $commit_message, + 'encoding' => $encoding + )); + } + + /** + * @param int $project_id + * @param string $file_path + * @param string $branch_name + * @param string $commit_message + * @return mixed + */ + public function deleteFile($project_id, $file_path, $branch_name, $commit_message) + { + return $this->delete($this->getProjectPath($project_id, 'repository/files'), array( + 'file_path' => $file_path, + 'branch_name' => $branch_name, + 'commit_message' => $commit_message + )); + } + + /** + * @param int $project_id + * @return mixed + */ + public function contributors($project_id) + { + return $this->get($this->getProjectPath($project_id, 'repository/contributors')); + } + + /** + * @param string $path + * @return string + */ + protected function encodeBranch($path) + { + $path = $this->encodePath($path); + + return str_replace('%2F', '/', $path); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Snippets.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Snippets.php new file mode 100644 index 0000000000000000000000000000000000000000..00921128c8922b3354885c8ddf48a27b08d165f0 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Snippets.php @@ -0,0 +1,70 @@ +<?php namespace Gitlab\Api; + +class Snippets extends AbstractApi +{ + /** + * @param int $project_id + * @return mixed + */ + public function all($project_id) + { + return $this->get($this->getProjectPath($project_id, 'snippets')); + } + + /** + * @param int $project_id + * @param int $snippet_id + * @return mixed + */ + public function show($project_id, $snippet_id) + { + return $this->get($this->getProjectPath($project_id, 'snippets/'.$this->encodePath($snippet_id))); + } + + /** + * @param int $project_id + * @param string $title + * @param string $filename + * @param string $code + * @return mixed + */ + public function create($project_id, $title, $filename, $code) + { + return $this->post($this->getProjectPath($project_id, 'snippets'), array( + 'title' => $title, + 'file_name' => $filename, + 'code' => $code + )); + } + + /** + * @param int $project_id + * @param int $snippet_id + * @param array $params + * @return mixed + */ + public function update($project_id, $snippet_id, array $params) + { + return $this->put($this->getProjectPath($project_id, 'snippets/'.$this->encodePath($snippet_id)), $params); + } + + /** + * @param int $project_id + * @param int $snippet_id + * @return string + */ + public function content($project_id, $snippet_id) + { + return $this->get($this->getProjectPath($project_id, 'snippets/'.$this->encodePath($snippet_id).'/raw')); + } + + /** + * @param int $project_id + * @param int $snippet_id + * @return mixed + */ + public function remove($project_id, $snippet_id) + { + return $this->delete($this->getProjectPath($project_id, 'snippets/'.$this->encodePath($snippet_id))); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/SystemHooks.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/SystemHooks.php new file mode 100644 index 0000000000000000000000000000000000000000..b21fd0908ffc06c29befeff674a3432fcfd7b888 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/SystemHooks.php @@ -0,0 +1,41 @@ +<?php namespace Gitlab\Api; + +class SystemHooks extends AbstractApi +{ + /** + * @return mixed + */ + public function all() + { + return $this->get('hooks'); + } + + /** + * @param string $url + * @return mixed + */ + public function create($url) + { + return $this->post('hooks', array( + 'url' => $url + )); + } + + /** + * @param int $id + * @return mixed + */ + public function test($id) + { + return $this->get('hooks/'.$this->encodePath($id)); + } + + /** + * @param int $id + * @return mixed + */ + public function remove($id) + { + return $this->delete('hooks/'.$this->encodePath($id)); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Users.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Users.php new file mode 100644 index 0000000000000000000000000000000000000000..2fa1d88c3799c86153f9eed609d4d8ec0ea67343 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Api/Users.php @@ -0,0 +1,210 @@ +<?php namespace Gitlab\Api; + +class Users extends AbstractApi +{ + /** + * @param null|true $active + * @param int $page + * @param int $per_page + * @return mixed + */ + public function all($active = null, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get('users', array( + 'active' => $active, + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param string $query + * @param null|true $active + * @param int $page + * @param int $per_page + * @return mixed + */ + public function search($query, $active = null, $page = 1, $per_page = self::PER_PAGE) + { + return $this->get('users', array( + 'search' => $query, + 'active' => $active, + 'page' => $page, + 'per_page' => $per_page + )); + } + + /** + * @param int $id + * @return mixed + */ + public function show($id) + { + return $this->get('users/'.$this->encodePath($id)); + } + + /** + * @param string $email + * @param string $password + * @param array $params + * @return mixed + */ + public function create($email, $password, array $params = array()) + { + $params['email'] = $email; + $params['password'] = $password; + + return $this->post('users', $params); + } + + /** + * @param int $id + * @param array $params + * @return mixed + */ + public function update($id, array $params) + { + return $this->put('users/'.$this->encodePath($id), $params); + } + + /** + * @param int $id + * @return mixed + */ + public function remove($id) + { + return $this->delete('users/'.$this->encodePath($id)); + } + + /** + * @param int $id + * @return mixed + */ + public function block($id) + { + return $this->put('users/'.$this->encodePath($id).'/block'); + } + + /** + * @param int $id + * @return mixed + */ + public function unblock($id) + { + return $this->put('users/'.$this->encodePath($id).'/unblock'); + } + + /** + * @param string $emailOrUsername + * @param string $password + * @return mixed + */ + public function session($emailOrUsername, $password) + { + return $this->post('session', array( + 'login' => $emailOrUsername, + 'email' => $emailOrUsername, + 'password' => $password + )); + } + + /** + * @param string $email + * @param string $password + * @return mixed + */ + public function login($email, $password) + { + return $this->session($email, $password); + } + + /** + * @return mixed + */ + public function me() + { + return $this->get('user'); + } + + /** + * @return mixed + */ + public function keys() + { + return $this->get('user/keys'); + } + + /** + * @param int $id + * @return mixed + */ + public function key($id) + { + return $this->get('user/keys/'.$this->encodePath($id)); + } + + /** + * @param string $title + * @param string $key + * @return mixed + */ + public function createKey($title, $key) + { + return $this->post('user/keys', array( + 'title' => $title, + 'key' => $key + )); + } + + /** + * @param int $id + * @return mixed + */ + public function removeKey($id) + { + return $this->delete('user/keys/'.$this->encodePath($id)); + } + + /** + * @param int $user_id + * @return mixed + */ + public function userKeys($user_id) + { + return $this->get('users/'.$this->encodePath($user_id).'/keys'); + } + + /* + * @param int $user_id + * @param int $key_id + * @return mixed + */ + public function userKey($user_id, $key_id) + { + return $this->get('users/'.$this->encodePath($user_id).'/keys/'.$this->encodePath($key_id)); + } + + /** + * @param int $user_id + * @param string $title + * @param string $key + * @return mixed + */ + public function createKeyForUser($user_id, $title, $key) + { + return $this->post('users/'.$this->encodePath($user_id).'/keys', array( + 'title' => $title, + 'key' => $key + )); + } + + /** + * @param int $user_id + * @param int $key_id + * @return mixed + */ + public function removeUserKey($user_id, $key_id) + { + return $this->delete('users/'.$this->encodePath($user_id).'/keys/'.$this->encodePath($key_id)); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Client.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Client.php new file mode 100644 index 0000000000000000000000000000000000000000..af6a694175548a59aed8dcdb8e4e681481be4f5d --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Client.php @@ -0,0 +1,272 @@ +<?php namespace Gitlab; + +use Buzz\Client\Curl; +use Buzz\Client\ClientInterface; + +use Gitlab\Api\AbstractApi; +use Gitlab\Exception\InvalidArgumentException; +use Gitlab\HttpClient\HttpClient; +use Gitlab\HttpClient\HttpClientInterface; +use Gitlab\HttpClient\Listener\AuthListener; + +/** + * Simple API wrapper for Gitlab + * + * @author Matt Humphrey <matt@m4tt.co> + * + * @property-read \Gitlab\Api\Groups $groups + * @property-read \Gitlab\Api\Issues $issues + * @property-read \Gitlab\Api\MergeRequests $merge_requests + * @property-read \Gitlab\Api\MergeRequests $mr + * @property-read \Gitlab\Api\Milestones $milestones + * @property-read \Gitlab\Api\Milestones $ms + * @property-read \Gitlab\Api\ProjectNamespaces $namespaces + * @property-read \Gitlab\Api\ProjectNamespaces $ns + * @property-read \Gitlab\Api\Projects $projects + * @property-read \Gitlab\Api\Repositories $repositories + * @property-read \Gitlab\Api\Repositories $repo + * @property-read \Gitlab\Api\Snippets $snippets + * @property-read \Gitlab\Api\SystemHooks $hooks + * @property-read \Gitlab\Api\SystemHooks $system_hooks + * @property-read \Gitlab\Api\Users $users + */ +class Client +{ + /** + * Constant for authentication method. Indicates the default, but deprecated + * login with username and token in URL. + */ + const AUTH_URL_TOKEN = 'url_token'; + + /** + * Constant for authentication method. Indicates the new login method with + * with username and token via HTTP Authentication. + */ + const AUTH_HTTP_TOKEN = 'http_token'; + + /** + * Constant for authentication method. Indicates the OAuth method with a key + * obtain using Gitlab's OAuth provider. + */ + const AUTH_OAUTH_TOKEN = 'oauth_token'; + + /** + * @var array + */ + private $options = array( + 'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)', + 'timeout' => 60 + ); + + private $baseUrl; + + /** + * The Buzz instance used to communicate with Gitlab + * + * @var HttpClient + */ + private $httpClient; + + /** + * Instantiate a new Gitlab client + * + * @param string $baseUrl + * @param null|ClientInterface $httpClient Buzz client + */ + public function __construct($baseUrl, ClientInterface $httpClient = null) + { + $httpClient = $httpClient ?: new Curl(); + $httpClient->setTimeout($this->options['timeout']); + $httpClient->setVerifyPeer(false); + + $this->baseUrl = $baseUrl; + $this->httpClient = new HttpClient($this->baseUrl, $this->options, $httpClient); + } + + /** + * @param string $name + * + * @return AbstractApi|mixed + * @throws InvalidArgumentException + */ + public function api($name) + { + switch ($name) { + + case 'groups': + $api = new Api\Groups($this); + break; + + case 'issues': + $api = new Api\Issues($this); + break; + + case 'mr': + case 'merge_requests': + $api = new Api\MergeRequests($this); + break; + + case 'milestones': + case 'ms': + $api = new Api\Milestones($this); + break; + + case 'namespaces': + case 'ns': + $api = new Api\ProjectNamespaces($this); + break; + + case 'projects': + $api = new Api\Projects($this); + break; + + case 'repo': + case 'repositories': + $api = new Api\Repositories($this); + break; + + case 'snippets': + $api = new Api\Snippets($this); + break; + + case 'hooks': + case 'system_hooks': + $api = new Api\SystemHooks($this); + break; + + case 'users': + $api = new Api\Users($this); + break; + + default: + throw new InvalidArgumentException('Invalid endpoint: "'.$name.'"'); + + } + + return $api; + } + + /** + * Authenticate a user for all next requests + * + * @param string $token Gitlab private token + * @param string $authMethod One of the AUTH_* class constants + * @param string $sudo + * @return $this + */ + public function authenticate($token, $authMethod = self::AUTH_URL_TOKEN, $sudo = null) + { + $this->httpClient->addListener( + new AuthListener( + $authMethod, + $token, + $sudo + ) + ); + + return $this; + } + + /** + * @return HttpClient + */ + public function getHttpClient() + { + return $this->httpClient; + } + + /** + * @param HttpClientInterface $httpClient + * @return $this + */ + public function setHttpClient(HttpClientInterface $httpClient) + { + $this->httpClient = $httpClient; + + return $this; + } + + /** + * @param string $url + * @return $this + */ + public function setBaseUrl($url) + { + $this->baseUrl = $url; + + return $this; + } + + /** + * @return string + */ + public function getBaseUrl() + { + return $this->baseUrl; + } + + /** + * Clears used headers + * + * @return $this + */ + public function clearHeaders() + { + $this->httpClient->clearHeaders(); + + return $this; + } + + /** + * @param array $headers + * @return $this + */ + public function setHeaders(array $headers) + { + $this->httpClient->setHeaders($headers); + + return $this; + } + + /** + * @param string $name + * + * @return mixed + * + * @throws InvalidArgumentException + */ + public function getOption($name) + { + if (!array_key_exists($name, $this->options)) { + throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); + } + + return $this->options[$name]; + } + + /** + * @param string $name + * @param mixed $value + * @throws InvalidArgumentException + * @return $this + */ + public function setOption($name, $value) + { + if (!array_key_exists($name, $this->options)) { + throw new InvalidArgumentException(sprintf('Undefined option called: "%s"', $name)); + } + + $this->options[$name] = $value; + + return $this; + } + + /** + * @param string $api + * @return AbstractApi + */ + public function __get($api) + { + return $this->api($api); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ErrorException.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ErrorException.php new file mode 100644 index 0000000000000000000000000000000000000000..322a7082da842e0a605b6ade666f9ecc23f54aec --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ErrorException.php @@ -0,0 +1,11 @@ +<?php namespace Gitlab\Exception; + +/** + * ErrorException + * + * @author Joseph Bielawski <stloyd@gmail.com> + */ +class ErrorException extends \ErrorException +{ + +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/InvalidArgumentException.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/InvalidArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..892a6dc4bd945fbe0ff6889d93aeb9f45906c721 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/InvalidArgumentException.php @@ -0,0 +1,11 @@ +<?php namespace Gitlab\Exception; + +/** + * InvalidArgumentException + * + * @author Joseph Bielawski <stloyd@gmail.com> + */ +class InvalidArgumentException extends \InvalidArgumentException +{ + +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/MissingArgumentException.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/MissingArgumentException.php new file mode 100644 index 0000000000000000000000000000000000000000..f157b49d1e5a263071e637a0f376d417476757dc --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/MissingArgumentException.php @@ -0,0 +1,18 @@ +<?php namespace Gitlab\Exception; + +/** + * MissingArgumentException + * + * @author Joseph Bielawski <stloyd@gmail.com> + */ +class MissingArgumentException extends ErrorException +{ + public function __construct($required, $code = 0, $previous = null) + { + if (is_string($required)) { + $required = array($required); + } + + parent::__construct(sprintf('One or more of required ("%s") parameters is missing!', implode('", "', $required)), $code, $previous); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/RuntimeException.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/RuntimeException.php new file mode 100644 index 0000000000000000000000000000000000000000..9d938e2cc3948e6c7858fc020d4cb753d828f709 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/RuntimeException.php @@ -0,0 +1,11 @@ +<?php namespace Gitlab\Exception; + +/** + * RuntimeException + * + * @author Joseph Bielawski <stloyd@gmail.com> + */ +class RuntimeException extends \RuntimeException +{ + +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ValidationFailedException.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ValidationFailedException.php new file mode 100644 index 0000000000000000000000000000000000000000..9ce6635fe58795a4b740ea1a8208d04cfac8d2bd --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Exception/ValidationFailedException.php @@ -0,0 +1,11 @@ +<?php namespace Gitlab\Exception; + +/** + * ValidationFailedException + * + * @author Joseph Bielawski <stloyd@gmail.com> + */ +class ValidationFailedException extends ErrorException +{ + +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClient.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClient.php new file mode 100644 index 0000000000000000000000000000000000000000..974b57ad8a9566b8099c6f42ae755d7d1ad0bfc5 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClient.php @@ -0,0 +1,213 @@ +<?php namespace Gitlab\HttpClient; + +use Buzz\Client\ClientInterface; +use Buzz\Listener\ListenerInterface; + +use Gitlab\Exception\ErrorException; +use Gitlab\Exception\RuntimeException; +use Gitlab\HttpClient\Listener\ErrorListener; +use Gitlab\HttpClient\Message\Request; +use Gitlab\HttpClient\Message\Response; + +/** + * Performs requests on Gitlab API. API documentation should be self-explanatory. + * + * @author Joseph Bielawski <stloyd@gmail.com> + * @author Matt Humphrey <matt@m4tt.co> + */ +class HttpClient implements HttpClientInterface +{ + /** + * @var array + */ + protected $options = array( + 'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)', + 'timeout' => 10, + ); + + /** + * @var string + */ + protected $baseUrl; + + /** + * @var ListenerInterface[] + */ + protected $listeners = array(); + /** + * @var array + */ + protected $headers = array(); + + /** + * @var Response + */ + private $lastResponse; + + /** + * @var Request + */ + private $lastRequest; + + /** + * @param string $baseUrl + * @param array $options + * @param ClientInterface $client + */ + public function __construct($baseUrl, array $options, ClientInterface $client) + { + $this->baseUrl = $baseUrl; + $this->options = array_merge($this->options, $options); + $this->client = $client; + + $this->addListener(new ErrorListener($this->options)); + + $this->clearHeaders(); + } + + /** + * {@inheritDoc} + */ + public function setOption($name, $value) + { + $this->options[$name] = $value; + } + + /** + * {@inheritDoc} + */ + public function setHeaders(array $headers) + { + $this->headers = array_merge($this->headers, $headers); + } + + /** + * Clears used headers + */ + public function clearHeaders() + { + $this->headers = array(); + } + + /** + * @param ListenerInterface $listener + */ + public function addListener(ListenerInterface $listener) + { + $this->listeners[get_class($listener)] = $listener; + } + + /** + * {@inheritDoc} + */ + public function get($path, array $parameters = array(), array $headers = array()) + { + if (0 < count($parameters)) { + $path .= (false === strpos($path, '?') ? '?' : '&').http_build_query($parameters, '', '&'); + } + + return $this->request($path, array(), 'GET', $headers); + } + + /** + * {@inheritDoc} + */ + public function post($path, array $parameters = array(), array $headers = array()) + { + return $this->request($path, $parameters, 'POST', $headers); + } + + /** + * {@inheritDoc} + */ + public function patch($path, array $parameters = array(), array $headers = array()) + { + return $this->request($path, $parameters, 'PATCH', $headers); + } + + /** + * {@inheritDoc} + */ + public function delete($path, array $parameters = array(), array $headers = array()) + { + return $this->request($path, $parameters, 'DELETE', $headers); + } + + /** + * {@inheritDoc} + */ + public function put($path, array $parameters = array(), array $headers = array()) + { + return $this->request($path, $parameters, 'PUT', $headers); + } + + /** + * {@inheritDoc} + */ + public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()) + { + $path = trim($this->baseUrl.$path, '/'); + + $request = $this->createRequest($httpMethod, $path); + $request->addHeaders($headers); + $request->setContent(http_build_query($parameters)); + + $hasListeners = 0 < count($this->listeners); + if ($hasListeners) { + foreach ($this->listeners as $listener) { + $listener->preSend($request); + } + } + + $response = new Response(); + + try { + $this->client->send($request, $response); + } catch (\LogicException $e) { + throw new ErrorException($e->getMessage()); + } catch (\RuntimeException $e) { + throw new RuntimeException($e->getMessage()); + } + + $this->lastRequest = $request; + $this->lastResponse = $response; + + if ($hasListeners) { + foreach ($this->listeners as $listener) { + $listener->postSend($request, $response); + } + } + + return $response; + } + + /** + * @return Request + */ + public function getLastRequest() + { + return $this->lastRequest; + } + + /** + * @return Response + */ + public function getLastResponse() + { + return $this->lastResponse; + } + + /** + * @param string $httpMethod + * @param string $url + * @return Request + */ + private function createRequest($httpMethod, $url) + { + $request = new Request($httpMethod); + $request->setHeaders($this->headers); + $request->fromUrl($url); + + return $request; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClientInterface.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClientInterface.php new file mode 100644 index 0000000000000000000000000000000000000000..ef268017b9b31caac1e9065cdd9a567fae05ab60 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/HttpClientInterface.php @@ -0,0 +1,97 @@ +<?php namespace Gitlab\HttpClient; + +use Gitlab\Exception\InvalidArgumentException; + +/** + * Performs requests on Gitlab API. API documentation should be self-explanatory. + * + * @author Joseph Bielawski <stloyd@gmail.com> + * @author Matt Humphrey <matt@m4tt.co> + */ +interface HttpClientInterface +{ + /** + * Send a GET request + * + * @param string $path Request path + * @param array $parameters GET Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return array Data + */ + public function get($path, array $parameters = array(), array $headers = array()); + + /** + * Send a POST request + * + * @param string $path Request path + * @param array $parameters POST Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return array Data + */ + public function post($path, array $parameters = array(), array $headers = array()); + + /** + * Send a PATCH request + * + * @param string $path Request path + * @param array $parameters PATCH Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return array Data + */ + public function patch($path, array $parameters = array(), array $headers = array()); + + /** + * Send a PUT request + * + * @param string $path Request path + * @param array $parameters PUT Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return array Data + */ + public function put($path, array $parameters = array(), array $headers = array()); + + /** + * Send a DELETE request + * + * @param string $path Request path + * @param array $parameters DELETE Parameters + * @param array $headers Reconfigure the request headers for this call only + * + * @return array Data + */ + public function delete($path, array $parameters = array(), array $headers = array()); + + /** + * Send a request to the server, receive a response, + * decode the response and returns an associative array + * + * @param string $path Request API path + * @param array $parameters Parameters + * @param string $httpMethod HTTP method to use + * @param array $headers Request headers + * + * @return array Data + */ + public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array()); + + /** + * Change an option value. + * + * @param string $name The option name + * @param mixed $value The value + * + * @throws InvalidArgumentException + */ + public function setOption($name, $value); + + /** + * Set HTTP headers + * + * @param array $headers + */ + public function setHeaders(array $headers); +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/AuthListener.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/AuthListener.php new file mode 100644 index 0000000000000000000000000000000000000000..27164112280cd918457cbaa4af00b0fc4afc453c --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/AuthListener.php @@ -0,0 +1,95 @@ +<?php namespace Gitlab\HttpClient\Listener; + +use Gitlab\Client; +use Gitlab\Exception\InvalidArgumentException; + +use Buzz\Listener\ListenerInterface; +use Buzz\Message\MessageInterface; +use Buzz\Message\RequestInterface; +use Buzz\Util\Url; + +/** + * @author Joseph Bielawski <stloyd@gmail.com> + * @author Matt Humphrey <matt@m4tt.co> + */ +class AuthListener implements ListenerInterface +{ + /** + * @var string + */ + private $method; + + /** + * @var string + */ + private $token; + + /** + * @var string|null + */ + private $sudo; + + /** + * @param string $method + * @param string $token + * @param string|null $sudo + */ + public function __construct($method, $token, $sudo = null) + { + $this->method = $method; + $this->token = $token; + $this->sudo = $sudo; + } + + /** + * {@inheritDoc} + * + * @throws InvalidArgumentException + */ + public function preSend(RequestInterface $request) + { + // Skip by default + if (null === $this->method) { + return; + } + + switch ($this->method) { + case Client::AUTH_HTTP_TOKEN: + $request->addHeader('PRIVATE-TOKEN: '.$this->token); + if (!is_null($this->sudo)) { + $request->addHeader('SUDO: '.$this->sudo); + } + break; + + case Client::AUTH_URL_TOKEN: + $url = $request->getUrl(); + + $query = array( + 'private_token' => $this->token + ); + + if (!is_null($this->sudo)) { + $query['sudo'] = $this->sudo; + } + + $url .= (false === strpos($url, '?') ? '?' : '&').utf8_encode(http_build_query($query, '', '&')); + + $request->fromUrl(new Url($url)); + break; + + case Client::AUTH_OAUTH_TOKEN: + $request->addHeader('Authorization: Bearer '.$this->token); + if (!is_null($this->sudo)) { + $request->addHeader('SUDO: '.$this->sudo); + } + break; + } + } + + /** + * {@inheritDoc} + */ + public function postSend(RequestInterface $request, MessageInterface $response) + { + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/ErrorListener.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/ErrorListener.php new file mode 100644 index 0000000000000000000000000000000000000000..4ec931cbb24c16df98cd429ec08ad552cc5d62fa --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Listener/ErrorListener.php @@ -0,0 +1,94 @@ +<?php namespace Gitlab\HttpClient\Listener; + +use Buzz\Listener\ListenerInterface; +use Buzz\Message\MessageInterface; +use Buzz\Message\RequestInterface; +use Gitlab\Exception\ErrorException; +use Gitlab\Exception\RuntimeException; + +/** + * @author Joseph Bielawski <stloyd@gmail.com> + * @author Matt Humphrey <git@m4tt.co> + */ +class ErrorListener implements ListenerInterface +{ + /** + * @var array + */ + private $options; + + /** + * @param array $options + */ + public function __construct(array $options) + { + $this->options = $options; + } + + /** + * {@inheritDoc} + */ + public function preSend(RequestInterface $request) + { + } + + /** + * {@inheritDoc} + */ + public function postSend(RequestInterface $request, MessageInterface $response) + { + /** @var $response \Gitlab\HttpClient\Message\Response */ + if ($response->isClientError() || $response->isServerError()) { + $content = $response->getContent(); + if (is_array($content) && isset($content['message'])) { + if (400 == $response->getStatusCode()) { + $message = $this->parseMessage($content['message']); + + throw new ErrorException($message, 400); + } + } + + $errorMessage = null; + if (isset($content['error'])) { + $errorMessage = implode("\n", $content['error']); + } elseif (isset($content['message'])) { + $errorMessage = $this->parseMessage($content['message']); + } else { + $errorMessage = $content; + } + + throw new RuntimeException($errorMessage, $response->getStatusCode()); + } + } + + /** + * @param mixed $message + * @return string + */ + protected function parseMessage($message) + { + $string = $message; + + if (is_array($message)) { + $format = '"%s" %s'; + $errors = array(); + + foreach ($message as $field => $messages) { + if (is_array($messages)) { + $messages = array_unique($messages); + foreach ($messages as $error) { + $errors[] = sprintf($format, $field, $error); + } + } elseif (is_integer($field)) { + $errors[] = $messages; + } else { + $errors[] = sprintf($format, $field, $messages); + } + } + + $string = implode(', ', $errors); + } + + return $string; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Request.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Request.php new file mode 100644 index 0000000000000000000000000000000000000000..41a950f35f3292a50ec7a06a4d4440ce3a20eadc --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Request.php @@ -0,0 +1,8 @@ +<?php namespace Gitlab\HttpClient\Message; + +use Buzz\Message\Request as BaseRequest; + +class Request extends BaseRequest +{ + +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Response.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Response.php new file mode 100644 index 0000000000000000000000000000000000000000..cfe7823f57240926abc2c441c266749dd7ca41b0 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/HttpClient/Message/Response.php @@ -0,0 +1,26 @@ +<?php namespace Gitlab\HttpClient\Message; + +use Buzz\Message\Response as BaseResponse; + +class Response extends BaseResponse +{ + /** + * {@inheritDoc} + */ + public function getContent() + { + $response = parent::getContent(); + + if ($this->getHeader('Content-Type') === 'application/json') { + $content = json_decode($response, true); + + if (JSON_ERROR_NONE !== json_last_error()) { + return $response; + } + + return $content; + } + + return $response; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/AbstractModel.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/AbstractModel.php new file mode 100644 index 0000000000000000000000000000000000000000..7c11d4b21eb6c62f03ac12525ac7a1ee1b8179b6 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/AbstractModel.php @@ -0,0 +1,129 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; +use Gitlab\Exception\RuntimeException; +use Gitlab\Api\AbstractApi; + +abstract class AbstractModel +{ + /** + * @var array + */ + protected static $properties; + + /** + * @var array + */ + protected $data = array(); + + /** + * @var Client + */ + protected $client; + + /** + * @return Client + */ + public function getClient() + { + return $this->client; + } + + /** + * @param Client $client + * @return $this + */ + public function setClient(Client $client = null) + { + if (null !== $client) { + $this->client = $client; + } + + return $this; + } + + /** + * @param string $api + * @return AbstractApi|mixed + */ + public function api($api) + { + return $this->getClient()->api($api); + } + + /** + * @param array $data + * @return $this + */ + protected function hydrate(array $data = array()) + { + if (!empty($data)) { + foreach ($data as $field => $value) { + $this->setData($field, $value); + } + } + + return $this; + } + + /** + * @param string $field + * @param mixed $value + * @return $this + */ + protected function setData($field, $value) + { + if (in_array($field, static::$properties)) { + $this->data[$field] = $value; + } + + return $this; + } + + /** + * @return array + */ + public function getData() + { + return $this->data; + } + + /** + * @param string $property + * @param mixed $value + * @throws RuntimeException + */ + public function __set($property, $value) + { + throw new RuntimeException('Model properties are immutable'); + } + + /** + * @param string $property + * @return mixed + */ + public function __get($property) + { + if (!in_array($property, static::$properties)) { + throw new RuntimeException(sprintf( + 'Property "%s" does not exist for %s object', + $property, get_called_class() + )); + } + + if (isset($this->data[$property])) { + return $this->data[$property]; + } + + return null; + } + + /** + * @param string $property + * @return bool + */ + public function __isset($property) + { + return isset($this->data[$property]); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Branch.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Branch.php new file mode 100644 index 0000000000000000000000000000000000000000..b5de63f7450e6a67477691ed28b86ea738a90a30 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Branch.php @@ -0,0 +1,142 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; +use Gitlab\Api\AbstractApi as Api; + +/** + * Class Branch + * + * @property-read string $name + * @property-read bool $protected + * @property-read Commit $commit + * @property-read Project $project + */ +class Branch extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'name', + 'commit', + 'project', + 'protected' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Branch + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $branch = new static($project, $data['name'], $client); + + if (isset($data['commit'])) { + $data['commit'] = Commit::fromArray($client, $project, $data['commit']); + } + + return $branch->hydrate($data); + } + + /** + * @param Project $project + * @param string $name + * @param Client $client + */ + public function __construct(Project $project, $name = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('name', $name); + } + + /** + * @return Branch + */ + public function show() + { + $data = $this->api('repositories')->branch($this->project->id, $this->name); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return Branch + */ + public function protect() + { + $data = $this->api('repositories')->protectBranch($this->project->id, $this->name); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return Branch + */ + public function unprotect() + { + $data = $this->api('repositories')->unprotectBranch($this->project->id, $this->name); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return bool + */ + public function delete() + { + $this->api('repositories')->deleteBranch($this->project->id, $this->name); + + return true; + } + + /** + * @param int $page + * @param int $per_page + * @return Commit[] + */ + public function commits($page = 1, $per_page = Api::PER_PAGE) + { + return $this->project->commits($page, $per_page, $this->name); + } + + /** + * @param string $file_path + * @param string $content + * @param string $commit_message + * @return File + */ + public function createFile($file_path, $content, $commit_message) + { + $data = $this->api('repositories')->createFile($this->project->id, $file_path, $content, $this->name, $commit_message); + + return File::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param string $file_path + * @param string $content + * @param string $commit_message + * @return File + */ + public function updateFile($file_path, $content, $commit_message) + { + $data = $this->api('repositories')->updateFile($this->project->id, $file_path, $content, $this->name, $commit_message); + + return File::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param string $file_path + * @param string $commit_message + * @return bool + */ + public function deleteFile($file_path, $commit_message) + { + $this->api('repositories')->deleteFile($this->project->id, $file_path, $this->name, $commit_message); + + return true; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Commit.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Commit.php new file mode 100644 index 0000000000000000000000000000000000000000..9b007325515feff26f7a49e1269403fd331180e2 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Commit.php @@ -0,0 +1,86 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Commit + * + * @property-read string $id + * @property-read string $short_id + * @property-read string $title + * @property-read string $message + * @property-read string $author_name + * @property-read string $author_email + * @property-read string $authored_date + * @property-read string $committed_date + * @property-read string $created_at + * @property-read Commit[] $parents + * @property-read Node[] $tree + * @property-read User $committer + * @property-read User $author + * @property-read Project $project + */ +class Commit extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'short_id', + 'parents', + 'tree', + 'title', + 'message', + 'author', + 'author_name', + 'author_email', + 'committer', + 'authored_date', + 'committed_date', + 'created_at', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Commit + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $commit = new static($project, $data['id'], $client); + + if (isset($data['parents'])) { + $parents = array(); + foreach ($data['parents'] as $parent) { + $parents[] = static::fromArray($client, $project, $parent); + } + + $data['parents'] = $parents; + } + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + if (isset($data['committer'])) { + $data['committer'] = User::fromArray($client, $data['committer']); + } + + return $commit->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/CommitNote.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/CommitNote.php new file mode 100644 index 0000000000000000000000000000000000000000..4b455c7f160979748b8cd1744bfcedbc14b2abfd --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/CommitNote.php @@ -0,0 +1,50 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class CommitNote + * + * @property-read string $note + * @property-read string $path + * @property-read string $line + * @property-read string $line_type + * @property-read User $author + */ +class CommitNote extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'note', + 'path', + 'line', + 'line_type', + 'author' + ); + + /** + * @param Client $client + * @param array $data + * @return CommitNote + */ + public static function fromArray(Client $client, array $data) + { + $comment = new static($client); + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + return $comment->hydrate($data); + } + + /** + * @param Client $client + */ + public function __construct(Client $client = null) + { + $this->setClient($client); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Comparison.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Comparison.php new file mode 100644 index 0000000000000000000000000000000000000000..27901829d5b6b1673677f911f9b33816ead635f9 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Comparison.php @@ -0,0 +1,73 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Comparison + * + * @property-read bool $compare_timeout + * @property-read bool $compare_same_ref + * @property-read Commit $commit + * @property-read Commit[] $commits + * @property-read Diff[] $diffs + * @property-read Project $project + */ +class Comparison extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'commit', + 'commits', + 'diffs', + 'compare_timeout', + 'compare_same_ref', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Comparison + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $file = new static($project, $client); + + if (isset($data['commit'])) { + $data['commit'] = Commit::fromArray($client, $project, $data['commit']); + } + + if (isset($data['commits'])) { + $commits = array(); + foreach ($data['commits'] as $commit) { + $commits[] = Commit::fromArray($client, $project, $commit); + } + + $data['commits'] = $commits; + } + + if (isset($data['diffs'])) { + $diffs = array(); + foreach ($data['diffs'] as $diff) { + $diffs[] = Diff::fromArray($client, $project, $diff); + } + + $data['diffs'] = $diffs; + } + + return $file->hydrate($data); + } + + /** + * @param Project $project + * @param Client $client + */ + public function __construct(Project $project, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Contributor.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Contributor.php new file mode 100644 index 0000000000000000000000000000000000000000..658da48bcfc634bb58db54ac959a168d9f0e4119 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Contributor.php @@ -0,0 +1,51 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Contributor + * + * @property-read string $name + * @property-read string $email + * @property-read int $commits + * @property-read int $additions + * @property-read int $deletions + * @property-read Project $project + */ +class Contributor extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'name', + 'email', + 'commits', + 'additions', + 'deletions', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Contributor + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $contributor = new static($project, $client); + + return $contributor->hydrate($data); + } + + /** + * @param Project $project + * @param Client $client + */ + public function __construct(Project $project, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Diff.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Diff.php new file mode 100644 index 0000000000000000000000000000000000000000..5fd95d5ac62a250a04fd07aed5c85624009d75cb --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Diff.php @@ -0,0 +1,65 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Diff + * + * @property-read string $old_path + * @property-read string $new_path + * @property-read string $a_mode + * @property-read string $b_mode + * @property-read string $diff + * @property-read bool $new_file + * @property-read bool $renamed_file + * @property-read bool $deleted_file + * @property-read Project $project + */ +class Diff extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'old_path', + 'new_path', + 'a_mode', + 'b_mode', + 'diff', + 'new_file', + 'renamed_file', + 'deleted_file', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Diff + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $diff = new static($project, $client); + + return $diff->hydrate($data); + } + + /** + * @param Project $project + * @param Client $client + */ + public function __construct(Project $project, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + } + + /** + * @return string + */ + public function __toString() + { + return $this->diff; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Event.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Event.php new file mode 100644 index 0000000000000000000000000000000000000000..83565e174da9bebd2b611b814ea43c58910a790a --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Event.php @@ -0,0 +1,65 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Event + * + * @property-read string $title + * @property-read int $id + * @property-read string $action_name + * @property-read string $data + * @property-read int $target_id + * @property-read string $target_type + * @property-read string $target_title + * @property-read int $author_id + * @property-read string $author_username + * @property-read User $author + * @property-read Project $project + */ +class Event extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'title', + 'project_id', + 'action_name', + 'target_id', + 'target_type', + 'author_id', + 'author_username', + 'data', + 'target_title', + 'author', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Event + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $event = new static($project, $client); + + if (isset($data['author_id'])) { + $data['author'] = new User($data['author_id'], $client); + } + + return $event->hydrate($data); + } + + /** + * @param Project $project + * @param Client $client + */ + public function __construct(Project $project, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/File.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/File.php new file mode 100644 index 0000000000000000000000000000000000000000..b2edac1273e5e11c2b53c3b8283307905829a0a2 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/File.php @@ -0,0 +1,47 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class File + * + * @property-read string $file_path + * @property-read string $branch_name + * @property-read Project $project + */ +class File extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'project', + 'file_path', + 'branch_name' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return File + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $file = new static($project, $data['file_path'], $client); + + return $file->hydrate($data); + } + + /** + * @param Project $project + * @param string $file_path + * @param Client $client + */ + public function __construct(Project $project, $file_path = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('file_path', $file_path); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Group.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Group.php new file mode 100644 index 0000000000000000000000000000000000000000..614d50ffb82e1c42fafaeb1b0ffe5984846f5522 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Group.php @@ -0,0 +1,128 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Group + * + * @property-read int $id + * @property-read string $name + * @property-read string $path + * @property-read string $description + * @property-read Project[] $projects + */ +class Group extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'name', + 'path', + 'description', + 'projects' + ); + + /** + * @param Client $client + * @param array $data + * @return Group + */ + public static function fromArray(Client $client, array $data) + { + $group = new static($data['id'], $client); + + if (isset($data['projects'])) { + $projects = array(); + foreach ($data['projects'] as $project) { + $projects[] = Project::fromArray($client, $project); + } + $data['projects'] = $projects; + } + + return $group->hydrate($data); + } + + /** + * @param Client $client + * @param string $name + * @param string $path + * @return Group + */ + public static function create(Client $client, $name, $path) + { + $data = $client->api('groups')->create($name, $path); + + return static::fromArray($client, $data); + } + + /** + * @param int $id + * @param Client $client + */ + public function __construct($id, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + } + + /** + * @return Group + */ + public function show() + { + $data = $this->api('groups')->show($this->id); + + return Group::fromArray($this->getClient(), $data); + } + + /** + * @param int $project_id + * @return Group + */ + public function transfer($project_id) + { + $data = $this->api('groups')->transfer($this->id, $project_id); + + return Group::fromArray($this->getClient(), $data); + } + + /** + * @return User[] + */ + public function members() + { + $data = $this->api('groups')->members($this->id); + + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($this->getClient(), $member); + } + + return $members; + } + + /** + * @param int $user_id + * @param int $access_level + * @return User + */ + public function addMember($user_id, $access_level) + { + $data = $this->api('groups')->addMember($this->id, $user_id, $access_level); + + return User::fromArray($this->getClient(), $data); + } + + /** + * @param int $user_id + * @return bool + */ + public function removeMember($user_id) + { + $this->api('groups')->removeMember($this->id, $user_id); + + return true; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Hook.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Hook.php new file mode 100644 index 0000000000000000000000000000000000000000..15bda3992286825d86ce990aee0804b963ab908d --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Hook.php @@ -0,0 +1,76 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Hook + * + * @property-read int $id + * @property-read string $url + * @property-read string $created_at + */ +class Hook extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'url', + 'created_at' + ); + + /** + * @param Client $client + * @param array $data + * @return Hook + */ + public static function fromArray(Client $client, array $data) + { + $hook = new static($data['id'], $client); + + return $hook->hydrate($data); + } + + /** + * @param Client $client + * @param string $url + * @return Hook + */ + public static function create(Client $client, $url) + { + $data = $client->api('system_hooks')->create($url); + + return static::fromArray($client, $data); + } + + /** + * @param int $id + * @param Client $client + */ + public function __construct($id, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + } + + /** + * @return bool + */ + public function test() + { + $this->api('system_hooks')->test($this->id); + + return true; + } + + /** + * @return bool + */ + public function delete() + { + $this->api('system_hooks')->remove($this->id); + + return true; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Issue.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Issue.php new file mode 100644 index 0000000000000000000000000000000000000000..86c7e2adda52c211fabbd724fe239536041df565 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Issue.php @@ -0,0 +1,171 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Issue + * + * @property-read int $id + * @property-read int $iid + * @property-read int $project_id, + * @property-read string $title + * @property-read string $description + * @property-read array $labels + * @property-read bool $closed + * @property-read string $updated_at + * @property-read string $created_at + * @property-read string $state + * @property-read User $assignee + * @property-read User $author + * @property-read Milestone $milestone + * @property-read Project $project + */ +class Issue extends AbstractModel implements Noteable +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'iid', + 'project_id', + 'title', + 'description', + 'labels', + 'milestone', + 'assignee', + 'author', + 'closed', + 'updated_at', + 'created_at', + 'project', + 'state' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Issue + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $issue = new static($project, $data['id'], $client); + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + if (isset($data['assignee'])) { + $data['assignee'] = User::fromArray($client, $data['assignee']); + } + + return $issue->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } + + /** + * @return Issue + */ + public function show() + { + $data = $this->api('issues')->show($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param array $params + * @return Issue + */ + public function update(array $params) + { + $data = $this->api('issues')->update($this->project->id, $this->id, $params); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param string $comment + * @return Issue + */ + public function close($comment = null) + { + if ($comment) { + $this->addComment($comment); + } + + return $this->update(array( + 'state_event' => 'close' + )); + } + + /** + * @return Issue + */ + public function open() + { + return $this->update(array( + 'state_event' => 'reopen' + )); + } + + /** + * @return Issue + */ + public function reopen() + { + return $this->open(); + } + + /** + * @param string $comment + * @return Note + */ + public function addComment($comment) + { + $data = $this->api('issues')->addComment($this->project->id, $this->id, array( + 'body' => $comment + )); + + return Note::fromArray($this->getClient(), $this, $data); + } + + /** + * @return Note[] + */ + public function showComments() + { + $notes = array(); + $data = $this->api('issues')->showComments($this->project->id, $this->id); + + foreach ($data as $note) { + $notes[] = Note::fromArray($this->getClient(), $this, $note); + } + + return $notes; + } + + /** + * @return bool + */ + public function isClosed() + { + if ($this->state == 'closed') { + return true; + } + + return false; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Key.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Key.php new file mode 100644 index 0000000000000000000000000000000000000000..5e6aebfa58ca38c68f91ff412874ff041d8a1015 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Key.php @@ -0,0 +1,44 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Key + * + * @property-read int $id + * @property-read string $title + * @property-read string $key + * @property-read string $created_at + */ +class Key extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'title', + 'key', + 'created_at' + ); + + /** + * @param Client $client + * @param array $data + * @return Key + */ + public static function fromArray(Client $client, array $data) + { + $key = new static($client); + + return $key->hydrate($data); + } + + /** + * @param Client $client + */ + public function __construct(Client $client = null) + { + $this->setClient($client); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Label.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Label.php new file mode 100644 index 0000000000000000000000000000000000000000..5c8a2091984e77c06616581f8e6ae69ed7b663fb --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Label.php @@ -0,0 +1,43 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Label + * + * @property-read string $name + * @property-read string $color + */ +class Label extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'name', + 'color' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Label + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $label = new static($project, $client); + + return $label->hydrate($data); + } + + /** + * @param Project $project + * @param Client $client + */ + public function __construct(Project $project, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/MergeRequest.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/MergeRequest.php new file mode 100644 index 0000000000000000000000000000000000000000..73eaa49ef9cbdd8b014e1ce86e6b7ac8b7fad273 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/MergeRequest.php @@ -0,0 +1,225 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class MergeRequest + * + * @property-read int $id + * @property-read int $iid + * @property-read string $target_branch + * @property-read string $source_branch + * @property-read int $project_id + * @property-read string $title + * @property-read bool $closed + * @property-read bool $merged + * @property-read string $state + * @property-read int $source_project_id + * @property-read int $target_project_id + * @property-read int $upvotes + * @property-read int $downvotes + * @property-read array $labels + * @property-read User $author + * @property-read User $assignee + * @property-read Project $project + * @property-read Milestone $milestone + * @property-read File[] $files + */ +class MergeRequest extends AbstractModel implements Noteable +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'iid', + 'target_branch', + 'source_branch', + 'project_id', + 'title', + 'closed', + 'merged', + 'author', + 'assignee', + 'project', + 'state', + 'source_project_id', + 'target_project_id', + 'upvotes', + 'downvotes', + 'labels', + 'milestone', + 'files' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return MergeRequest + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $mr = new static($project, $data['id'], $client); + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + if (isset($data['assignee'])) { + $data['assignee'] = User::fromArray($client, $data['assignee']); + } + + if (isset($data['milestone'])) { + $data['milestone'] = Milestone::fromArray($client, $project, $data['milestone']); + } + + if (isset($data['files'])) { + $files = array(); + foreach ($data['files'] as $file) { + $files[] = File::fromArray($client, $project, $file); + } + + $data['files'] = $files; + } + + return $mr->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } + + /** + * @return MergeRequest + */ + public function show() + { + $data = $this->api('mr')->show($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param array $params + * @return MergeRequest + */ + public function update(array $params) + { + $data = $this->api('mr')->update($this->project->id, $this->id, $params); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param string $comment + * @return MergeRequest + */ + public function close($comment = null) + { + if ($comment) { + $this->addComment($comment); + } + + return $this->update(array( + 'state_event' => 'close' + )); + } + + /** + * @return MergeRequest + */ + public function reopen() + { + return $this->update(array( + 'state_event' => 'reopen' + )); + } + + /** + * @return MergeRequest + */ + public function open() + { + return $this->reopen(); + } + + /** + * @param string $message + * @return MergeRequest + */ + public function merge($message = null) + { + $data = $this->api('mr')->merge($this->project->id, $this->id, array( + 'merge_commit_message' => $message + )); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return MergeRequest + */ + public function merged() + { + return $this->update(array( + 'state_event' => 'merge' + )); + } + + /** + * @param string $comment + * @return Note + */ + public function addComment($comment) + { + $data = $this->api('mr')->addComment($this->project->id, $this->id, $comment); + + return Note::fromArray($this->getClient(), $this, $data); + } + + /** + * @return Note[] + */ + public function showComments() + { + $notes = array(); + $data = $this->api('mr')->showComments($this->project->id, $this->id); + + foreach ($data as $note) { + $notes[] = Note::fromArray($this->getClient(), $this, $note); + } + + return $notes; + } + + /** + * @return bool + */ + public function isClosed() + { + if (in_array($this->state, array('closed', 'merged'))) { + return true; + } + + return false; + } + + /** + * @return MergeRequest + */ + public function changes() + { + $data = $this->api('mr')->changes($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Milestone.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Milestone.php new file mode 100644 index 0000000000000000000000000000000000000000..c59afca38bf63f02c65335b55c5112d15e56ffd8 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Milestone.php @@ -0,0 +1,115 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Milestone + * + * @property-read int $id + * @property-read int $iid + * @property-read int $project_id + * @property-read string $title + * @property-read string $description + * @property-read string $due_date + * @property-read string $state + * @property-read bool $closed + * @property-read string $updated_at + * @property-read string $created_at + * @property-read Project $project + */ +class Milestone extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'iid', + 'project', + 'project_id', + 'title', + 'description', + 'due_date', + 'state', + 'closed', + 'updated_at', + 'created_at' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Milestone + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $milestone = new static($project, $data['id'], $client); + + return $milestone->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + $this->setData('project', $project); + } + + /** + * @return Milestone + */ + public function show() + { + $data = $this->api('milestones')->show($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param array $params + * @return Milestone + */ + public function update(array $params) + { + $data = $this->api('milestones')->update($this->project->id, $this->id, $params); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return Milestone + */ + public function complete() + { + return $this->update(array('closed' => true)); + } + + /** + * @return Milestone + */ + public function incomplete() + { + return $this->update(array('closed' => false)); + } + + /** + * @return Issue[] + */ + public function issues() + { + $data = $this->api('milestones')->issues($this->project->id, $this->id); + + $issues = array(); + foreach ($data as $issue) { + $issues[] = Issue::fromArray($this->getClient(), $this->project, $issue); + } + + return $issues; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Node.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Node.php new file mode 100644 index 0000000000000000000000000000000000000000..8add42a07ae3d06578a7bdfe92e36c81de77b220 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Node.php @@ -0,0 +1,51 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Node + * + * @property-read string $name + * @property-read string $type + * @property-read string $mode + * @property-read int $id + * @property-read Project $project + */ +class Node extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'name', + 'type', + 'mode', + 'id', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Node + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $node = new static($project, $data['id'], $client); + + return $node->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id = null, Client $client) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Note.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Note.php new file mode 100644 index 0000000000000000000000000000000000000000..36afeb1326ed80b72bc6828b8d6d0fd69d17b69f --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Note.php @@ -0,0 +1,58 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Note + * + * @property-read User $author + * @property-read string $body + * @property-read string $created_at + * @property-read string $updated_at + * @property-read string $parent_type + * @property-read Issue|MergeRequest $parent + * @property-read string $attachment + */ +class Note extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'author', + 'body', + 'created_at', + 'updated_at', + 'parent_type', + 'parent', + 'attachment' + ); + + /** + * @param Client $client + * @param Noteable $type + * @param array $data + * @return mixed + */ + public static function fromArray(Client $client, Noteable $type, array $data) + { + $comment = new static($type, $client); + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + return $comment->hydrate($data); + } + + /** + * @param Noteable $type + * @param Client $client + */ + public function __construct(Noteable $type, Client $client = null) + { + $this->setClient($client); + $this->setData('parent_type', get_class($type)); + $this->setData('parent', $type); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Noteable.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Noteable.php new file mode 100644 index 0000000000000000000000000000000000000000..11e2cb6506d4b83e9e6f98875e6de834447ba4d1 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Noteable.php @@ -0,0 +1,36 @@ +<?php namespace Gitlab\Model; + +interface Noteable +{ + /** + * @param string $comment + * @return Note + */ + public function addComment($comment); + + /** + * @return Note[] + */ + public function showComments(); + + /** + * @param string $comment + * @return static + */ + public function close($comment = null); + + /** + * @return static + */ + public function open(); + + /** + * @return static + */ + public function reopen(); + + /** + * @return bool + */ + public function isClosed(); +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Project.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Project.php new file mode 100644 index 0000000000000000000000000000000000000000..1fd4912e512237c9740237d19b9a7c8dd0ee726e --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Project.php @@ -0,0 +1,1034 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Api\MergeRequests; +use Gitlab\Client; +use Gitlab\Api\AbstractApi as Api; + +/** + * Class Project + * + * @property-read int $id + * @property-read string $code + * @property-read string $name + * @property-read string $name_with_namespace + * @property-read string $description + * @property-read string $path + * @property-read string $path_with_namespace + * @property-read string $ssh_url_to_repo + * @property-read string $http_url_to_repo + * @property-read string $web_url + * @property-read string $default_branch + * @property-read bool $private + * @property-read bool $public + * @property-read bool $issues_enabled + * @property-read bool $merge_requests_enabled + * @property-read bool $wall_enabled + * @property-read bool $wiki_enabled + * @property-read bool $snippets_enabled + * @property-read string $created_at + * @property-read int $greatest_access_level + * @property-read string $last_activity_at + * @property-read string $tag_list + * @property-read User $owner + * @property-read ProjectNamespace $namespace + */ +class Project extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'code', + 'name', + 'name_with_namespace', + 'namespace', + 'description', + 'path', + 'path_with_namespace', + 'ssh_url_to_repo', + 'http_url_to_repo', + 'web_url', + 'default_branch', + 'owner', + 'private', + 'public', + 'issues_enabled', + 'merge_requests_enabled', + 'wall_enabled', + 'wiki_enabled', + 'created_at', + 'greatest_access_level', + 'last_activity_at', + 'snippets_enabled', + 'tag_list' + ); + + /** + * @param Client $client + * @param array $data + * @return Project + */ + public static function fromArray(Client $client, array $data) + { + $project = new static($data['id']); + $project->setClient($client); + + if (isset($data['owner'])) { + $data['owner'] = User::fromArray($client, $data['owner']); + } + + if (isset($data['namespace']) && is_array($data['namespace'])) { + $data['namespace'] = ProjectNamespace::fromArray($client, $data['namespace']); + } + + return $project->hydrate($data); + } + + /** + * @param Client $client + * @param string $name + * @param array $params + * @return Project + */ + public static function create(Client $client, $name, array $params = array()) + { + $data = $client->api('projects')->create($name, $params); + + return static::fromArray($client, $data); + } + + /** + * @param int $user_id + * @param Client $client + * @param string $name + * @param array $params + * @return Project + */ + public static function createForUser($user_id, Client $client, $name, array $params = array()) + { + $data = $client->api('projects')->createForUser($user_id, $name, $params); + + return static::fromArray($client, $data); + } + /** + * @param int $id + * @param Client $client + */ + public function __construct($id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + } + + /** + * @return Project + */ + public function show() + { + $data = $this->api('projects')->show($this->id); + + return static::fromArray($this->getClient(), $data); + } + + /** + * @param array $params + * @return Project + */ + public function update(array $params) + { + $data = $this->api('projects')->update($this->id, $params); + + return static::fromArray($this->getClient(), $data); + } + + /** + * @return bool + */ + public function remove() + { + $this->api('projects')->remove($this->id); + + return true; + } + + /** + * @param string $username_query + * @return User[] + */ + public function members($username_query = null) + { + $data = $this->api('projects')->members($this->id, $username_query); + + $members = array(); + foreach ($data as $member) { + $members[] = User::fromArray($this->getClient(), $member); + } + + return $members; + } + + /** + * @param int $user_id + * @return User + */ + public function member($user_id) + { + $data = $this->api('projects')->member($this->id, $user_id); + + return User::fromArray($this->getClient(), $data); + } + + /** + * @param int $user_id + * @param int $access_level + * @return User + */ + public function addMember($user_id, $access_level) + { + $data = $this->api('projects')->addMember($this->id, $user_id, $access_level); + + return User::fromArray($this->getClient(), $data); + } + + /** + * @param int $user_id + * @param int $access_level + * @return User + */ + public function saveMember($user_id, $access_level) + { + $data = $this->api('projects')->saveMember($this->id, $user_id, $access_level); + + return User::fromArray($this->getClient(), $data); + } + + /** + * @param int $user_id + * @return bool + */ + public function removeMember($user_id) + { + $this->api('projects')->removeMember($this->id, $user_id); + + return true; + } + + /** + * @param int $page + * @param int $per_page + * @return ProjectHook[] + */ + public function hooks($page = 1, $per_page = Api::PER_PAGE) + { + $data = $this->api('projects')->hooks($this->id, $page, $per_page); + + $hooks = array(); + foreach ($data as $hook) { + $hooks[] = ProjectHook::fromArray($this->getClient(), $this, $hook); + } + + return $hooks; + } + + /** + * @param int $id + * @return ProjectHook + */ + public function hook($id) + { + $hook = new ProjectHook($this, $id, $this->getClient()); + + return $hook->show(); + } + + /** + * @param string $url + * @param array $events + * @return ProjectHook + */ + public function addHook($url, array $events = array()) + { + $data = $this->api('projects')->addHook($this->id, $url, $events); + + return ProjectHook::fromArray($this->getClient(), $this, $data); + } + + /** + * @param int $hook_id + * @param array $params + * @return mixed + */ + public function updateHook($hook_id, array $params) + { + $hook = new ProjectHook($this, $hook_id, $this->getClient()); + + return $hook->update($params); + } + + /** + * @param int $hook_id + * @return bool + */ + public function removeHook($hook_id) + { + $hook = new ProjectHook($this, $hook_id, $this->getClient()); + + return $hook->delete(); + } + + /** + * @return Key[] + */ + public function keys() + { + $data = $this->api('projects')->keys($this->id); + + $keys = array(); + foreach ($data as $key) { + $hooks[] = Key::fromArray($this->getClient(), $key); + } + + return $keys; + } + + /** + * @param int $key_id + * @return Key + */ + public function key($key_id) + { + $data = $this->api('projects')->key($this->id, $key_id); + + return Key::fromArray($this->getClient(), $data); + } + + /** + * @param string $title + * @param string $key + * @return Key + */ + public function addKey($title, $key) + { + $data = $this->api('projects')->addKey($this->id, $title, $key); + + return Key::fromArray($this->getClient(), $data); + } + + /** + * @param string $key_id + * @return bool + */ + public function removeKey($key_id) + { + $this->api('projects')->removeKey($this->id, $key_id); + + return true; + } + + /** + * @param string $name + * @param string $ref + * @return Branch + */ + public function createBranch($name, $ref) + { + $data = $this->api('repositories')->createBranch($this->id, $name, $ref); + + return Branch::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $name + * @return bool + */ + public function deleteBranch($name) + { + $this->api('repositories')->deleteBranch($this->id, $name); + + return true; + } + + /** + * @return Branch[] + */ + public function branches() + { + $data = $this->api('repo')->branches($this->id); + + $branches = array(); + foreach ($data as $branch) { + $branches[] = Branch::fromArray($this->getClient(), $this, $branch); + } + + return $branches; + } + + /** + * @param string $branch_name + * @return Branch + */ + public function branch($branch_name) + { + $branch = new Branch($this, $branch_name); + $branch->setClient($this->getClient()); + + return $branch->show(); + } + + /** + * @param string $branch_name + * @return Branch + */ + public function protectBranch($branch_name) + { + $branch = new Branch($this, $branch_name); + $branch->setClient($this->getClient()); + + return $branch->protect(); + } + + /** + * @param string $branch_name + * @return Branch + */ + public function unprotectBranch($branch_name) + { + $branch = new Branch($this, $branch_name); + $branch->setClient($this->getClient()); + + return $branch->unprotect(); + } + + /** + * @return Tag[] + */ + public function tags() + { + $data = $this->api('repo')->tags($this->id); + + $tags = array(); + foreach ($data as $tag) { + $tags[] = Tag::fromArray($this->getClient(), $this, $tag); + } + + return $tags; + } + + /** + * @param int $page + * @param int $per_page + * @param string $ref_name + * @return Commit[] + */ + public function commits($page = 0, $per_page = Api::PER_PAGE, $ref_name = null) + { + $data = $this->api('repo')->commits($this->id, $page, $per_page, $ref_name); + + $commits = array(); + foreach ($data as $commit) { + $commits[] = Commit::fromArray($this->getClient(), $this, $commit); + } + + return $commits; + } + + /** + * @param string $sha + * @return Commit + */ + public function commit($sha) + { + $data = $this->api('repo')->commit($this->id, $sha); + + return Commit::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $ref + * @param int $page + * @param int $per_page + * @return Commit[] + */ + public function commitComments($ref, $page = 0, $per_page = Api::PER_PAGE) + { + $data = $this->api('repo')->commitComments($this->id, $ref, $page, $per_page); + + $comments = array(); + foreach ($data as $comment) { + $comments[] = CommitNote::fromArray($this->getClient(), $comment); + } + + return $comments; + } + + /** + * @param string $ref + * @param string $note + * @param array $params + * @return CommitNote + */ + public function createCommitComment($ref, $note, array $params = array()) + { + $data = $this->api('repo')->createCommitComment($this->id, $ref, $note, $params); + + return CommitNote::fromArray($this->getClient(), $data); + } + + /** + * @param string $sha + * @return string + */ + public function diff($sha) + { + return $this->api('repo')->diff($this->id, $sha); + } + + /** + * @param string $from + * @param string $to + * @return Comparison + */ + public function compare($from, $to) + { + $data = $this->api('repo')->compare($this->id, $from, $to); + + return Comparison::fromArray($this->getClient(), $this, $data); + } + + /** + * @param array $params + * @return Node[] + */ + public function tree(array $params = array()) + { + $data = $this->api('repo')->tree($this->id, $params); + + $tree = array(); + foreach ($data as $node) { + $tree[] = Node::fromArray($this->getClient(), $this, $node); + } + + return $tree; + } + + /** + * @param string $sha + * @param string $filepath + * @return string + */ + public function blob($sha, $filepath) + { + return $this->api('repo')->blob($this->id, $sha, $filepath); + } + + /** + * @param string $file_path + * @param string $content + * @param string $branch_name + * @param string $commit_message + * @return File + */ + public function createFile($file_path, $content, $branch_name, $commit_message) + { + $data = $this->api('repo')->createFile($this->id, $file_path, $content, $branch_name, $commit_message); + + return File::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $file_path + * @param string $content + * @param string $branch_name + * @param string $commit_message + * @return File + */ + public function updateFile($file_path, $content, $branch_name, $commit_message) + { + $data = $this->api('repo')->updateFile($this->id, $file_path, $content, $branch_name, $commit_message); + + return File::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $file_path + * @param string $branch_name + * @param string $commit_message + * @return bool + */ + public function deleteFile($file_path, $branch_name, $commit_message) + { + $this->api('repo')->deleteFile($this->id, $file_path, $branch_name, $commit_message); + + return true; + } + + /** + * @param int $page + * @param int $per_page + * @return Event[] + */ + public function events($page = 1, $per_page = Api::PER_PAGE) + { + $data = $this->api('projects')->events($this->id, $page, $per_page); + + $events = array(); + foreach ($data as $event) { + $events[] = Event::fromArray($this->getClient(), $this, $event); + } + + return $events; + } + + /** + * @param int $page + * @param int $per_page + * @param string $state + * @return MergeRequest[] + */ + public function mergeRequests($page = 1, $per_page = Api::PER_PAGE, $state = MergeRequests::STATE_ALL) + { + $data = $this->api('mr')->$state($this->id, $page, $per_page); + + $mrs = array(); + foreach ($data as $mr) { + $mrs[] = MergeRequest::fromArray($this->getClient(), $this, $mr); + } + + return $mrs; + } + + /** + * @param int $id + * @return MergeRequest + */ + public function mergeRequest($id) + { + $mr = new MergeRequest($this, $id, $this->getClient()); + + return $mr->show(); + } + + /** + * @param string $source + * @param string $target + * @param string $title + * @param int $assignee + * @param string $description + * @return MergeRequest + */ + public function createMergeRequest($source, $target, $title, $assignee = null, $description = null) + { + $data = $this->api('mr')->create($this->id, $source, $target, $title, $assignee, null, $description); + + return MergeRequest::fromArray($this->getClient(), $this, $data); + } + + /** + * @param int $id + * @param array $params + * @return MergeRequest + */ + public function updateMergeRequest($id, array $params) + { + $mr = new MergeRequest($this, $id, $this->getClient()); + + return $mr->update($params); + } + + /** + * @param int $id + * @return MergeRequest + */ + public function closeMergeRequest($id) + { + $mr = new MergeRequest($this, $id, $this->getClient()); + + return $mr->close(); + } + + /** + * @param int $id + * @return MergeRequest + */ + public function openMergeRequest($id) + { + $mr = new MergeRequest($this, $id, $this->getClient()); + + return $mr->reopen(); + } + + /** + * @param int $id + * @return MergeRequest + */ + public function mergeMergeRequest($id) + { + $mr = new MergeRequest($this, $id, $this->getClient()); + + return $mr->merge(); + } + + /** + * @param int $page + * @param int $per_page + * @return Issue[] + */ + public function issues($page = 1, $per_page = Api::PER_PAGE) + { + $data = $this->api('issues')->all($this->id, $page, $per_page); + + $issues = array(); + foreach ($data as $issue) { + $issues[] = Issue::fromArray($this->getClient(), $this, $issue); + } + + return $issues; + } + + /** + * @param string $title + * @param array $params + * @return Issue + */ + public function createIssue($title, array $params = array()) + { + $params['title'] = $title; + $data = $this->api('issues')->create($this->id, $params); + + return Issue::fromArray($this->getClient(), $this, $data); + } + + /** + * @param int $id + * @return Issue + */ + public function issue($id) + { + $issue = new Issue($this, $id, $this->getClient()); + + return $issue->show(); + } + + /** + * @param int $id + * @param array $params + * @return Issue + */ + public function updateIssue($id, array $params) + { + $issue = new Issue($this, $id, $this->getClient()); + + return $issue->update($params); + } + + /** + * @param int $id + * @param string $comment + * @return Issue + */ + public function closeIssue($id, $comment = null) + { + $issue = new Issue($this, $id, $this->getClient()); + + return $issue->close($comment); + } + + /** + * @param int $id + * @return Issue + */ + public function openIssue($id) + { + $issue = new Issue($this, $id, $this->getClient()); + + return $issue->open(); + } + + /** + * @param int $page + * @param int $per_page + * @return Milestone[] + */ + public function milestones($page = 1, $per_page = Api::PER_PAGE) + { + $data = $this->api('milestones')->all($this->id, $page, $per_page); + + $milestones = array(); + foreach ($data as $milestone) { + $milestones[] = Milestone::fromArray($this->getClient(), $this, $milestone); + } + + return $milestones; + } + + /** + * @param string $title + * @param array $params + * @return Milestone + */ + public function createMilestone($title, array $params = array()) + { + $params['title'] = $title; + $data = $this->api('milestones')->create($this->id, $params); + + return Milestone::fromArray($this->getClient(), $this, $data); + } + + /** + * @param int $id + * @return Milestone + */ + public function milestone($id) + { + $milestone = new Milestone($this, $id, $this->getClient()); + + return $milestone->show(); + } + + /** + * @param int $id + * @param array $params + * @return Milestone + */ + public function updateMilestone($id, array $params) + { + $milestone = new Milestone($this, $id, $this->getClient()); + + return $milestone->update($params); + } + + /** + * @param int $id + * @return Issue[] + */ + public function milestoneIssues($id) + { + $milestone = new Milestone($this, $id, $this->getClient()); + + return $milestone->issues(); + } + + /** + * @return Snippet[] + */ + public function snippets() + { + $data = $this->api('snippets')->all($this->id); + + $snippets = array(); + foreach ($data as $snippet) { + $snippets[] = Snippet::fromArray($this->getClient(), $this, $snippet); + } + + return $snippets; + } + + /** + * @param string $title + * @param string $filename + * @param string $code + * @param string $lifetime + * @return Snippet + */ + public function createSnippet($title, $filename, $code, $lifetime = null) + { + $data = $this->api('snippets')->create($this->id, $title, $filename, $code, $lifetime); + + return Snippet::fromArray($this->getClient(), $this, $data); + } + + /** + * @param int $id + * @return Snippet + */ + public function snippet($id) + { + $snippet = new Snippet($this, $id, $this->getClient()); + + return $snippet->show(); + } + + /** + * @param int $id + * @return Snippet + */ + public function snippetContent($id) + { + $snippet = new Snippet($this, $id, $this->getClient()); + + return $snippet->content(); + } + + /** + * @param int $id + * @param array $params + * @return Snippet + */ + public function updateSnippet($id, array $params) + { + $snippet = new Snippet($this, $id, $this->getClient()); + + return $snippet->update($params); + } + + /** + * @param int $id + * @return bool + */ + public function removeSnippet($id) + { + $snippet = new Snippet($this, $id, $this->getClient()); + + return $snippet->remove(); + } + + /** + * @param int $group_id + * @return Group + */ + public function transfer($group_id) + { + $group = new Group($group_id, $this->getClient()); + + return $group->transfer($this->id); + } + + /** + * @param int $id + * @return Project + */ + public function forkTo($id) + { + $data = $this->api('projects')->createForkRelation($id, $this->id); + + return Project::fromArray($this->getClient(), $data); + } + + /** + * @param int $id + * @return Project + */ + public function forkFrom($id) + { + return $this->createForkRelation($id); + } + + /** + * @param int $id + * @return Project + */ + public function createForkRelation($id) + { + $data = $this->api('projects')->createForkRelation($this->id, $id); + + return Project::fromArray($this->getClient(), $data); + } + + /** + * @return bool + */ + public function removeForkRelation() + { + $this->api('projects')->removeForkRelation($this->id); + + return true; + } + + /** + * @param string $service_name + * @param array $params + * @return bool + */ + public function setService($service_name, array $params = array()) + { + $this->api('projects')->setService($this->id, $service_name, $params); + + return true; + } + + /** + * @param string $service_name + * @return bool + */ + public function removeService($service_name) + { + $this->api('projects')->removeService($this->id, $service_name); + + return true; + } + + /** + * @return Label[] + */ + public function labels() + { + $data = $this->api('projects')->labels($this->id); + + $labels = array(); + foreach ($data as $label) { + $labels[] = Label::fromArray($this->getClient(), $this, $label); + } + + return $labels; + } + + /** + * @param string $name + * @param string $color + * @return Label + */ + public function addLabel($name, $color) + { + $data = $this->api('projects')->addLabel($this->id, array( + 'name' => $name, + 'color' => $color + )); + + return Label::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $name + * @param array $params + * @return Label + */ + public function updateLabel($name, array $params) + { + if (isset($params['name'])) { + $params['new_name'] = $params['name']; + } + + $params['name'] = $name; + + $data = $this->api('projects')->updateLabel($this->id, $params); + + return Label::fromArray($this->getClient(), $this, $data); + } + + /** + * @param string $name + * @return bool + */ + public function removeLabel($name) + { + $this->api('projects')->removeLabel($this->id, $name); + + return true; + } + + /** + * @return array + */ + public function contributors() + { + $data = $this->api('repo')->contributors($this->id); + + $contributors = array(); + foreach ($data as $contributor) { + $contributors[] = Contributor::fromArray($this->getClient(), $this, $contributor); + } + + return $contributors; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectHook.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectHook.php new file mode 100644 index 0000000000000000000000000000000000000000..a235bff8313f175f3b90ffe5cd21a3f401026c8c --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectHook.php @@ -0,0 +1,98 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class ProjectHook + * + * @property-read int $id + * @property-read string $url + * @property-read int $project_id + * @property-read bool $push_events + * @property-read bool $issues_events + * @property-read bool $merge_requests_events + * @property-read bool $tag_push_events + * @property-read string $created_at + * @property-read Project $project + */ +class ProjectHook extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'project', + 'url', + 'project_id', + 'push_events', + 'issues_events', + 'merge_requests_events', + 'tag_push_events', + 'created_at' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return ProjectHook + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $hook = new static($project, $data['id'], $client); + + return $hook->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } + + /** + * @return ProjectHook + */ + public function show() + { + $data = $this->api('projects')->hook($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return bool + */ + public function delete() + { + $this->api('projects')->removeHook($this->project->id, $this->id); + + return true; + } + + /** + * @return bool + */ + public function remove() + { + return $this->delete(); + } + + /** + * @param array $params + * @return ProjectHook + */ + public function update(array $params) + { + $data = $this->api('projects')->updateHook($this->project->id, $this->id, $params); + + return static::fromArray($this->getClient(), $this->project, $data); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectNamespace.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectNamespace.php new file mode 100644 index 0000000000000000000000000000000000000000..9e3aee4ed5a366635a4b8165ca73dc91fb74ee9b --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/ProjectNamespace.php @@ -0,0 +1,55 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class ProjectNamespace + * + * @property-read int $id + * @property-read string $name + * @property-read string $path + * @property-read string $kind + * @property-read int $owner_id + * @property-read string $created_at + * @property-read string $updated_at + * @property-read string $description + */ +class ProjectNamespace extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'name', + 'path', + 'kind', + 'owner_id', + 'created_at', + 'updated_at', + 'description' + ); + + /** + * @param Client $client + * @param array $data + * @return ProjectNamespace + */ + public static function fromArray(Client $client, array $data) + { + $project = new static($data['id']); + $project->setClient($client); + + return $project->hydrate($data); + } + + /** + * @param int $id + * @param Client $client + */ + public function __construct($id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Session.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Session.php new file mode 100644 index 0000000000000000000000000000000000000000..f9b8177beff6844a93708abdb11ad6c50e947cfc --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Session.php @@ -0,0 +1,70 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Session + * + * @property-read int $id + * @property-read string $email + * @property-read string $name + * @property-read string $private_token + * @property-read string $created_at + * @property-read bool $blocked + */ +class Session extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'email', + 'name', + 'private_token', + 'created_at', + 'blocked' + ); + + /** + * @param Client $client + * @param array $data + * @return Session + */ + public static function fromArray(Client $client, array $data) + { + $session = new static($client); + + return $session->hydrate($data); + } + + /** + * @param Client $client + */ + public function __construct(Client $client = null) + { + $this->setClient($client); + } + + /** + * @return User + */ + public function me() + { + $data = $this->api('users')->show(); + + return User::fromArray($this->getClient(), $data); + } + + /** + * @param string $email + * @param string $password + * @return $this + */ + public function login($email, $password) + { + $data = $this->api('users')->session($email, $password); + + return $this->hydrate($data); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Snippet.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Snippet.php new file mode 100644 index 0000000000000000000000000000000000000000..5d20e0dbf729a5201306703aad054b17b48f6fff --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Snippet.php @@ -0,0 +1,100 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Snippet + * + * @property-read int $id + * @property-read string $title + * @property-read string $file_name + * @property-read string $expires_at + * @property-read string $updated_at + * @property-read string $created_at + * @property-read Project $project + * @property-read User $author + */ +class Snippet extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'title', + 'file_name', + 'author', + 'expires_at', + 'updated_at', + 'created_at', + 'project' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Snippet + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $snippet = new static($project, $data['id'], $client); + + if (isset($data['author'])) { + $data['author'] = User::fromArray($client, $data['author']); + } + + return $snippet->hydrate($data); + } + + /** + * @param Project $project + * @param int $id + * @param Client $client + */ + public function __construct(Project $project, $id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('id', $id); + } + + /** + * @return Snippet + */ + public function show() + { + $data = $this->api('snippets')->show($this->project->id, $this->id); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @param array $params + * @return Snippet + */ + public function update(array $params) + { + $data = $this->api('snippets')->update($this->project->id, $this->id, $params); + + return static::fromArray($this->getClient(), $this->project, $data); + } + + /** + * @return string + */ + public function content() + { + return $this->api('snippets')->content($this->project->id, $this->id); + } + + /** + * @return bool + */ + public function remove() + { + $this->api('snippets')->remove($this->project->id, $this->id); + + return true; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Tag.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Tag.php new file mode 100644 index 0000000000000000000000000000000000000000..6028b3da5882dda97d6259d0d61082ad849cc2e8 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/Tag.php @@ -0,0 +1,53 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class Tag + * + * @property-read string $name + * @property-read bool $protected + * @property-read Commit $commit + * @property-read Project $project + */ +class Tag extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'name', + 'commit', + 'project', + 'protected' + ); + + /** + * @param Client $client + * @param Project $project + * @param array $data + * @return Tag + */ + public static function fromArray(Client $client, Project $project, array $data) + { + $branch = new static($project, $data['name'], $client); + + if (isset($data['commit'])) { + $data['commit'] = Commit::fromArray($client, $project, $data['commit']); + } + + return $branch->hydrate($data); + } + + /** + * @param Project $project + * @param string $name + * @param Client $client + */ + public function __construct(Project $project, $name = null, Client $client = null) + { + $this->setClient($client); + $this->setData('project', $project); + $this->setData('name', $name); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/User.php b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/User.php new file mode 100644 index 0000000000000000000000000000000000000000..5ffffc16e269a426e76a09df7d0b1b83e797b3e5 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/lib/Gitlab/Model/User.php @@ -0,0 +1,227 @@ +<?php namespace Gitlab\Model; + +use Gitlab\Client; + +/** + * Class User + * + * @property-read int $id + * @property-read string $email + * @property-read string $password + * @property-read string $username + * @property-read string $name + * @property-read string $bio + * @property-read string $skype + * @property-read string $linkedin + * @property-read string $twitter + * @property-read bool $dark_scheme + * @property-read int $theme_id + * @property-read int $color_scheme_id + * @property-read bool $blocked + * @property-read int $access_level + * @property-read string $created_at + * @property-read string $extern_uid + * @property-read string $provider + * @property-read string $state + * @property-read bool $is_admin + * @property-read bool $can_create_group + * @property-read bool $can_create_project + * @property-read string $avatar_url + * @property-read string $current_sign_in_at + * @property-read bool $two_factor_enabled + */ +class User extends AbstractModel +{ + /** + * @var array + */ + protected static $properties = array( + 'id', + 'email', + 'password', + 'username', + 'name', + 'bio', + 'skype', + 'linkedin', + 'twitter', + 'dark_scheme', + 'theme_id', + 'color_scheme_id', + 'blocked', + 'projects_limit', + 'access_level', + 'created_at', + 'extern_uid', + 'provider', + 'state', + 'is_admin', + 'can_create_group', + 'can_create_project', + 'avatar_url', + 'current_sign_in_at', + 'two_factor_enabled' + ); + + /** + * @param Client $client + * @param array $data + * @return User + */ + public static function fromArray(Client $client, array $data) + { + $id = isset($data['id']) ? $data['id'] : 0; + + $user = new static($id, $client); + + return $user->hydrate($data); + } + + /** + * @param Client $client + * @param string $email + * @param string $password + * @param array $params + * @return User + */ + public static function create(Client $client, $email, $password, array $params = array()) + { + $data = $client->api('users')->create($email, $password, $params); + + return static::fromArray($client, $data); + } + + /** + * @param int $id + * @param Client $client + */ + public function __construct($id = null, Client $client = null) + { + $this->setClient($client); + $this->setData('id', $id); + } + + /** + * @return User + */ + public function show() + { + $data = $this->api('users')->show($this->id); + + return static::fromArray($this->getClient(), $data); + } + + /** + * @param array $params + * @return User + */ + public function update(array $params) + { + $data = $this->api('users')->update($this->id, $params); + + return static::fromArray($this->getClient(), $data); + } + + /** + * @return bool + */ + public function remove() + { + $this->api('users')->remove($this->id); + + return true; + } + + /** + * @return bool + */ + public function block() + { + $this->api('users')->block($this->id); + + return true; + } + + /** + * @return bool + */ + public function unblock() + { + $this->api('users')->unblock($this->id); + + return true; + } + + /** + * @return Key[] + */ + public function keys() + { + $data = $this->api('users')->keys(); + + $keys = array(); + foreach ($data as $key) { + $keys[] = Key::fromArray($this->getClient(), $key); + } + + return $keys; + } + + /** + * @param string $title + * @param string $key + * @return Key + */ + public function createKey($title, $key) + { + $data = $this->api('users')->createKey($title, $key); + + return Key::fromArray($this->getClient(), $data); + } + + /** + * @param string $title + * @param string $key + * @return Key + */ + public function createKeyForUser($user_id, $title, $key) + { + $data = $this->api('users')->createKeyForUser($user_id, $title, $key); + + return Key::fromArray($this->getClient(), $data); + } + + /** + * @param int $id + * @return bool + */ + public function removeKey($id) + { + $this->api('users')->removeKey($id); + + return true; + } + + /** + * @param int $group_id + * @param int $access_level + * @return User + */ + public function addToGroup($group_id, $access_level) + { + $group = new Group($group_id, $this->getClient()); + + return $group->addMember($this->id, $access_level); + } + + /** + * @param int $group_id + * @return bool + */ + public function removeFromGroup($group_id) + { + $group = new Group($group_id, $this->getClient()); + + return $group->removeMember($this->id); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/phpunit.xml.dist b/vendor/m4tthumphrey/php-gitlab-api/phpunit.xml.dist new file mode 100644 index 0000000000000000000000000000000000000000..e01386f15e1d1938f4f166c60ffdb9a2d34f418c --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/phpunit.xml.dist @@ -0,0 +1,25 @@ +<?xml version="1.0" encoding="UTF-8"?> + +<phpunit backupGlobals="false" + backupStaticAttributes="false" + colors="true" + convertErrorsToExceptions="true" + convertNoticesToExceptions="true" + convertWarningsToExceptions="true" + processIsolation="false" + stopOnFailure="false" + syntaxCheck="false" + bootstrap="test/bootstrap.php" + > + <testsuites> + <testsuite name="php-gitlab-api Test Suite"> + <directory>./test/Gitlab/</directory> + </testsuite> + </testsuites> + + <filter> + <whitelist> + <directory suffix=".php">./lib/Gitlab/</directory> + </whitelist> + </filter> +</phpunit> \ No newline at end of file diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/AbstractApiTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/AbstractApiTest.php new file mode 100644 index 0000000000000000000000000000000000000000..2b3374f4eed4c3a1549172c0413b7d3881b9936b --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/AbstractApiTest.php @@ -0,0 +1,177 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; +use Gitlab\Client; +use Gitlab\HttpClient\Message\Response; + +class AbstractApiTest extends TestCase +{ + /** + * @test + */ + public function shouldPassGETRequestToClient() + { + $response = $this->getResponse('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('get') + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) + ->will($this->returnValue($response)); + + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = $this->getAbstractApiObject($client); + $this->assertEquals('value', $api->get('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + } + + /** + * @test + */ + public function shouldPassPOSTRequestToClient() + { + $response = $this->getResponse('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('post') + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) + ->will($this->returnValue($response)); + + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = $this->getAbstractApiObject($client); + $this->assertEquals('value', $api->post('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + } + + /** + * @test + */ + public function shouldPassPUTRequestToClient() + { + $response = $this->getResponse('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('put') + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) + ->will($this->returnValue($response)); + + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = $this->getAbstractApiObject($client); + $this->assertEquals('value', $api->put('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + } + + /** + * @test + */ + public function shouldPassDELETERequestToClient() + { + $response = $this->getResponse('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('delete') + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) + ->will($this->returnValue($response)); + + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = $this->getAbstractApiObject($client); + $this->assertEquals('value', $api->delete('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + } + + /** + * @test + */ + public function shouldPassPATCHRequestToClient() + { + $response = $this->getResponse('value'); + + $httpClient = $this->getHttpMock(); + $httpClient + ->expects($this->any()) + ->method('patch') + ->with('/path', array('param1' => 'param1value'), array('header1' => 'header1value')) + ->will($this->returnValue($response)); + + $client = $this->getClientMock(); + $client->setHttpClient($httpClient); + + $api = $this->getAbstractApiObject($client); + $this->assertEquals('value', $api->patch('/path', array('param1' => 'param1value'), array('header1' => 'header1value'))); + } + + /** + * @param mixed $value + * @return Response + */ + protected function getResponse($value) + { + $response = new Response(); + $response->setContent($value); + + return $response; + } + + /** + * @param Client $client + * @return AbstractApiTestInstance + */ + protected function getAbstractApiObject(Client $client) + { + return new AbstractApiTestInstance($client); + } +} + +class AbstractApiTestInstance extends AbstractApi +{ + /** + * {@inheritDoc} + */ + public function get($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::get($path, $parameters, $requestHeaders); + } + + /** + * {@inheritDoc} + */ + public function post($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::post($path, $parameters, $requestHeaders); + } + + /** + * {@inheritDoc} + */ + public function patch($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::patch($path, $parameters, $requestHeaders); + } + + /** + * {@inheritDoc} + */ + public function put($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::put($path, $parameters, $requestHeaders); + } + + /** + * {@inheritDoc} + */ + public function delete($path, array $parameters = array(), $requestHeaders = array()) + { + return parent::delete($path, $parameters, $requestHeaders); + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ApiTestCase.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ApiTestCase.php new file mode 100644 index 0000000000000000000000000000000000000000..a695d97cb8007b5ef05014099192368a099403bc --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ApiTestCase.php @@ -0,0 +1,23 @@ +<?php namespace Gitlab\Tests\Api; + +abstract class ApiTestCase extends TestCase +{ + abstract protected function getApiClass(); + + /** + * @param array $methods + * @return \PHPUnit_Framework_MockObject_MockObject|mixed + */ + protected function getApiMock($methods = array()) + { + $client = $this->getClientMock(); + + $methods = array_merge(array('get', 'post', 'postRaw', 'patch', 'delete', 'put', 'head'), $methods); + + return $this->getMockBuilder($this->getApiClass()) + ->setMethods($methods) + ->setConstructorArgs(array($client)) + ->getMock() + ; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/GroupsTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/GroupsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..b84baffdaeac65042fbb3cab795db0d925ba22e2 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/GroupsTest.php @@ -0,0 +1,247 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; + +class GroupsTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllGroups() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups', array('page' => 1, 'per_page' => 10)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1, 10)); + } + + /** + * @test + */ + public function shouldNotNeedPaginationWhenGettingGroups() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldSearchGroups() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups?search=some%20group', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('some group')); + } + + /** + * @test + */ + public function shouldSearchGroupsWithPagination() + { + $expectedArray = array( + array('id' => 1, 'name' => 'A group'), + array('id' => 2, 'name' => 'Another group'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups?search=group', array('page' => 2, 'per_page' => 5)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('group', 2, 5)); + } + + /** + * @test + */ + public function shouldShowGroup() + { + $expectedArray = array('id' => 1, 'name' => 'A group'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups/1') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1)); + } + + /** + * @test + */ + public function shouldCreateGroup() + { + $expectedArray = array('id' => 1, 'name' => 'A new group'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => null)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('A new group', 'a-new-group')); + } + + /** + * @test + */ + public function shouldCreateGroupWithDescription() + { + $expectedArray = array('id' => 1, 'name' => 'A new group'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('groups', array('name' => 'A new group', 'path' => 'a-new-group', 'description' => 'Description')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('A new group', 'a-new-group', 'Description')); + } + + /** + * @test + */ + public function shouldTransferProjectToGroup() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('groups/1/projects/2') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->transfer(1, 2)); + } + + /** + * @test + */ + public function shouldGetMembers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt'), + array('id' => 2, 'name' => 'Bob') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('groups/1/members') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->members(1)); + } + + /** + * @test + */ + public function shouldAddMember() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('groups/1/members', array('user_id' => 2, 'access_level' => 3)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addMember(1, 2, 3)); + } + + /** + * @test + */ + public function shouldSaveMember() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('groups/1/members/2', array('access_level' => 4)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->saveMember(1, 2, 4)); + } + + /** + * @test + */ + public function shouldRemoveMember() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('groups/1/members/2') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeMember(1, 2)); + } + + /** + * @test + */ + public function shouldRemoveGroup() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('groups/1') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->remove(1)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Groups'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/IssuesTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/IssuesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..86ffb977145075433ab00b6bb32d2e6f6da51609 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/IssuesTest.php @@ -0,0 +1,194 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; + +class IssuesTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllIssues() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An issue'), + array('id' => 2, 'title' => 'Another issue'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('issues', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetProjectIssuesWithPagination() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An issue'), + array('id' => 2, 'title' => 'Another issue'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues', array('page' => 2, 'per_page' => 5)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1, 2, 5)); + } + + /** + * @test + */ + public function shouldGetProjectIssuesWithParams() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An issue'), + array('id' => 2, 'title' => 'Another issue'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues', array('page' => 2, 'per_page' => 5, 'order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'open')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1, 2, 5, array('order_by' => 'created_at', 'sort' => 'desc', 'labels' => 'foo,bar', 'state' => 'open'))); + } + + /** + * @test + */ + public function shouldShowIssue() + { + $expectedArray = array('id' => 2, 'title' => 'Another issue'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1, 2)); + } + + /** + * @test + */ + public function shouldCreateIssue() + { + $expectedArray = array('id' => 3, 'title' => 'A new issue'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/issues', array('title' => 'A new issue', 'labels' => 'foo,bar')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create(1, array('title' => 'A new issue', 'labels' => 'foo,bar'))); + } + + /** + * @test + */ + public function shouldUpdateIssue() + { + $expectedArray = array('id' => 2, 'title' => 'A renamed issue'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/issues/2', array('title' => 'A renamed issue', 'labels' => 'foo')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(1, 2, array('title' => 'A renamed issue', 'labels' => 'foo'))); + } + + /** + * @test + */ + public function shouldGetIssueComments() + { + $expectedArray = array( + array('id' => 1, 'body' => 'A comment'), + array('id' => 2, 'body' => 'Another comment') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/2/notes') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->showComments(1, 2)); + } + + /** + * @test + */ + public function shouldGetIssueComment() + { + $expectedArray = array('id' => 3, 'body' => 'A new comment'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/issues/2/notes/3') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->showComment(1, 2, 3)); + } + + /** + * @test + */ + public function shouldCreateComment() + { + $expectedArray = array('id' => 3, 'body' => 'A new comment'); + + $api = $this->getApiMock(); + $api->expects($this->exactly(2)) + ->method('post') + ->with('projects/1/issues/2/notes', array('body' => 'A new comment')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addComment(1, 2, array('body' => 'A new comment'))); + $this->assertEquals($expectedArray, $api->addComment(1, 2, 'A new comment')); + } + + /** + * @test + */ + public function shouldUpdateComment() + { + $expectedArray = array('id' => 3, 'body' => 'An edited comment'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/issues/2/notes/3', array('body' => 'An edited comment')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->updateComment(1, 2, 3, 'An edited comment')); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Issues'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MergeRequestsTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MergeRequestsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..92114fcc05bc58c49e2abf8c1e3f7e9211e4f6a8 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MergeRequestsTest.php @@ -0,0 +1,331 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; +use Gitlab\Api\MergeRequests; + +class MergeRequestsTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetMergeRequestListWithDefaultParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_requests', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE, 'state' => MergeRequests::STATE_ALL, 'order_by' => MergeRequests::ORDER_BY, 'sort' => MergeRequests::SORT)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->getList(1)); + } + + /** + * @test + */ + public function shouldGetAll() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_ALL, 1, AbstractApi::PER_PAGE, MergeRequests::ORDER_BY, MergeRequests::SORT) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1)); + } + + /** + * @test + */ + public function shouldGetAllWithParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_ALL, 2, 5, 'title', 'desc') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1, 2, 5, 'title', 'desc')); + } + + /** + * @test + */ + public function shouldGetMerged() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_MERGED, 1, AbstractApi::PER_PAGE, MergeRequests::ORDER_BY, MergeRequests::SORT) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->merged(1)); + } + + /** + * @test + */ + public function shouldGetMergedWithParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_MERGED, 3, 15, 'updated_at', 'asc') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->merged(1, 3, 15, 'updated_at', 'asc')); + } + + /** + * @test + */ + public function shouldGetOpened() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_OPENED, 1, AbstractApi::PER_PAGE, MergeRequests::ORDER_BY, MergeRequests::SORT) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->opened(1)); + } + + /** + * @test + */ + public function shouldGetOpenedWithParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_OPENED, 2, 4, 'title', 'desc') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->opened(1, 2, 4, 'title', 'desc')); + } + + /** + * @test + */ + public function shouldGetClosed() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_CLOSED, 1, AbstractApi::PER_PAGE, MergeRequests::ORDER_BY, MergeRequests::SORT) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->closed(1)); + } + + /** + * @test + */ + public function shouldGetClosedWithParams() + { + $expectedArray = $this->getMultipleMergeRequestsData(); + + $api = $this->getApiMock(array('getList')); + $api->expects($this->once()) + ->method('getList') + ->with(1, MergeRequests::STATE_CLOSED, 2, 4, 'title', 'desc') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->closed(1, 2, 4, 'title', 'desc')); + } + + /** + * @test + */ + public function shouldShowMergeRequest() + { + $expectedArray = array('id' => 2, 'name' => 'A merge request'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_request/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1, 2)); + } + + /** + * @test + */ + public function shouldCreateMergeRequestWithoutOptionalParams() + { + $expectedArray = array('id' => 3, 'title' => 'Merge Request'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_requests', array( + 'title' => 'Merge Request', + 'target_branch' => 'master', + 'source_branch' => 'develop', + 'description' => null, + 'assignee_id' => null, + 'target_project_id' => null + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create(1, 'develop', 'master', 'Merge Request')); + } + + /** + * @test + */ + public function shouldCreateMergeRequestWithOptionalParams() + { + $expectedArray = array('id' => 3, 'title' => 'Merge Request'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_requests', array( + 'title' => 'Merge Request', + 'target_branch' => 'master', + 'source_branch' => 'develop', + 'description' => 'Some changes', + 'assignee_id' => 6, + 'target_project_id' => 20 + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create(1, 'develop', 'master', 'Merge Request', 6, 20, 'Some changes')); + } + + /** + * @test + */ + public function shouldUpdateMergeRequest() + { + $expectedArray = array('id' => 2, 'title' => 'Updated title'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/merge_request/2', array('title' => 'Updated title', 'description' => 'No so many changes now', 'state_event' => 'close')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(1, 2, array( + 'title' => 'Updated title', + 'description' => 'No so many changes now', + 'state_event' => 'close' + ))); + } + + /** + * @test + */ + public function shouldMergeMergeRequest() + { + $expectedArray = array('id' => 2, 'title' => 'Updated title'); + + $api = $this->getApiMock(); + $api->expects($this->exactly(2)) + ->method('put') + ->with('projects/1/merge_request/2/merge', array('merge_commit_message' => 'Accepted')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->merge(1, 2, 'Accepted')); + $this->assertEquals($expectedArray, $api->merge(1, 2, array('merge_commit_message' => 'Accepted'))); + } + + /** + * @test + */ + public function shouldGetMergeRequestComments() + { + $expectedArray = array( + array('id' => 1, 'note' => 'A comment'), + array('id' => 2, 'note' => 'Another comment') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_request/2/comments') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->showComments(1, 2)); + } + + /** + * @test + */ + public function shouldAddMergeRequestComment() + { + $expectedArray = array('id' => 2, 'title' => 'A comment'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/merge_request/2/comments', array('note' => 'A comment')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addComment(1, 2, 'A comment')); + } + + /** + * @test + */ + public function shouldGetMergeRequestChanges() + { + $expectedArray = array('id' => 1, 'title' => 'A merge request'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/merge_request/2/changes') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->changes(1, 2)); + } + + protected function getMultipleMergeRequestsData() + { + return array( + array('id' => 1, 'title' => 'A merge request'), + array('id' => 2, 'title' => 'Another merge request') + ); + } + + protected function getApiClass() + { + return 'Gitlab\Api\MergeRequests'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MilestonesTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MilestonesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..e22c2370ff9dfbc49db5087284329da980253438 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/MilestonesTest.php @@ -0,0 +1,100 @@ +<?php namespace Gitlab\Tests\Api; + +class MilestonesTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllMilestones() + { + $expectedArray = array( + array('id' => 1, 'title' => 'A milestone'), + array('id' => 2, 'title' => 'Another milestone'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/milestones') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1)); + } + + /** + * @test + */ + public function shouldShowMilestone() + { + $expectedArray = array('id' => 1, 'name' => 'A milestone'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/milestones/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1, 2)); + } + + /** + * @test + */ + public function shouldCreateMilestone() + { + $expectedArray = array('id' => 3, 'title' => 'A new milestone'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/milestones', array('description' => 'Some text', 'title' => 'A new milestone')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create(1, array('description' => 'Some text', 'title' => 'A new milestone'))); + } + + /** + * @test + */ + public function shouldUpdateMilestone() + { + $expectedArray = array('id' => 3, 'title' => 'Updated milestone'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/milestones/3', array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(1, 3, array('title' => 'Updated milestone', 'due_date' => '2015-04-01', 'state_event' => 'close'))); + } + + /** + * @test + */ + public function shouldGetMilestonesIssues() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An issue'), + array('id' => 2, 'title' => 'Another issue'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/milestones/3/issues') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->issues(1, 3)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Milestones'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectNamespacesTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectNamespacesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..1feb5ff1f4146d0b9e020a2ec4f601364aebf5ce --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectNamespacesTest.php @@ -0,0 +1,70 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; + +class ProjectNamespacesTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllNamespaces() + { + $expectedArray = array( + array('id' => 1, 'name' => 'bespokes'), + array('id' => 2, 'name' => 'internal') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('namespaces', array('page' => 1, 'per_page' => 10)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1, 10)); + } + + /** + * @test + */ + public function shouldNotNeedPaginationWhenGettingNamespaces() + { + $expectedArray = array( + array('id' => 1, 'name' => 'bespokes'), + array('id' => 2, 'name' => 'internal') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('namespaces', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + /** + * @test + */ + public function shouldSearchNamespaces() + { + $expectedArray = array( + array('id' => 1, 'name' => 'bespokes'), + array('id' => 2, 'name' => 'internal') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('namespaces', array('search' => 'term', 'page' => 1, 'per_page' => 10)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('term', 1, 10)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\ProjectNamespaces'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectsTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..fdcdf5141d3b137981b4659ae6bd6f106e9df06f --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/ProjectsTest.php @@ -0,0 +1,691 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; +use Gitlab\Api\Projects; + +class ProjectsTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects/all', $expectedArray); + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetAllProjectsSortedByName() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects/all', $expectedArray, 1, 5, 'name', 'asc'); + + $this->assertEquals($expectedArray, $api->all(1, 5, 'name')); + } + + /** + * @test + */ + public function shouldNotNeedPaginationWhenGettingProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/all', array('page' => 1, 'per_page' => AbstractApi::PER_PAGE, 'order_by' => Projects::ORDER_BY, 'sort' => Projects::SORT)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldGetAccessibleProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects', $expectedArray, 2, 7); + + $this->assertEquals($expectedArray, $api->accessible(2, 7)); + } + + /** + * @test + */ + public function shouldGetOwnedProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects/owned', $expectedArray, 3, 50); + + $this->assertEquals($expectedArray, $api->owned(3, 50)); + } + + /** + * @test + */ + public function shouldSearchProjects() + { + $expectedArray = $this->getMultipleProjectsData(); + + $api = $this->getMultipleProjectsRequestMock('projects/search/a%20project', $expectedArray); + $this->assertEquals($expectedArray, $api->search('a project')); + + $api = $this->getMultipleProjectsRequestMock('projects/search/a%2Eproject', $expectedArray); + $this->assertEquals($expectedArray, $api->search('a.project')); + + $api = $this->getMultipleProjectsRequestMock('projects/search/a%2Fproject', $expectedArray); + $this->assertEquals($expectedArray, $api->search('a/project')); + } + + /** + * @test + */ + public function shouldShowProject() + { + $expectedArray = array('id' => 1, 'name' => 'Project Name'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1)); + } + + /** + * @test + */ + public function shouldCreateProject() + { + $expectedArray = array('id' => 1, 'name' => 'Project Name'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects', array('name' => 'Project Name', 'issues_enabled' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('Project Name', array( + 'issues_enabled' => true + ))); + } + + /** + * @test + */ + public function shouldUpdateProject() + { + $expectedArray = array('id' => 1, 'name' => 'Updated Name'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1', array('name' => 'Updated Name', 'issues_enabled' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(1, array( + 'name' => 'Updated Name', + 'issues_enabled' => true + ))); + } + + /** + * @test + */ + public function shouldCreateProjectForUser() + { + $expectedArray = array('id' => 1, 'name' => 'Project Name'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/user/1', array('name' => 'Project Name', 'issues_enabled' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createForUser(1, 'Project Name', array( + 'issues_enabled' => true + ))); + } + + /** + * @test + */ + public function shouldRemoveProject() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->remove(1)); + } + + /** + * @test + */ + public function shouldGetMembers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt'), + array('id' => 2, 'name' => 'Bob') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/members') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->members(1)); + } + + /** + * @test + */ + public function shouldGetMembersWithQuery() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/members', array('query' => 'at')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->members(1, 'at')); + } + + /** + * @test + */ + public function shouldGetMember() + { + $expectedArray = array('id' => 2, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/members/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->member(1, 2)); + } + + /** + * @test + */ + public function shouldAddMember() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/members', array('user_id' => 2, 'access_level' => 3)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addMember(1, 2, 3)); + } + + /** + * @test + */ + public function shouldSaveMember() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/members/2', array('access_level' => 4)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->saveMember(1, 2, 4)); + } + + /** + * @test + */ + public function shouldRemoveMember() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/members/2') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeMember(1, 2)); + } + + /** + * @test + */ + public function shouldGetHooks() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Test hook'), + array('id' => 2, 'name' => 'Another hook'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/hooks') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->hooks(1)); + } + + /** + * @test + */ + public function shouldGetHook() + { + $expectedArray = array('id' => 2, 'name' => 'Another hook'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/hooks/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->hook(1, 2)); + } + + /** + * @test + */ + public function shouldAddHook() + { + $expectedArray = array('id' => 3, 'name' => 'A new hook', 'url' => 'http://www.example.com'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/hooks', array('url' => 'http://www.example.com', 'push_events' => true, 'issues_events' => true, 'merge_requests_events' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addHook(1, 'http://www.example.com', array('push_events' => true, 'issues_events' => true, 'merge_requests_events' => true))); + } + + /** + * @test + */ + public function shouldAddHookWithOnlyUrl() + { + $expectedArray = array('id' => 3, 'name' => 'A new hook', 'url' => 'http://www.example.com'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/hooks', array('url' => 'http://www.example.com', 'push_events' => true)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addHook(1, 'http://www.example.com')); + } + + /** + * @test + */ + public function shouldAddHookWithoutPushEvents() + { + $expectedArray = array('id' => 3, 'name' => 'A new hook', 'url' => 'http://www.example.com'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/hooks', array('url' => 'http://www.example.com', 'push_events' => false)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addHook(1, 'http://www.example.com', array('push_events' => false))); + } + + /** + * @test + */ + public function shouldUpdateHook() + { + $expectedArray = array('id' => 3, 'name' => 'A new hook', 'url' => 'http://www.example.com'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/hooks/3', array('url' => 'http://www.example-test.com', 'push_events' => false)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->updateHook(1, 3, array('url' => 'http://www.example-test.com', 'push_events' => false))); + } + + /** + * @test + */ + public function shouldRemoveHook() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/hooks/2') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeHook(1, 2)); + } + + /** + * @test + */ + public function shouldGetKeys() + { + $expectedArray = array( + array('id' => 1, 'title' => 'test-key'), + array('id' => 2, 'title' => 'another-key') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/keys') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->keys(1)); + } + + /** + * @test + */ + public function shouldGetKey() + { + $expectedArray = array('id' => 2, 'title' => 'another-key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/keys/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->key(1, 2)); + } + + /** + * @test + */ + public function shouldAddKey() + { + $expectedArray = array('id' => 3, 'title' => 'new-key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/keys', array('title' => 'new-key', 'key' => '...')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addKey(1, 'new-key', '...')); + } + + /** + * @test + */ + public function shouldRemoveKey() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/keys/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeKey(1, 3)); + } + + /** + * @test + */ + public function shouldGetEvents() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An event'), + array('id' => 2, 'title' => 'Another event') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/events', array( + 'page' => 1, + 'per_page' => AbstractApi::PER_PAGE + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->events(1)); + } + + /** + * @test + */ + public function shouldGetEventsWithPagination() + { + $expectedArray = array( + array('id' => 1, 'title' => 'An event'), + array('id' => 2, 'title' => 'Another event') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/events', array( + 'page' => 2, + 'per_page' => 15 + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->events(1, 2, 15)); + } + + /** + * @test + */ + public function shouldGetLabels() + { + $expectedArray = array( + array('name' => 'bug', 'color' => '#000000'), + array('name' => 'feature', 'color' => '#ff0000') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/labels') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->labels(1)); + } + + /** + * @test + */ + public function shouldAddLabel() + { + $expectedArray = array('name' => 'bug', 'color' => '#000000'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/labels', array('name' => 'wont-fix', 'color' => '#ffffff')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->addLabel(1, array('name' => 'wont-fix', 'color' => '#ffffff'))); + } + + /** + * @test + */ + public function shouldUpdateLabel() + { + $expectedArray = array('name' => 'bug', 'color' => '#00ffff'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/labels', array('name' => 'bug', 'new_name' => 'big-bug', 'color' => '#00ffff')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->updateLabel(1, array('name' => 'bug', 'new_name' => 'big-bug', 'color' => '#00ffff'))); + } + + /** + * @test + */ + public function shouldRemoveLabel() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/labels', array('name' => 'bug')) + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeLabel(1, 'bug')); + } + + /** + * @test + */ + public function shouldCreateForkRelation() + { + $expectedArray = array('project_id' => 1, 'forked_id' => 2); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/fork/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createForkRelation(1, 2)); + } + + /** + * @test + */ + public function shouldRemoveForkRelation() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/2/fork') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeForkRelation(2)); + } + + /** + * @test + */ + public function shouldSetService() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/services/hipchat', array('param' => 'value')) + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->setService(1, 'hipchat', array('param' => 'value'))); + } + + /** + * @test + */ + public function shouldRemoveService() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/services/hipchat') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeService(1, 'hipchat')); + } + + protected function getMultipleProjectsRequestMock($path, $expectedArray = array(), $page = 1, $per_page = 20, $order_by = 'created_at', $sort = 'asc') + { + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with($path, array('page' => $page, 'per_page' => $per_page, 'order_by' => $order_by, 'sort' => $sort)) + ->will($this->returnValue($expectedArray)) + ; + + return $api; + } + + protected function getMultipleProjectsData() + { + return array( + array('id' => 1, 'name' => 'A project'), + array('id' => 2, 'name' => 'Another project') + ); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Projects'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/RepositoriesTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/RepositoriesTest.php new file mode 100644 index 0000000000000000000000000000000000000000..d3fd61faacea31c743d78f5090ec6b6d9439991f --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/RepositoriesTest.php @@ -0,0 +1,516 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; + +class RepositoriesTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetBranches() + { + $expectedArray = array( + array('name' => 'master'), + array('name' => 'develop') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/branches') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->branches(1)); + } + + /** + * @test + */ + public function shouldGetBranch() + { + $expectedArray = array('name' => 'master'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/branches/master') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->branch(1, 'master')); + } + + /** + * @test + */ + public function shouldCreateBranch() + { + $expectedArray = array('name' => 'feature'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/branches', array('branch_name' => 'feature', 'ref' => 'master')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createBranch(1, 'feature', 'master')); + } + + /** + * @test + */ + public function shouldDeleteBranch() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/repository/branches/master') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->deleteBranch(1, 'master')); + } + + /** + * @test + */ + public function shouldProtectBranch() + { + $expectedArray = array('name' => 'master'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/repository/branches/master/protect') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->protectBranch(1, 'master')); + } + + /** + * @test + */ + public function shouldUnprotectBranch() + { + $expectedArray = array('name' => 'master'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/repository/branches/master/unprotect') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->unprotectBranch(1, 'master')); + } + + /** + * @test + */ + public function shouldGetTags() + { + $expectedArray = array( + array('name' => '1.0'), + array('name' => '1.1') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/tags') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->tags(1)); + } + + /** + * @test + */ + public function shouldCreateTag() + { + $expectedArray = array('name' => '1.0'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/tags', array( + 'tag_name' => '1.0', + 'ref' => 'abcd1234', + 'message' => '1.0 release' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createTag(1, '1.0', 'abcd1234', '1.0 release')); + } + + /** + * @test + */ + public function shouldGetCommits() + { + $expectedArray = array( + array('id' => 'abcd1234', 'title' => 'A commit'), + array('id' => 'efgh5678', 'title' => 'Another commit') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits', array('page' => 0, 'per_page' => AbstractApi::PER_PAGE, 'ref_name' => null)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commits(1)); + } + + /** + * @test + */ + public function shouldGetCommitsWithParams() + { + $expectedArray = array( + array('id' => 'abcd1234', 'title' => 'A commit'), + array('id' => 'efgh5678', 'title' => 'Another commit') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits', array('page' => 2, 'per_page' => 25, 'ref_name' => 'master')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commits(1, 2, 25, 'master')); + } + + /** + * @test + */ + public function shouldGetCommit() + { + $expectedArray = array('id' => 'abcd1234', 'title' => 'A commit'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits/abcd1234') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commit(1, 'abcd1234')); + } + + /** + * @test + */ + public function shouldGetCommitComments() + { + $expectedArray = array( + array('note' => 'A commit message'), + array('note' => 'Another commit message') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits/abcd1234/comments') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->commitComments(1, 'abcd1234')); + } + + /** + * @test + */ + public function shouldCreateCommitComment() + { + $expectedArray = array('id' => 2, 'title' => 'A new comment'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/commits/abcd1234/comments', array('note' => 'A new comment')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createCommitComment(1, 'abcd1234', 'A new comment')); + } + + /** + * @test + */ + public function shouldCreateCommitCommentWithParams() + { + $expectedArray = array('id' => 2, 'title' => 'A new comment'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/commits/abcd1234/comments', array( + 'note' => 'A new comment', + 'path' => '/some/file.txt', + 'line' => 123, 'line_type' => 'old' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createCommitComment(1, 'abcd1234', 'A new comment', array( + 'path' => '/some/file.txt', + 'line' => 123, + 'line_type' => 'old' + ))); + } + + /** + * @test + */ + public function shouldCompare() + { + $expectedArray = array('commit' => 'object'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/compare?from=master&to=feature') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->compare(1, 'master', 'feature')); + } + + /** + * @test + */ + public function shouldGetDiff() + { + $expectedArray = array( + array('diff' => '--- ...'), + array('diff' => '+++ ...') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits/abcd1234/diff') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->diff(1, 'abcd1234')); + } + + /** + * @test + */ + public function shouldGetTree() + { + $expectedArray = array( + array('name' => 'file1.txt'), + array('name' => 'file2.csv') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/tree') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->tree(1)); + } + + /** + * @test + */ + public function shouldGetTreeWithParams() + { + $expectedArray = array( + array('name' => 'dir/file1.txt'), + array('name' => 'dir/file2.csv') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/tree', array('path' => 'dir/', 'ref_name' => 'master')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->tree(1, array('path' => 'dir/', 'ref_name' => 'master'))); + } + + /** + * @test + */ + public function shouldGetBlob() + { + $expectedString = 'something in a file'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/commits/abcd1234/blob', array('filepath' => 'dir/file1.txt')) + ->will($this->returnValue($expectedString)) + ; + + $this->assertEquals($expectedString, $api->blob(1, 'abcd1234', 'dir/file1.txt')); + } + + /** + * @test + */ + public function shouldGetFile() + { + $expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/files', array('file_path' => 'dir/file1.txt', 'ref' => 'abcd1234')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->getFile(1, 'dir/file1.txt', 'abcd1234')); + } + + /** + * @test + */ + public function shouldCreateFile() + { + $expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/files', array( + 'file_path' => 'dir/file1.txt', + 'branch_name' => 'master', + 'encoding' => null, + 'content' => 'some contents', + 'commit_message' => 'Added new file' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createFile(1, 'dir/file1.txt', 'some contents', 'master', 'Added new file')); + } + + /** + * @test + */ + public function shouldCreateFileWithEncoding() + { + $expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/repository/files', array( + 'file_path' => 'dir/file1.txt', + 'branch_name' => 'master', + 'encoding' => 'text', + 'content' => 'some contents', + 'commit_message' => 'Added new file' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createFile(1, 'dir/file1.txt', 'some contents', 'master', 'Added new file', 'text')); + } + + /** + * @test + */ + public function shouldUpdateFile() + { + $expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/repository/files', array( + 'file_path' => 'dir/file1.txt', + 'branch_name' => 'master', + 'encoding' => null, + 'content' => 'some new contents', + 'commit_message' => 'Updated new file' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->updateFile(1, 'dir/file1.txt', 'some new contents', 'master', 'Updated new file')); + } + + /** + * @test + */ + public function shouldUpdateFileWithEncoding() + { + $expectedArray = array('file_name' => 'file1.txt', 'file_path' => 'dir/file1.txt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/repository/files', array( + 'file_path' => 'dir/file1.txt', + 'branch_name' => 'master', + 'encoding' => 'base64', + 'content' => 'some new contents', + 'commit_message' => 'Updated file' + )) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->updateFile(1, 'dir/file1.txt', 'some new contents', 'master', 'Updated file', 'base64')); + } + + /** + * @test + */ + public function shouldDeleteFile() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/repository/files', array('file_path' => 'dir/file1.txt', 'branch_name' => 'master', 'commit_message' => 'Deleted file')) + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->deleteFile(1, 'dir/file1.txt', 'master', 'Deleted file')); + } + + /** + * @test + */ + public function shouldGetContributors() + { + $expectedArray = array( + array('name' => 'Matt'), + array('name' => 'Bob') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/repository/contributors') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->contributors(1)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Repositories'; + } +} \ No newline at end of file diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SnippetsTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SnippetsTest.php new file mode 100644 index 0000000000000000000000000000000000000000..694aac5959ddecfade4f6b1bedf6d32580003517 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SnippetsTest.php @@ -0,0 +1,114 @@ +<?php namespace Gitlab\Tests\Api; + +class SnippetsTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllSnippets() + { + $expectedArray = array( + array('id' => 1, 'title' => 'A snippet'), + array('id' => 2, 'title' => 'Another snippet'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/snippets') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(1)); + } + + /** + * @test + */ + public function shouldShowSnippet() + { + $expectedArray = array('id' => 2, 'title' => 'Another snippet'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/snippets/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1, 2)); + } + + /** + * @test + */ + public function shouldCreateSnippet() + { + $expectedArray = array('id' => 3, 'title' => 'A new snippet'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('projects/1/snippets', array('title' => 'A new snippet', 'code' => 'A file', 'file_name' => 'file.txt')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create(1, 'A new snippet', 'file.txt', 'A file')); + } + + /** + * @test + */ + public function shouldUpdateSnippet() + { + $expectedArray = array('id' => 3, 'title' => 'Updated snippet'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('projects/1/snippets/3', array('title' => 'Updated snippet', 'code' => 'New content', 'file_name' => 'new_file.txt')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(1, 3, array('file_name' => 'new_file.txt', 'code' => 'New content', 'title' => 'Updated snippet'))); + } + + /** + * @test + */ + public function shouldShowContent() + { + $expectedString = 'New content'; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('projects/1/snippets/3/raw') + ->will($this->returnValue($expectedString)) + ; + + $this->assertEquals($expectedString, $api->content(1, 3)); + } + + /** + * @test + */ + public function shouldRemoveSnippet() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('projects/1/snippets/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->remove(1, 3)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Snippets'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SystemHooksTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SystemHooksTest.php new file mode 100644 index 0000000000000000000000000000000000000000..3bf16bce6bcd948fad1f0d3c280fc4a4a478e7cb --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/SystemHooksTest.php @@ -0,0 +1,80 @@ +<?php namespace Gitlab\Tests\Api; + +class SystemHooksTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllHooks() + { + $expectedArray = array( + array('id' => 1, 'url' => 'http://www.example.com'), + array('id' => 2, 'url' => 'http://www.example.org'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('hooks') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldCreateHook() + { + $expectedArray = array('id' => 3, 'url' => 'http://www.example.net'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('hooks', array('url' => 'http://www.example.net')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('http://www.example.net')); + } + + /** + * @test + */ + public function shouldTestHook() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('hooks/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->test(3)); + } + + /** + * @test + */ + public function shouldRemoveHook() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('hooks/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->remove(3)); + } + + protected function getApiClass() + { + return 'Gitlab\Api\SystemHooks'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/TestCase.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/TestCase.php new file mode 100644 index 0000000000000000000000000000000000000000..cba51e5e26a9bf8cdc1554ae094450706f3eef9b --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/TestCase.php @@ -0,0 +1,38 @@ +<?php namespace Gitlab\Tests\Api; + +use Buzz\Client\Curl; + +use Gitlab\Client; +use Gitlab\HttpClient\HttpClientInterface; + +abstract class TestCase extends \PHPUnit_Framework_TestCase +{ + /** + * @return Client + */ + protected function getClientMock() + { + return new Client($this->getHttpMock()); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|HttpClientInterface + */ + protected function getHttpMock() + { + return $this->getMock('Gitlab\HttpClient\HttpClient', array(), array(null, array(), $this->getHttpClientMock())); + } + + /** + * @return \PHPUnit_Framework_MockObject_MockObject|Curl + */ + protected function getHttpClientMock() + { + $httpClient = $this->getMock('Buzz\Client\Curl', array('send')); + $httpClient + ->expects($this->any()) + ->method('send'); + + return $httpClient; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/UsersTest.php b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/UsersTest.php new file mode 100644 index 0000000000000000000000000000000000000000..cc1d262ab5d8dffa69a698b7fc9a6d12a7490328 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/Gitlab/Tests/Api/UsersTest.php @@ -0,0 +1,424 @@ +<?php namespace Gitlab\Tests\Api; + +use Gitlab\Api\AbstractApi; + +class UsersTest extends ApiTestCase +{ + /** + * @test + */ + public function shouldGetAllUsers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt'), + array('id' => 2, 'name' => 'John'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('active' => null, 'page' => 1, 'per_page' => 10)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(null, 1, 10)); + } + + /** + * @test + */ + public function shouldGetActiveUsers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt'), + array('id' => 2, 'name' => 'John'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('active' => true, 'page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all(true)); + } + + /** + * @test + */ + public function shouldNotNeedPaginationWhenGettingUsers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt'), + array('id' => 2, 'name' => 'John'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('active' => null, 'page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->all()); + } + + /** + * @test + */ + public function shouldSearchUsers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('search' => 'ma', 'active' => null, 'page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('ma')); + } + + /** + * @test + */ + public function shouldSearchActiveUsers() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('search' => 'ma', 'active' => true, 'page' => 1, 'per_page' => AbstractApi::PER_PAGE)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('ma', true)); + } + + /** + * @test + */ + public function shouldSearchActiveUsersWithPagination() + { + $expectedArray = array( + array('id' => 1, 'name' => 'Matt') + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users', array('search' => 'ma', 'active' => true, 'page' => 2, 'per_page' => 5)) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->search('ma', true, 2, 5)); + } + + /** + * @test + */ + public function shouldShowUser() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users/1') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->show(1)); + } + + /** + * @test + */ + public function shouldCreateUser() + { + $expectedArray = array('id' => 3, 'name' => 'Billy'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('users', array('email' => 'billy@example.com', 'password' => 'password')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('billy@example.com', 'password')); + } + + /** + * @test + */ + public function shouldCreateUserWithAdditionalInfo() + { + $expectedArray = array('id' => 3, 'name' => 'Billy'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('users', array('email' => 'billy@example.com', 'password' => 'password', 'name' => 'Billy', 'bio' => 'A person')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->create('billy@example.com', 'password', array('name' => 'Billy', 'bio' => 'A person'))); + } + + /** + * @test + */ + public function shouldUpdateUser() + { + $expectedArray = array('id' => 3, 'name' => 'Billy Bob'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/3', array('name' => 'Billy Bob')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->update(3, array('name' => 'Billy Bob'))); + } + + /** + * @test + */ + public function shouldRemoveUser() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('users/1') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->remove(1)); + } + + /** + * @test + */ + public function shouldBlockUser() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/1/block') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->block(1)); + } + + /** + * @test + */ + public function shouldUnblockUser() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('put') + ->with('users/1/unblock') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->unblock(1)); + } + + /** + * @test + */ + public function shouldShowCurrentUser() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->me()); + } + + /** + * @test + */ + public function shouldGetCurrentUserKeys() + { + $expectedArray = array( + array('id' => 1, 'title' => 'A key'), + array('id' => 2, 'name' => 'Another key'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/keys') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->keys(1)); + } + + /** + * @test + */ + public function shouldGetCurrentUserKey() + { + $expectedArray = array('id' => 1, 'title' => 'A key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('user/keys/1') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->key(1)); + } + + /** + * @test + */ + public function shouldCreateKeyForCurrentUser() + { + $expectedArray = array('id' => 3, 'title' => 'A new key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('user/keys', array('title' => 'A new key', 'key' => '...')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createKey('A new key', '...')); + } + + /** + * @test + */ + public function shouldDeleteKeyForCurrentUser() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('user/keys/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeKey(3)); + } + + /** + * @test + */ + public function shouldGetUserKeys() + { + $expectedArray = array( + array('id' => 1, 'title' => 'A key'), + array('id' => 2, 'name' => 'Another key'), + ); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users/1/keys') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->userKeys(1)); + } + + /** + * @test + */ + public function shouldGetUserKey() + { + $expectedArray = array('id' => 2, 'title' => 'Another key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('get') + ->with('users/1/keys/2') + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->userKey(1, 2)); + } + + /** + * @test + */ + public function shouldCreateKeyForUser() + { + $expectedArray = array('id' => 3, 'title' => 'A new key'); + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('post') + ->with('users/1/keys', array('title' => 'A new key', 'key' => '...')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->createKeyForUser(1, 'A new key', '...')); + } + + /** + * @test + */ + public function shouldDeleteKeyForUser() + { + $expectedBool = true; + + $api = $this->getApiMock(); + $api->expects($this->once()) + ->method('delete') + ->with('users/1/keys/3') + ->will($this->returnValue($expectedBool)) + ; + + $this->assertEquals($expectedBool, $api->removeUserKey(1, 3)); + } + + /** + * @test + */ + public function shouldAttemptLogin() + { + $expectedArray = array('id' => 1, 'name' => 'Matt'); + + $api = $this->getApiMock(); + $api->expects($this->exactly(2)) + ->method('post') + ->with('session', array('login' => 'matt', 'password' => 'password', 'email' => 'matt')) + ->will($this->returnValue($expectedArray)) + ; + + $this->assertEquals($expectedArray, $api->session('matt', 'password')); + $this->assertEquals($expectedArray, $api->login('matt', 'password')); + } + + protected function getApiClass() + { + return 'Gitlab\Api\Users'; + } +} diff --git a/vendor/m4tthumphrey/php-gitlab-api/test/bootstrap.php b/vendor/m4tthumphrey/php-gitlab-api/test/bootstrap.php new file mode 100644 index 0000000000000000000000000000000000000000..83bc8b088a4fee7016d39ea78c45258cde578119 --- /dev/null +++ b/vendor/m4tthumphrey/php-gitlab-api/test/bootstrap.php @@ -0,0 +1,18 @@ +<?php + +function includeIfExists($file) +{ + if (file_exists($file)) { + return include $file; + } +} + +if ((!$loader = includeIfExists(__DIR__.'/../vendor/autoload.php')) && (!$loader = includeIfExists(__DIR__.'/../../../.composer/autoload.php'))) { + die('You must set up the project dependencies, run the following commands:'.PHP_EOL. + 'curl -s http://getcomposer.org/installer | php'.PHP_EOL. + 'php composer.phar install'.PHP_EOL); +} + +$loader->add('Gitlab\Tests', __DIR__); + +return $loader; \ No newline at end of file