From 04977359245d86e28ffb2675a93653c88d8de514 Mon Sep 17 00:00:00 2001 From: Jan Gabrhel Date: Wed, 27 Feb 2019 15:20:23 +0100 Subject: [PATCH] fix regex for parsing gitlab access informations --- PHPCI/Service/ProjectService.php | 6 +++--- Tests/PHPCI/Service/ProjectServiceTest.php | 22 ++++++++++++++++++++++ 2 files changed, 25 insertions(+), 3 deletions(-) diff --git a/PHPCI/Service/ProjectService.php b/PHPCI/Service/ProjectService.php index 8b07b0a97..2e00f5c60 100644 --- a/PHPCI/Service/ProjectService.php +++ b/PHPCI/Service/ProjectService.php @@ -123,12 +123,12 @@ protected function processAccessInformation(Project &$project) if ($project->getType() == 'gitlab') { $info = array(); - if (preg_match('`^(.+)@(.+):([0-9]*)\/?(.+)\.git`', $reference, $matches)) { + if (preg_match('`^(.+)@(.+):(([0-9]*)\/)?\/?(.+)\.git`', $reference, $matches)) { $info['user'] = $matches[1]; $info['domain'] = $matches[2]; - $info['port'] = $matches[3]; + $info['port'] = $matches[4]; - $project->setReference($matches[4]); + $project->setReference($matches[5]); } $project->setAccessInformation($info); diff --git a/Tests/PHPCI/Service/ProjectServiceTest.php b/Tests/PHPCI/Service/ProjectServiceTest.php index 11894d790..f3142b60d 100644 --- a/Tests/PHPCI/Service/ProjectServiceTest.php +++ b/Tests/PHPCI/Service/ProjectServiceTest.php @@ -125,4 +125,26 @@ public function testExecute_DeleteProject() $this->assertEquals(true, $service->deleteProject($project)); } + + + public function testExecute_CreateGitlabProjectWithNumberInVendor() + { + $reference = 'git@gitlab.block8.net:8block/phpci.git'; + $returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference); + + $this->assertEquals('git', $returnValue->getAccessInformation('user')); + $this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain')); + $this->assertEquals('8block/phpci', $returnValue->getReference()); + } + + public function testExecute_CreateGitlabProjectWithPortAndNumberInVendor() + { + $reference = 'git@gitlab.block8.net:22/8block/phpci.git'; + $returnValue = $this->testedService->createProject('Gitlab', 'gitlab', $reference); + + $this->assertEquals('git', $returnValue->getAccessInformation('user')); + $this->assertEquals('gitlab.block8.net', $returnValue->getAccessInformation('domain')); + $this->assertEquals(22, $returnValue->getAccessInformation('port')); + $this->assertEquals('8block/phpci', $returnValue->getReference()); + } }