Added Gitlab support

This commit is contained in:
a.cianfarani 2013-08-23 16:05:12 +02:00
commit 47be59ae46
4 changed files with 123 additions and 1 deletions

View file

@ -158,6 +158,16 @@ class ProjectController extends \PHPCI\Controller
}
$values = $form->getValues();
if ($values['type'] == "gitlab") {
preg_match('`^(.*)@(.*):(.*)/(.*)\.git`',$values['reference'],$matches);
$info = array();
$info["user"] = $matches[1];
$info["domain"] = $matches[2];
$values['access_information'] = serialize($info);
$values['reference'] = $matches[3]."/".$matches[4];
}
$values['git_key'] = $values['key'];
$project = new Project();
@ -213,8 +223,13 @@ class ProjectController extends \PHPCI\Controller
} else {
$values = $project->getDataArray();
$values['key'] = $values['git_key'];
if ($values['type'] == "gitlab") {
$accessInfo = $project->getAccessInformation();
$values['reference'] = $accessInfo["user"].'@'.$accessInfo["domain"].':' . $project->getReference().".git";
}
}
$form = $this->projectForm($values, 'edit/' . $projectId);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) {
@ -230,6 +245,15 @@ class ProjectController extends \PHPCI\Controller
$values = $form->getValues();
$values['git_key'] = $values['key'];
if ($values['type'] == "gitlab") {
preg_match('`^(.*)@(.*):(.*)/(.*)\.git`',$values['reference'],$matches);
$info = array();
$info["user"] = $matches[1];
$info["domain"] = $matches[2];
$values['access_information'] = serialize($info);
$values['reference'] = $matches[3]."/".$matches[4];
}
$project->setValues($values);
$project = $this->_projectStore->save($project);
@ -253,13 +277,14 @@ class ProjectController extends \PHPCI\Controller
'choose' => 'Select repository type...',
'github' => 'Github',
'bitbucket' => 'Bitbucket',
'gitlab' => 'Gitlab',
'remote' => 'Remote URL',
'local' => 'Local Path'
);
$field = new Form\Element\Select('type');
$field->setRequired(true);
$field->setPattern('^(github|bitbucket|remote|local)');
$field->setPattern('^(github|bitbucket|gitlab|remote|local)');
$field->setOptions($options);
$field->setLabel('Where is your project hosted?');
$field->setClass('form-control');
@ -289,6 +314,11 @@ class ProjectController extends \PHPCI\Controller
throw new \Exception('The path you specified does not exist.');
}
break;
case 'gitlab':
if (!preg_match('`^(.*)@(.*):(.*)/(.*)\.git`', $val)) {
throw new \Exception('GitLab Repository name must be in the format "user@domain.tld:owner/repo.git".');
}
break;
case 'github':
case 'bitbucket':
if (!preg_match('/^[a-zA-Z0-9_\-]+\/[a-zA-Z0-9_\-\.]+$/', $val)) {