Merge pull request #124 from c2is/master

Atoum Plugin improvements and implementation
This commit is contained in:
Dan Cryer 2013-08-27 05:48:42 -07:00
commit 8965034041
6 changed files with 146 additions and 10 deletions

View file

@ -40,6 +40,9 @@ class BuildFactory
case 'bitbucket':
$type = 'BitbucketBuild';
break;
case 'gitlab':
$type = 'GitlabBuild';
break;
}
$type = '\\PHPCI\\Model\\Build\\' . $type;

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)) {

View file

@ -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.
*

View 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';
}
}
}

View file

@ -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;
}
}

View file

@ -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":"*"
}
}