diff --git a/Classes/Lightwerk/SurfCaptain/GitApi/Driver/AbstractDriver.php b/Classes/Lightwerk/SurfCaptain/GitApi/Driver/AbstractDriver.php index 715cdea..b03c989 100644 --- a/Classes/Lightwerk/SurfCaptain/GitApi/Driver/AbstractDriver.php +++ b/Classes/Lightwerk/SurfCaptain/GitApi/Driver/AbstractDriver.php @@ -55,6 +55,7 @@ protected function getRepositoryAccount($repositoryUrl) /** * Extracts git@github.com from git@github.com:account/repository.git + * as well as from ssh://git@bitbucket.org * * @param string $repositoryUrl * @return string diff --git a/Classes/Lightwerk/SurfCaptain/GitApi/Driver/GitLabDriver.php b/Classes/Lightwerk/SurfCaptain/GitApi/Driver/GitLabDriver.php index 800dd78..3b7066c 100644 --- a/Classes/Lightwerk/SurfCaptain/GitApi/Driver/GitLabDriver.php +++ b/Classes/Lightwerk/SurfCaptain/GitApi/Driver/GitLabDriver.php @@ -16,6 +16,11 @@ */ class GitLabDriver extends AbstractDriver { + /** + * @var int + */ + protected $apiVersion = 3; + /** * @param array $settings * @return void @@ -23,9 +28,17 @@ class GitLabDriver extends AbstractDriver public function setSettings(array $settings) { $this->settings = $settings; + $this->apiRequest = $this->objectManager->get('Lightwerk\SurfCaptain\GitApi\Request\HttpAuthRequestInterface'); $this->apiRequest->setApiUrl($settings['apiUrl']); $this->apiRequest->setAuthorizationHeader(['PRIVATE-TOKEN: ' . $this->settings['privateToken']]); + + if (strpos($settings['apiUrl'], 'v3') !== false) { + $this->apiVersion = 3; + } + if (strpos($settings['apiUrl'], 'v4') !== false) { + $this->apiVersion = 4; + } } /** @@ -34,7 +47,8 @@ public function setSettings(array $settings) */ public function hasRepository($repositoryUrl) { - return $this->getGitVendorFromRepositoryUrl($repositoryUrl) === $this->settings['accountName']; + $vendorName = $this->getGitVendorFromRepositoryUrl($repositoryUrl); + return $vendorName === $this->settings['accountName'] || strpos($vendorName, 'gitlab') !== false; } /** @@ -43,12 +57,20 @@ public function hasRepository($repositoryUrl) public function getRepositories() { $repositories = []; - foreach ($this->settings['repositories'] as $command) { + foreach ($this->settings['repositories'] as $path) { + if ($this->apiVersion === 3) { + $command = $path; + } + if ($this->apiVersion === 4) { + $command = 'users/' . $this->settings['accountName'] . '/' . $path; + } $response = $this->apiRequest->call($command); - if (isset($response['projects']) === false) { - $projects = [$response]; - } else { + if (isset($response['projects'])) { $projects = $response['projects']; + } elseif (is_array($response)) { + $projects = $response; + } else { + $projects = [$response]; } $repositories = array_merge( $repositories, @@ -59,6 +81,7 @@ public function getRepositories() ) ); } + return $repositories; }