Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 28 additions & 5 deletions Classes/Lightwerk/SurfCaptain/GitApi/Driver/GitLabDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,29 @@
*/
class GitLabDriver extends AbstractDriver
{
/**
* @var int
*/
protected $apiVersion = 3;

/**
* @param array $settings
* @return void
*/
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;
}
}

/**
Expand All @@ -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;
}

/**
Expand All @@ -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,
Expand All @@ -59,6 +81,7 @@ public function getRepositories()
)
);
}

return $repositories;
}

Expand Down