diff --git a/PHPCI/BuildFactory.php b/PHPCI/BuildFactory.php index c4479b05..689e5604 100644 --- a/PHPCI/BuildFactory.php +++ b/PHPCI/BuildFactory.php @@ -40,6 +40,9 @@ class BuildFactory case 'bitbucket': $type = 'BitbucketBuild'; break; + case 'gitlab': + $type = 'GitlabBuild'; + break; } $type = '\\PHPCI\\Model\\Build\\' . $type; diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 3406cbd6..e343ac88 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -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)) { diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index c9d577af..4e8b1e38 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -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. * diff --git a/PHPCI/Model/Build/GitlabBuild.php b/PHPCI/Model/Build/GitlabBuild.php new file mode 100644 index 00000000..9f456b0a --- /dev/null +++ b/PHPCI/Model/Build/GitlabBuild.php @@ -0,0 +1,50 @@ + +* @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'; + } + } +} diff --git a/PHPCI/Plugin/Atoum.php b/PHPCI/Plugin/Atoum.php index a97fa00a..54783b07 100644 --- a/PHPCI/Plugin/Atoum.php +++ b/PHPCI/Plugin/Atoum.php @@ -7,17 +7,15 @@ class Atoum implements \PHPCI\Plugin private $args; private $config; private $directory; - private $executable; public function __construct(\PHPCI\Builder $phpci, array $options = array()) { $this->phpci = $phpci; if (isset($options['executable'])) { - $this->executable = $options['executable']; - } - else { - $this->executable = './vendor/bin/atoum'; + $this->executable = $this->phpci->buildPath . DIRECTORY_SEPARATOR.$options['executable']; + } else { + $this->executable = PHPCI_BIN_DIR.'atoum'; } if (isset($options['args'])) { @@ -35,7 +33,7 @@ class Atoum implements \PHPCI\Plugin public function execute() { - $cmd = $this->phpci->buildPath . DIRECTORY_SEPARATOR . $this->executable; + $cmd = $this->executable; if ($this->args !== null) { $cmd .= " {$this->args}"; @@ -44,8 +42,23 @@ class Atoum implements \PHPCI\Plugin $cmd .= " -c '{$this->config}'"; } if ($this->directory !== null) { - $cmd .= " -d '{$this->directory}'"; + $dirPath = $this->phpci->buildPath . DIRECTORY_SEPARATOR . $this->directory; + $cmd .= " -d '{$dirPath}'"; } - return $this->phpci->executeCommand($cmd); + + $output = ''; + $status = true; + exec($cmd, $output); + + if (count(preg_grep("/Success \(/", $output)) == 0 ) { + $status = false; + $this->phpci->log($output, ' '); + } + if (count($output) == 0) { + $status = false; + $this->phpci->log("No test have been performed!", ' '); + } + + return $status; } } diff --git a/composer.json b/composer.json index a6368878..a45bd0e8 100644 --- a/composer.json +++ b/composer.json @@ -34,6 +34,7 @@ "symfony/console" : "2.2.*", "fabpot/php-cs-fixer" : "0.3.*@dev", "swiftmailer/swiftmailer" : "v5.0.0", - "phploc/phploc": "*" + "phploc/phploc": "*", + "atoum/atoum":"*" } }