Added Gitlab support
This commit is contained in:
parent
f1fab01fd8
commit
47be59ae46
|
@ -40,6 +40,9 @@ class BuildFactory
|
|||
case 'bitbucket':
|
||||
$type = 'BitbucketBuild';
|
||||
break;
|
||||
case 'gitlab':
|
||||
$type = 'GitlabBuild';
|
||||
break;
|
||||
}
|
||||
|
||||
$type = '\\PHPCI\\Model\\Build\\' . $type;
|
||||
|
|
|
@ -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)) {
|
||||
|
|
|
@ -34,6 +34,7 @@ class ProjectBase extends Model
|
|||
protected $data = array(
|
||||
'id' => null,
|
||||
'title' => null,
|
||||
'access_information' => null,
|
||||
'reference' => null,
|
||||
'git_key' => null,
|
||||
'type' => null,
|
||||
|
@ -49,6 +50,7 @@ class ProjectBase extends Model
|
|||
'reference' => 'getReference',
|
||||
'git_key' => 'getGitKey',
|
||||
'type' => 'getType',
|
||||
'access_information' => 'getAccessInformation',
|
||||
'token' => 'getToken',
|
||||
);
|
||||
|
||||
|
@ -61,6 +63,7 @@ class ProjectBase extends Model
|
|||
'reference' => 'setReference',
|
||||
'git_key' => 'setGitKey',
|
||||
'type' => 'setType',
|
||||
'access_information' => 'setAccessInformation',
|
||||
'token' => 'setToken',
|
||||
);
|
||||
|
||||
|
@ -82,6 +85,10 @@ class ProjectBase extends Model
|
|||
'type' => 'varchar',
|
||||
'length' => '250',
|
||||
),
|
||||
'access_information' => array(
|
||||
'type' => 'varchar',
|
||||
'length' => '250',
|
||||
),
|
||||
'git_key' => array(
|
||||
'type' => 'text',
|
||||
'length' => '',
|
||||
|
@ -150,6 +157,19 @@ class ProjectBase extends Model
|
|||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of Domain / domain.
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getAccessInformation()
|
||||
{
|
||||
$rtn = unserialize($this->data['access_information']);
|
||||
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of GitKey / git_key.
|
||||
*
|
||||
|
@ -246,6 +266,25 @@ class ProjectBase extends Model
|
|||
$this->_setModified('reference');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of Domain / domain.
|
||||
*
|
||||
* Must not be null.
|
||||
* @param $value string
|
||||
*/
|
||||
public function setAccessInformation($value)
|
||||
{
|
||||
$this->_validateNotNull('AccessInformation', $value);
|
||||
$this->_validateString('AccessInformation', $value);
|
||||
if ($this->data['access_information'] == $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['access_information'] = $value;
|
||||
|
||||
$this->_setModified('access_information');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of GitKey / git_key.
|
||||
*
|
||||
|
|
50
PHPCI/Model/Build/GitlabBuild.php
Normal file
50
PHPCI/Model/Build/GitlabBuild.php
Normal file
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
/**
|
||||
* PHPCI - Continuous Integration for PHP
|
||||
*
|
||||
* @copyright Copyright 2013, Block 8 Limited.
|
||||
* @license https://github.com/Block8/PHPCI/blob/master/LICENSE.md
|
||||
* @link http://www.phptesting.org/
|
||||
*/
|
||||
|
||||
namespace PHPCI\Model\Build;
|
||||
|
||||
use PHPCI\Model\Build\RemoteGitBuild;
|
||||
|
||||
/**
|
||||
* Gitlab Build Model
|
||||
* @author André Cianfarani <a.cianfarani@c2is.fr>
|
||||
* @package PHPCI
|
||||
* @subpackage Core
|
||||
*/
|
||||
class GitlabBuild extends RemoteGitBuild
|
||||
{
|
||||
|
||||
/**
|
||||
* Get link to commit from another source (i.e. Github)
|
||||
*/
|
||||
public function getCommitLink()
|
||||
{
|
||||
return 'http://'.$this->getProject()->getAccessInformation()["domain"].'/' . $this->getProject()->getReference() . '/commit/' . $this->getCommitId();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get link to branch from another source (i.e. Github)
|
||||
*/
|
||||
public function getBranchLink()
|
||||
{
|
||||
return 'http://'.$this->getProject()->getAccessInformation()["domain"].'/' . $this->getProject()->getReference() . '/tree/' . $this->getBranch();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the URL to be used to clone this remote repository.
|
||||
*/
|
||||
protected function getCloneUrl()
|
||||
{
|
||||
$key = trim($this->getProject()->getGitKey());
|
||||
|
||||
if (!empty($key)) {
|
||||
return $this->getProject()->getAccessInformation()["user"].'@'.$this->getProject()->getAccessInformation()["domain"].':' . $this->getProject()->getReference() . '.git';
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue