diff --git a/composer.json b/composer.json index 3c29600a4..4c136375a 100644 --- a/composer.json +++ b/composer.json @@ -24,7 +24,7 @@ "php": ">=5.3.2", "ext-curl": "*", "ext-xml": "*", - "kriswallsmith/buzz": ">=0.7" + "kriswallsmith/buzz": "^0.7" }, "require-dev": { "phpunit/phpunit": "~4.5" diff --git a/lib/Gitlab/Api/AbstractApi.php b/lib/Gitlab/Api/AbstractApi.php index d6e3ab723..a67974a98 100644 --- a/lib/Gitlab/Api/AbstractApi.php +++ b/lib/Gitlab/Api/AbstractApi.php @@ -21,7 +21,7 @@ abstract class AbstractApi implements ApiInterface * * @var Client */ - protected $client; + public $client; /** * @param Client $client @@ -46,7 +46,7 @@ public function configure() * @param array $requestHeaders * @return mixed */ - protected function get($path, array $parameters = array(), $requestHeaders = array()) + public function get($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->get($path, $parameters, $requestHeaders); @@ -60,7 +60,7 @@ protected function get($path, array $parameters = array(), $requestHeaders = arr * @param array $files * @return mixed */ - protected function post($path, array $parameters = array(), $requestHeaders = array(), array $files = array()) + public function post($path, array $parameters = array(), $requestHeaders = array(), array $files = array()) { $response = $this->client->getHttpClient()->post($path, $parameters, $requestHeaders, $files); @@ -73,7 +73,7 @@ protected function post($path, array $parameters = array(), $requestHeaders = ar * @param array $requestHeaders * @return mixed */ - protected function patch($path, array $parameters = array(), $requestHeaders = array()) + public function patch($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->patch($path, $parameters, $requestHeaders); @@ -86,7 +86,7 @@ protected function patch($path, array $parameters = array(), $requestHeaders = a * @param array $requestHeaders * @return mixed */ - protected function put($path, array $parameters = array(), $requestHeaders = array()) + public function put($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->put($path, $parameters, $requestHeaders); @@ -99,7 +99,7 @@ protected function put($path, array $parameters = array(), $requestHeaders = arr * @param array $requestHeaders * @return mixed */ - protected function delete($path, array $parameters = array(), $requestHeaders = array()) + public function delete($path, array $parameters = array(), $requestHeaders = array()) { $response = $this->client->getHttpClient()->delete($path, $parameters, $requestHeaders); @@ -111,7 +111,7 @@ protected function delete($path, array $parameters = array(), $requestHeaders = * @param string $path * @return string */ - protected function getProjectPath($id, $path) + public function getProjectPath($id, $path) { return 'projects/'.$this->encodePath($id).'/'.$path; } @@ -120,7 +120,7 @@ protected function getProjectPath($id, $path) * @param string $path * @return string */ - protected function encodePath($path) + public function encodePath($path) { $path = rawurlencode($path); diff --git a/lib/Gitlab/Api/Issues.php b/lib/Gitlab/Api/Issues.php index 661ea7ac1..b5bf1a63d 100644 --- a/lib/Gitlab/Api/Issues.php +++ b/lib/Gitlab/Api/Issues.php @@ -13,7 +13,6 @@ public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, a { $path = $project_id === null ? 'issues' : $this->getProjectPath($project_id, 'issues'); - $params = array_intersect_key($params, array('labels' => '', 'state' => '', 'sort' => '', 'order_by' => '', 'milestone' => '')); $params = array_merge(array( 'page' => $page, 'per_page' => $per_page @@ -29,7 +28,22 @@ public function all($project_id = null, $page = 1, $per_page = self::PER_PAGE, a */ public function show($project_id, $issue_id) { - return $this->get($this->getProjectPath($project_id, 'issues?iid='.$this->encodePath($issue_id))); + if(is_array($issue_id)) { + $issue_id = array_map(function($item) { return $this->encodePath($item); }, $issue_id); + $issue_id = 'iids[]=' . join('iids[]=', $issue_id); + } else { + $issue_id = 'iids[]=' . $this->encodePath($issue_id); + } + + return $this->get($this->getProjectPath($project_id, 'issues?'.$issue_id)); + } + + public function time_estimate($project_id, $issue_id, $duration = '1h30m') { + return $this->post($this->getProjectPath($project_id, 'issues/' . $this->encodePath($issue_id) . '/time_estimate?duration=' . $duration), []); + } + + public function add_spent_time($project_id, $issue_id, $duration = '1h30m') { + return $this->post($this->getProjectPath($project_id, 'issues/' . $this->encodePath($issue_id) . '/add_spent_time?duration=' . $duration), []); } /** diff --git a/lib/Gitlab/Client.php b/lib/Gitlab/Client.php index 5f0fd3950..c4c38ba52 100644 --- a/lib/Gitlab/Client.php +++ b/lib/Gitlab/Client.php @@ -58,7 +58,7 @@ class Client */ private $options = array( 'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)', - 'timeout' => 60 + 'timeout' => 960 ); private $baseUrl; diff --git a/lib/Gitlab/HttpClient/HttpClient.php b/lib/Gitlab/HttpClient/HttpClient.php index 7a84bfb43..f59d41dad 100644 --- a/lib/Gitlab/HttpClient/HttpClient.php +++ b/lib/Gitlab/HttpClient/HttpClient.php @@ -3,13 +3,12 @@ use Buzz\Client\ClientInterface; use Buzz\Listener\ListenerInterface; use Buzz\Message\Form\FormUpload; - use Gitlab\Exception\ErrorException; use Gitlab\Exception\RuntimeException; use Gitlab\HttpClient\Listener\ErrorListener; +use Gitlab\HttpClient\Message\FormRequest; use Gitlab\HttpClient\Message\Request; use Gitlab\HttpClient\Message\Response; -use Gitlab\HttpClient\Message\FormRequest; /** * Performs requests on Gitlab API. API documentation should be self-explanatory. @@ -23,8 +22,8 @@ class HttpClient implements HttpClientInterface * @var array */ protected $options = array( - 'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)', - 'timeout' => 10, + 'user_agent' => 'php-gitlab-api (http://github.com/m4tthumphrey/php-gitlab-api)', + 'timeout' => 10, ); /** @@ -60,7 +59,7 @@ public function __construct($baseUrl, array $options, ClientInterface $client) { $this->baseUrl = $baseUrl; $this->options = array_merge($this->options, $options); - $this->client = $client; + $this->client = $client; $this->addListener(new ErrorListener($this->options)); @@ -105,9 +104,11 @@ public function addListener(ListenerInterface $listener) public function get($path, array $parameters = array(), array $headers = array()) { if (0 < count($parameters)) { - $path .= (false === strpos($path, '?') ? '?' : '&').http_build_query($parameters, '', '&'); + $path .= (false === strpos($path, '?') ? '?' : '&') . http_build_query($parameters, '', '&'); } + $path = preg_replace("/%5B([0-9]+)%5D\=/", "[]=", $path); + return $this->request($path, array(), 'GET', $headers); } @@ -148,37 +149,49 @@ public function put($path, array $parameters = array(), array $headers = array() */ public function request($path, array $parameters = array(), $httpMethod = 'GET', array $headers = array(), array $files = array()) { - $path = trim($this->baseUrl.$path, '/'); + $ckey = md5(json_encode([$path, $parameters, $httpMethod, $headers])); + + $getData = function () use($ckey, $path, $parameters, $httpMethod, $headers, $files) { + $path = trim($this->baseUrl . $path, '/'); - $request = $this->createRequest($httpMethod, $path, $parameters, $headers, $files); + $request = $this->createRequest($httpMethod, $path, $parameters, $headers, $files); - $hasListeners = 0 < count($this->listeners); - if ($hasListeners) { - foreach ($this->listeners as $listener) { - $listener->preSend($request); + $hasListeners = 0 < count($this->listeners); + if ($hasListeners) { + foreach ($this->listeners as $listener) { + $listener->preSend($request); + } } - } - $response = new Response(); + $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()); - } + 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; + $this->lastRequest = $request; + $this->lastResponse = $response; - if ($hasListeners) { - foreach ($this->listeners as $listener) { - $listener->postSend($request, $response); + if ($hasListeners) { + foreach ($this->listeners as $listener) { + $listener->postSend($request, $response); + } } + + return $response; + }; + + if(\Illuminate\Support\Facades\Request::header('Cache-Control') === 'no-cache') { + $_data = $getData(); + \Cache::put($ckey, $_data, 120); + return $_data; } - return $response; + return \Cache::remember($ckey, 120, $getData); } /** diff --git a/lib/Gitlab/Model/Issue.php b/lib/Gitlab/Model/Issue.php index 86c7e2add..99d2d0528 100644 --- a/lib/Gitlab/Model/Issue.php +++ b/lib/Gitlab/Model/Issue.php @@ -39,6 +39,8 @@ class Issue extends AbstractModel implements Noteable 'updated_at', 'created_at', 'project', + 'time_stats', + 'due_date', 'state' ); @@ -81,8 +83,7 @@ public function __construct(Project $project, $id = null, Client $client = null) public function show() { $data = $this->api('issues')->show($this->project->id, $this->id); - - return static::fromArray($this->getClient(), $this->project, $data); + return static::fromArray($this->getClient(), $this->project, isset($data[0]) ? $data[0] : []); } /** diff --git a/lib/Gitlab/Model/Project.php b/lib/Gitlab/Model/Project.php index 44fa9a7ee..c984fbbcd 100644 --- a/lib/Gitlab/Model/Project.php +++ b/lib/Gitlab/Model/Project.php @@ -733,11 +733,12 @@ public function mergeMergeRequest($id) /** * @param int $page * @param int $per_page + * @param array $params * @return Issue[] */ - public function issues($page = 1, $per_page = Api::PER_PAGE) + public function issues($page = 1, $per_page = Api::PER_PAGE, $params = []) { - $data = $this->api('issues')->all($this->id, $page, $per_page); + $data = $this->api('issues')->all($this->id, $page, $per_page, $params); $issues = array(); foreach ($data as $issue) {