PHPCI/Helper and PHPCI/Model PSR2 compliance. Issue #18

This commit is contained in:
Dan Cryer 2013-05-16 15:40:40 +01:00
parent e4a6e224c4
commit 11a3e3403f
12 changed files with 1186 additions and 1212 deletions

View file

@ -17,9 +17,9 @@ namespace PHPCI\Helper;
*/
class User
{
public function __call($method, $params = array())
{
$user = \b8\Registry::getInstance()->get('user');
return call_user_func_array(array($user, $method), $params);
}
}
public function __call($method, $params = array())
{
$user = \b8\Registry::getInstance()->get('user');
return call_user_func_array(array($user, $method), $params);
}
}

File diff suppressed because it is too large Load diff

View file

@ -5,6 +5,7 @@
*/
namespace PHPCI\Model\Base;
use b8\Model;
/**
@ -12,311 +13,304 @@ use b8\Model;
*/
class ProjectBase extends Model
{
/**
* @var array
*/
public static $sleepable = array();
/**
* @var array
*/
public static $sleepable = array();
/**
* @var string
*/
protected $_tableName = 'project';
/**
* @var string
*/
protected $tableName = 'project';
/**
* @var string
*/
protected $_modelName = 'Project';
/**
* @var string
*/
protected $modelName = 'Project';
/**
* @var array
*/
protected $_data = array(
'id' => null,
'title' => null,
'reference' => null,
'git_key' => null,
'type' => null,
'token' => null,
);
/**
* @var array
*/
protected $data = array(
'id' => null,
'title' => null,
'reference' => null,
'git_key' => null,
'type' => null,
'token' => null,
);
/**
* @var array
*/
protected $_getters = array(
'id' => 'getId',
'title' => 'getTitle',
'reference' => 'getReference',
'git_key' => 'getGitKey',
'type' => 'getType',
'token' => 'getToken',
);
/**
* @var array
*/
protected $getters = array(
'id' => 'getId',
'title' => 'getTitle',
'reference' => 'getReference',
'git_key' => 'getGitKey',
'type' => 'getType',
'token' => 'getToken',
);
/**
* @var array
*/
protected $_setters = array(
'id' => 'setId',
'title' => 'setTitle',
'reference' => 'setReference',
'git_key' => 'setGitKey',
'type' => 'setType',
'token' => 'setToken',
);
/**
* @var array
*/
protected $setters = array(
'id' => 'setId',
'title' => 'setTitle',
'reference' => 'setReference',
'git_key' => 'setGitKey',
'type' => 'setType',
'token' => 'setToken',
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'title' => array(
'type' => 'varchar',
'length' => '250',
),
'reference' => array(
'type' => 'varchar',
'length' => '250',
),
'git_key' => array(
'type' => 'text',
'length' => '',
),
'type' => array(
'type' => 'varchar',
'length' => '50',
),
'token' => array(
'type' => 'varchar',
'length' => '50',
'nullable' => true,
),
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'title' => array(
'type' => 'varchar',
'length' => '250',
),
'reference' => array(
'type' => 'varchar',
'length' => '250',
),
'git_key' => array(
'type' => 'text',
'length' => '',
),
'type' => array(
'type' => 'varchar',
'length' => '50',
),
'token' => array(
'type' => 'varchar',
'length' => '50',
'nullable' => true,
),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Title / title.
*
* @return string
*/
public function getTitle()
{
$rtn = $this->_data['title'];
/**
* Get the value of Title / title.
*
* @return string
*/
public function getTitle()
{
$rtn = $this->_data['title'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Reference / reference.
*
* @return string
*/
public function getReference()
{
$rtn = $this->_data['reference'];
/**
* Get the value of Reference / reference.
*
* @return string
*/
public function getReference()
{
$rtn = $this->_data['reference'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of GitKey / git_key.
*
* @return string
*/
public function getGitKey()
{
$rtn = $this->_data['git_key'];
/**
* Get the value of GitKey / git_key.
*
* @return string
*/
public function getGitKey()
{
$rtn = $this->_data['git_key'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Type / type.
*
* @return string
*/
public function getType()
{
$rtn = $this->_data['type'];
/**
* Get the value of Type / type.
*
* @return string
*/
public function getType()
{
$rtn = $this->_data['type'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Token / token.
*
* @return string
*/
public function getToken()
{
$rtn = $this->_data['token'];
/**
* Get the value of Token / token.
*
* @return string
*/
public function getToken()
{
$rtn = $this->_data['token'];
return $rtn;
}
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if($this->_data['id'] === $value)
{
return;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if ($this->_data['id'] === $value) {
return;
}
$this->_data['id'] = $value;
$this->_data['id'] = $value;
$this->_setModified('id');
}
$this->_setModified('id');
}
/**
* Set the value of Title / title.
*
* Must not be null.
* @param $value string
*/
public function setTitle($value)
{
$this->_validateNotNull('Title', $value);
$this->_validateString('Title', $value);
if($this->_data['title'] === $value)
{
return;
}
/**
* Set the value of Title / title.
*
* Must not be null.
* @param $value string
*/
public function setTitle($value)
{
$this->_validateNotNull('Title', $value);
$this->_validateString('Title', $value);
if ($this->_data['title'] === $value) {
return;
}
$this->_data['title'] = $value;
$this->_data['title'] = $value;
$this->_setModified('title');
}
$this->_setModified('title');
}
/**
* Set the value of Reference / reference.
*
* Must not be null.
* @param $value string
*/
public function setReference($value)
{
$this->_validateNotNull('Reference', $value);
$this->_validateString('Reference', $value);
if($this->_data['reference'] === $value)
{
return;
}
/**
* Set the value of Reference / reference.
*
* Must not be null.
* @param $value string
*/
public function setReference($value)
{
$this->_validateNotNull('Reference', $value);
$this->_validateString('Reference', $value);
if ($this->_data['reference'] === $value) {
return;
}
$this->_data['reference'] = $value;
$this->_data['reference'] = $value;
$this->_setModified('reference');
}
$this->_setModified('reference');
}
/**
* Set the value of GitKey / git_key.
*
* Must not be null.
* @param $value string
*/
public function setGitKey($value)
{
$this->_validateNotNull('GitKey', $value);
$this->_validateString('GitKey', $value);
if($this->_data['git_key'] === $value)
{
return;
}
/**
* Set the value of GitKey / git_key.
*
* Must not be null.
* @param $value string
*/
public function setGitKey($value)
{
$this->_validateNotNull('GitKey', $value);
$this->_validateString('GitKey', $value);
if ($this->_data['git_key'] === $value) {
return;
}
$this->_data['git_key'] = $value;
$this->_data['git_key'] = $value;
$this->_setModified('git_key');
}
$this->_setModified('git_key');
}
/**
* Set the value of Type / type.
*
* Must not be null.
* @param $value string
*/
public function setType($value)
{
$this->_validateNotNull('Type', $value);
$this->_validateString('Type', $value);
if($this->_data['type'] === $value)
{
return;
}
/**
* Set the value of Type / type.
*
* Must not be null.
* @param $value string
*/
public function setType($value)
{
$this->_validateNotNull('Type', $value);
$this->_validateString('Type', $value);
if ($this->_data['type'] === $value) {
return;
}
$this->_data['type'] = $value;
$this->_data['type'] = $value;
$this->_setModified('type');
}
$this->_setModified('type');
}
/**
* Set the value of Token / token.
*
* @param $value string
*/
public function setToken($value)
{
/**
* Set the value of Token / token.
*
* @param $value string
*/
public function setToken($value)
{
$this->_validateString('Token', $value);
if($this->_data['token'] === $value)
{
return;
}
$this->_validateString('Token', $value);
if ($this->_data['token'] === $value) {
return;
}
$this->_data['token'] = $value;
$this->_data['token'] = $value;
$this->_setModified('token');
}
/**
* Get Build models by ProjectId for this Project.
*
* @uses \PHPCI\Store\BuildStore::getByProjectId()
* @uses \PHPCI\Model\Build
* @return \PHPCI\Model\Build[]
*/
public function getProjectBuilds()
{
return \b8\Store\Factory::getStore('Build')->getByProjectId($this->getId());
}
$this->_setModified('token');
}
/**
* Get Build models by ProjectId for this Project.
*
* @uses \PHPCI\Store\BuildStore::getByProjectId()
* @uses \PHPCI\Model\Build
* @return \PHPCI\Model\Build[]
*/
public function getProjectBuilds()
{
return \b8\Store\Factory::getStore('Build')->getByProjectId($this->getId());
}
}

View file

@ -5,6 +5,7 @@
*/
namespace PHPCI\Model\Base;
use b8\Model;
/**
@ -12,260 +13,254 @@ use b8\Model;
*/
class UserBase extends Model
{
/**
* @var array
*/
public static $sleepable = array();
/**
* @var array
*/
public static $sleepable = array();
/**
* @var string
*/
protected $_tableName = 'user';
/**
* @var string
*/
protected $tableName = 'user';
/**
* @var string
*/
protected $_modelName = 'User';
/**
* @var string
*/
protected $modelName = 'User';
/**
* @var array
*/
protected $_data = array(
'id' => null,
'email' => null,
'hash' => null,
'is_admin' => null,
'name' => null,
);
/**
* @var array
*/
protected $data = array(
'id' => null,
'email' => null,
'hash' => null,
'is_admin' => null,
'name' => null,
);
/**
* @var array
*/
protected $_getters = array(
'id' => 'getId',
'email' => 'getEmail',
'hash' => 'getHash',
'is_admin' => 'getIsAdmin',
'name' => 'getName',
);
/**
* @var array
*/
protected $getters = array(
'id' => 'getId',
'email' => 'getEmail',
'hash' => 'getHash',
'is_admin' => 'getIsAdmin',
'name' => 'getName',
);
/**
* @var array
*/
protected $_setters = array(
'id' => 'setId',
'email' => 'setEmail',
'hash' => 'setHash',
'is_admin' => 'setIsAdmin',
'name' => 'setName',
);
/**
* @var array
*/
protected $setters = array(
'id' => 'setId',
'email' => 'setEmail',
'hash' => 'setHash',
'is_admin' => 'setIsAdmin',
'name' => 'setName',
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'email' => array(
'type' => 'varchar',
'length' => '250',
),
'hash' => array(
'type' => 'varchar',
'length' => '250',
),
'is_admin' => array(
'type' => 'tinyint',
'length' => '1',
),
'name' => array(
'type' => 'varchar',
'length' => '250',
),
);
/**
* @var array
*/
public $columns = array(
'id' => array(
'type' => 'int',
'length' => '11',
'primary_key' => true,
'auto_increment' => true,
),
'email' => array(
'type' => 'varchar',
'length' => '250',
),
'hash' => array(
'type' => 'varchar',
'length' => '250',
),
'is_admin' => array(
'type' => 'tinyint',
'length' => '1',
),
'name' => array(
'type' => 'varchar',
'length' => '250',
),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_email' => array('unique' => true, 'columns' => 'email'),
);
/**
* @var array
*/
public $indexes = array(
'PRIMARY' => array('unique' => true, 'columns' => 'id'),
'idx_email' => array('unique' => true, 'columns' => 'email'),
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* @var array
*/
public $foreignKeys = array(
);
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
/**
* Get the value of Id / id.
*
* @return int
*/
public function getId()
{
$rtn = $this->_data['id'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Email / email.
*
* @return string
*/
public function getEmail()
{
$rtn = $this->_data['email'];
/**
* Get the value of Email / email.
*
* @return string
*/
public function getEmail()
{
$rtn = $this->_data['email'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Hash / hash.
*
* @return string
*/
public function getHash()
{
$rtn = $this->_data['hash'];
/**
* Get the value of Hash / hash.
*
* @return string
*/
public function getHash()
{
$rtn = $this->_data['hash'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of IsAdmin / is_admin.
*
* @return int
*/
public function getIsAdmin()
{
$rtn = $this->_data['is_admin'];
/**
* Get the value of IsAdmin / is_admin.
*
* @return int
*/
public function getIsAdmin()
{
$rtn = $this->_data['is_admin'];
return $rtn;
}
return $rtn;
}
/**
* Get the value of Name / name.
*
* @return string
*/
public function getName()
{
$rtn = $this->_data['name'];
/**
* Get the value of Name / name.
*
* @return string
*/
public function getName()
{
$rtn = $this->_data['name'];
return $rtn;
}
return $rtn;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if($this->_data['id'] === $value)
{
return;
}
/**
* Set the value of Id / id.
*
* Must not be null.
* @param $value int
*/
public function setId($value)
{
$this->_validateNotNull('Id', $value);
$this->_validateInt('Id', $value);
if ($this->_data['id'] === $value) {
return;
}
$this->_data['id'] = $value;
$this->_data['id'] = $value;
$this->_setModified('id');
}
$this->_setModified('id');
}
/**
* Set the value of Email / email.
*
* Must not be null.
* @param $value string
*/
public function setEmail($value)
{
$this->_validateNotNull('Email', $value);
$this->_validateString('Email', $value);
if($this->_data['email'] === $value)
{
return;
}
/**
* Set the value of Email / email.
*
* Must not be null.
* @param $value string
*/
public function setEmail($value)
{
$this->_validateNotNull('Email', $value);
$this->_validateString('Email', $value);
if ($this->_data['email'] === $value) {
return;
}
$this->_data['email'] = $value;
$this->_data['email'] = $value;
$this->_setModified('email');
}
$this->_setModified('email');
}
/**
* Set the value of Hash / hash.
*
* Must not be null.
* @param $value string
*/
public function setHash($value)
{
$this->_validateNotNull('Hash', $value);
$this->_validateString('Hash', $value);
if($this->_data['hash'] === $value)
{
return;
}
/**
* Set the value of Hash / hash.
*
* Must not be null.
* @param $value string
*/
public function setHash($value)
{
$this->_validateNotNull('Hash', $value);
$this->_validateString('Hash', $value);
if ($this->_data['hash'] === $value) {
return;
}
$this->_data['hash'] = $value;
$this->_data['hash'] = $value;
$this->_setModified('hash');
}
$this->_setModified('hash');
}
/**
* Set the value of IsAdmin / is_admin.
*
* Must not be null.
* @param $value int
*/
public function setIsAdmin($value)
{
$this->_validateNotNull('IsAdmin', $value);
$this->_validateInt('IsAdmin', $value);
if($this->_data['is_admin'] === $value)
{
return;
}
/**
* Set the value of IsAdmin / is_admin.
*
* Must not be null.
* @param $value int
*/
public function setIsAdmin($value)
{
$this->_validateNotNull('IsAdmin', $value);
$this->_validateInt('IsAdmin', $value);
if ($this->_data['is_admin'] === $value) {
return;
}
$this->_data['is_admin'] = $value;
$this->_data['is_admin'] = $value;
$this->_setModified('is_admin');
}
$this->_setModified('is_admin');
}
/**
* Set the value of Name / name.
*
* Must not be null.
* @param $value string
*/
public function setName($value)
{
$this->_validateNotNull('Name', $value);
$this->_validateString('Name', $value);
if($this->_data['name'] === $value)
{
return;
}
/**
* Set the value of Name / name.
*
* Must not be null.
* @param $value string
*/
public function setName($value)
{
$this->_validateNotNull('Name', $value);
$this->_validateString('Name', $value);
if ($this->_data['name'] === $value) {
return;
}
$this->_data['name'] = $value;
$this->_setModified('name');
}
$this->_data['name'] = $value;
$this->_setModified('name');
}
}

View file

@ -9,36 +9,34 @@
namespace PHPCI\Model;
require_once(APPLICATION_PATH . 'PHPCI/Model/Base/BuildBase.php');
use PHPCI\Model\Base\BuildBase,
PHPCI\Builder;
use PHPCI\Model\Base\BuildBase;
use PHPCI\Builder;
/**
* Build Model
* @uses PHPCI\Model\Base\BuildBase
* @uses PHPCI\Model\Base\BuildBase
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core
*/
class Build extends BuildBase
{
public function getCommitLink()
{
return '#';
}
public function getCommitLink()
{
return '#';
}
public function getBranchLink()
{
return '#';
}
public function getBranchLink()
{
return '#';
}
public function sendStatusPostback()
{
return;
}
public function sendStatusPostback()
{
return;
}
public function createWorkingCopy(Builder $builder, $buildPath)
{
}
public function createWorkingCopy(Builder $builder, $buildPath)
{
}
}

View file

@ -8,8 +8,9 @@
*/
namespace PHPCI\Model\Build;
use PHPCI\Model\Build,
PHPCI\Model\Build\RemoteGitBuild;
use PHPCI\Model\Build;
use PHPCI\Model\Build\RemoteGitBuild;
/**
* BitBucket Build Model
@ -19,25 +20,24 @@ use PHPCI\Model\Build,
*/
class BitbucketBuild extends RemoteGitBuild
{
public function getCommitLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/commits/' . $this->getCommitId();
}
public function getCommitLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/commits/' . $this->getCommitId();
}
public function getBranchLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/src/?at=' . $this->getBranch();
}
public function getBranchLink()
{
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '/src/?at=' . $this->getBranch();
}
protected function getCloneUrl()
{
$key = trim($this->getProject()->getGitKey());
protected function getCloneUrl()
{
$key = trim($this->getProject()->getGitKey());
if(!empty($key)) {
return 'git@bitbucket.org:' . $this->getProject()->getReference() . '.git';
}
else {
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '.git';
}
}
if (!empty($key)) {
return 'git@bitbucket.org:' . $this->getProject()->getReference() . '.git';
} else {
return 'https://bitbucket.org/' . $this->getProject()->getReference() . '.git';
}
}
}

View file

@ -8,6 +8,7 @@
*/
namespace PHPCI\Model\Build;
use PHPCI\Model\Build\RemoteGitBuild;
/**
@ -18,67 +19,65 @@ use PHPCI\Model\Build\RemoteGitBuild;
*/
class GithubBuild extends RemoteGitBuild
{
public function getCommitLink()
{
return 'https://github.com/' . $this->getProject()->getReference() . '/commit/' . $this->getCommitId();
}
public function getCommitLink()
{
return 'https://github.com/' . $this->getProject()->getReference() . '/commit/' . $this->getCommitId();
}
public function getBranchLink()
{
return 'https://github.com/' . $this->getProject()->getReference() . '/tree/' . $this->getBranch();
}
public function getBranchLink()
{
return 'https://github.com/' . $this->getProject()->getReference() . '/tree/' . $this->getBranch();
}
public function sendStatusPostback()
{
$project = $this->getProject();
public function sendStatusPostback()
{
$project = $this->getProject();
// The postback will only work if we have an access token.
if(!$project->getToken()) {
return;
}
// The postback will only work if we have an access token.
if (!$project->getToken()) {
return;
}
$url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->getCommitId();
$http = new \b8\HttpClient();
$url = 'https://api.github.com/repos/'.$project->getReference().'/statuses/'.$this->getCommitId();
$http = new \b8\HttpClient();
switch($this->getStatus())
{
case 0:
case 1:
$status = 'pending';
break;
switch($this->getStatus())
{
case 0:
case 1:
$status = 'pending';
break;
case 2:
$status = 'success';
break;
case 3:
$status = 'failure';
break;
default:
$status = 'error';
break;
}
case 2:
$status = 'success';
break;
$url = \b8\Registry::getInstance()->get('install_url');
$params = array( 'state' => $status,
'target_url' => $url . '/build/view/' . $this->getId());
$headers = array(
'Authorization: token ' . $project->getToken(),
'Content-Type: application/x-www-form-urlencoded'
);
case 3:
$status = 'failure';
break;
$http->setHeaders($headers);
$http->request('POST', $url, json_encode($params));
}
default:
$status = 'error';
break;
}
protected function getCloneUrl()
{
$key = trim($this->getProject()->getGitKey());
$params = array( 'state' => $status,
'target_url' => \b8\Registry::getInstance()->get('install_url') . '/build/view/' . $this->getId());
$http->setHeaders(array(
'Authorization: token ' . $project->getToken(),
'Content-Type: application/x-www-form-urlencoded'
));
$http->request('POST', $url, json_encode($params));
}
protected function getCloneUrl()
{
$key = trim($this->getProject()->getGitKey());
if(!empty($key)) {
return 'git@github.com:' . $this->getProject()->getReference() . '.git';
}
else {
return 'https://github.com/' . $this->getProject()->getReference() . '.git';
}
}
if (!empty($key)) {
return 'git@github.com:' . $this->getProject()->getReference() . '.git';
} else {
return 'https://github.com/' . $this->getProject()->getReference() . '.git';
}
}
}

View file

@ -8,9 +8,10 @@
*/
namespace PHPCI\Model\Build;
use PHPCI\Model\Build,
PHPCI\Builder,
Symfony\Component\Yaml\Parser as YamlParser;
use PHPCI\Model\Build;
use PHPCI\Builder;
use Symfony\Component\Yaml\Parser as YamlParser;
/**
* Local Build Model
@ -20,39 +21,38 @@ use PHPCI\Model\Build,
*/
class LocalBuild extends Build
{
public function createWorkingCopy(Builder $builder, $buildPath)
{
$reference = $this->getProject()->getReference();
$reference = substr($reference, -1) == '/' ? substr($reference, 0, -1) : $reference;
$buildPath = substr($buildPath, 0, -1);
$yamlParser = new YamlParser();
public function createWorkingCopy(Builder $builder, $buildPath)
{
$reference = $this->getProject()->getReference();
$reference = substr($reference, -1) == '/' ? substr($reference, 0, -1) : $reference;
$buildPath = substr($buildPath, 0, -1);
$yamlParser = new YamlParser();
if(!is_file($reference . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
if (!is_file($reference . '/phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$yamlFile = file_get_contents($reference . '/phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$yamlFile = file_get_contents($reference . '/phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$buildSettings = $builder->getConfig('build_settings');
$buildSettings = $builder->getConfig('build_settings');
if(isset($buildSettings['prefer_symlink']) && $buildSettings['prefer_symlink'] === true) {
if(is_link($buildPath) && is_file($buildPath)) {
unlink($buildPath);
}
if (isset($buildSettings['prefer_symlink']) && $buildSettings['prefer_symlink'] === true) {
if (is_link($buildPath) && is_file($buildPath)) {
unlink($buildPath);
}
$builder->log(sprintf('Symlinking: %s to %s',$reference, $buildPath));
$builder->log(sprintf('Symlinking: %s to %s', $reference, $buildPath));
if(!symlink($reference, $buildPath)) {
$builder->logFailure('Failed to symlink.');
return false;
}
}
else {
$builder->executeCommand('cp -Rf "%s" "%s/"', $reference, $buildPath);
}
if (!symlink($reference, $buildPath)) {
$builder->logFailure('Failed to symlink.');
return false;
}
} else {
$builder->executeCommand('cp -Rf "%s" "%s/"', $reference, $buildPath);
}
return true;
}
return true;
}
}

View file

@ -8,9 +8,10 @@
*/
namespace PHPCI\Model\Build;
use PHPCI\Model\Build,
PHPCI\Builder,
Symfony\Component\Yaml\Parser as YamlParser;
use PHPCI\Model\Build;
use PHPCI\Builder;
use Symfony\Component\Yaml\Parser as YamlParser;
/**
* Remote Git Build Model
@ -20,55 +21,55 @@ use PHPCI\Model\Build,
*/
abstract class RemoteGitBuild extends Build
{
abstract protected function getCloneUrl();
abstract protected function getCloneUrl();
public function createWorkingCopy(Builder $builder, $buildPath)
{
$yamlParser = new YamlParser();
$success = true;
$key = trim($this->getProject()->getGitKey());
public function createWorkingCopy(Builder $builder, $buildPath)
{
$yamlParser = new YamlParser();
$success = true;
$key = trim($this->getProject()->getGitKey());
if(!empty($key)) {
$success = $this->cloneBySsh($builder, $buildPath);
}
else {
$success = $this->cloneByHttp($builder, $buildPath);
}
if (!empty($key)) {
$success = $this->cloneBySsh($builder, $buildPath);
} else {
$success = $this->cloneByHttp($builder, $buildPath);
}
if(!$success) {
$builder->logFailure('Failed to clone remote git repository.');
return false;
}
if (!$success) {
$builder->logFailure('Failed to clone remote git repository.');
return false;
}
if(!is_file($buildPath . 'phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
if (!is_file($buildPath . 'phpci.yml')) {
$builder->logFailure('Project does not contain a phpci.yml file.');
return false;
}
$yamlFile = file_get_contents($buildPath . 'phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
$yamlFile = file_get_contents($buildPath . 'phpci.yml');
$builder->setConfigArray($yamlParser->parse($yamlFile));
return true;
}
return true;
}
protected function cloneByHttp(Builder $builder, $to)
{
return $builder->executeCommand('git clone -b %s %s "%s"', $this->getBranch(), $this->getCloneUrl(), $to);
}
protected function cloneByHttp(Builder $builder, $to)
{
return $builder->executeCommand('git clone -b %s %s "%s"', $this->getBranch(), $this->getCloneUrl(), $to);
}
protected function cloneBySsh(Builder $builder, $to)
{
// Copy the project's keyfile to disk:
$keyFile = realpath($to) . '.key';
file_put_contents($keyFile, $this->getProject()->getGitKey());
chmod($keyFile, 0600);
protected function cloneBySsh(Builder $builder, $to)
{
// Copy the project's keyfile to disk:
$keyFile = realpath($to) . '.key';
file_put_contents($keyFile, $this->getProject()->getGitKey());
chmod($keyFile, 0600);
// Use the key file to do an SSH clone:
$success = $builder->executeCommand('ssh-agent ssh-add "%s" && git clone -b %s %s "%s" && ssh-agent -k', $keyFile, $build->getBranch(), $this->getCloneUrl(), $to);
// Remove the key file:
unlink($keyFile);
// Use the key file to do an SSH clone:
$cmd = 'ssh-agent ssh-add "%s" && git clone -b %s %s "%s" && ssh-agent -k';
$success = $builder->executeCommand($cmd, $keyFile, $build->getBranch(), $this->getCloneUrl(), $to);
// Remove the key file:
unlink($keyFile);
return $success;
}
return $success;
}
}

View file

@ -9,13 +9,11 @@
namespace PHPCI\Model;
require_once(APPLICATION_PATH . 'PHPCI/Model/Base/ProjectBase.php');
use PHPCI\Model\Base\ProjectBase;
/**
* Project Model
* @uses PHPCI\Model\Base\ProjectBase
* @uses PHPCI\Model\Base\ProjectBase
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core

View file

@ -9,18 +9,16 @@
namespace PHPCI\Model;
require_once(APPLICATION_PATH . 'PHPCI/Model/Base/UserBase.php');
use PHPCI\Model\Base\UserBase;
/**
* User Model
* @uses PHPCI\Model\Base\UserBase
* @uses PHPCI\Model\Base\UserBase
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core
*/
class User extends UserBase
{
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.
}

View file

@ -14,9 +14,11 @@ require_once(APPLICATION_PATH . 'PHPCI/Store/Base/BuildStoreBase.php');
use PHPCI\Store\Base\BuildStoreBase;
/**
* Build Store
* @uses PHPCI\Store\Base\BuildStoreBase
*/
* Build Store
* @author Dan Cryer <dan@block8.co.uk>
* @package PHPCI
* @subpackage Core
*/
class BuildStore extends BuildStoreBase
{
// This class has been left blank so that you can modify it - changes in this file will not be overwritten.