Added ability to merge in-database project config over in-repository

config instead of only overwrite. This commit solve issues: #14, #70,
#106, #121.
This commit is contained in:
Dmitry Khomutov 2018-04-15 15:48:50 +07:00
parent f2a1ab39a2
commit 069026bc2d
No known key found for this signature in database
GPG key ID: EC19426474B37AAC
20 changed files with 277 additions and 130 deletions

View file

@ -127,13 +127,14 @@ class Builder implements LoggerAwareInterface
* *
* @throws \Exception * @throws \Exception
*/ */
public function setConfigArray($config) public function setConfig(array $config)
{ {
if (is_null($config) || !is_array($config)) { if (is_null($config) || !is_array($config)) {
throw new \Exception('This project does not contain a .php-censor.yml (.phpci.yml|phpci.yml) file, or it is empty.'); throw new \Exception('This project does not contain a .php-censor.yml (.phpci.yml|phpci.yml) file, or it is empty.');
} }
$this->logDebug('Config: ' . json_encode($config)); $this->logDebug('Config: ' . json_encode($config));
$this->config = $config; $this->config = $config;
} }
@ -144,15 +145,16 @@ class Builder implements LoggerAwareInterface
* *
* @return mixed * @return mixed
*/ */
public function getConfig($key) public function getConfig($key = null)
{ {
$rtn = null; $value = null;
if (null === $key) {
if (isset($this->config[$key])) { $value = $this->config;
$rtn = $this->config[$key]; } elseif (isset($this->config[$key])) {
$value = $this->config[$key];
} }
return $rtn; return $value;
} }
/** /**
@ -353,6 +355,8 @@ class Builder implements LoggerAwareInterface
$this->commandExecutor->setBuildPath($this->buildPath); $this->commandExecutor->setBuildPath($this->buildPath);
$this->build->handleConfigBeforeClone($this);
// Create a working copy of the project: // Create a working copy of the project:
if (!$this->build->createWorkingCopy($this, $this->buildPath)) { if (!$this->build->createWorkingCopy($this, $this->buildPath)) {
throw new \Exception('Could not create a working copy.'); throw new \Exception('Could not create a working copy.');
@ -395,10 +399,20 @@ class Builder implements LoggerAwareInterface
$this->buildLogger->log($message, $level, $context); $this->buildLogger->log($message, $level, $context);
} }
/**
* Add a warning-coloured message to the log.
*
* @param string $message
*/
public function logWarning($message)
{
$this->buildLogger->logWarning($message);
}
/** /**
* Add a success-coloured message to the log. * Add a success-coloured message to the log.
* *
* @param string * @param string $message
*/ */
public function logSuccess($message) public function logSuccess($message)
{ {
@ -417,9 +431,9 @@ class Builder implements LoggerAwareInterface
} }
/** /**
* Add a debug message to the log. * Add a debug-coloured message to the log.
* *
* @param string * @param string $message
*/ */
public function logDebug($message) public function logDebug($message)
{ {

View file

@ -311,18 +311,18 @@ class ProjectController extends WebController
$sshKey = new SshKey(); $sshKey = new SshKey();
$key = $sshKey->generate(); $key = $sshKey->generate();
$values['key'] = $key['private_key']; $values['ssh_private_key'] = $key['ssh_private_key'];
$values['pubkey'] = $key['public_key']; $values['ssh_public_key'] = $key['ssh_public_key'];
} }
$form = $this->projectForm($values); $form = $this->projectForm($values);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { if ($method !== 'POST' || ($method === 'POST' && !$form->validate())) {
$view = new View('Project/edit'); $view = new View('Project/edit');
$view->type = 'add'; $view->type = 'add';
$view->project = null; $view->project = null;
$view->form = $form; $view->form = $form;
$view->key = $values['pubkey']; $view->key = $values['ssh_public_key'];
return $view->render(); return $view->render();
} else { } else {
@ -331,14 +331,15 @@ class ProjectController extends WebController
$type = $this->getParam('type', null); $type = $this->getParam('type', null);
$options = [ $options = [
'ssh_private_key' => $this->getParam('key', null), 'ssh_private_key' => $this->getParam('ssh_private_key', null),
'ssh_public_key' => $this->getParam('pubkey', null), 'ssh_public_key' => $this->getParam('ssh_public_key', null),
'build_config' => $this->getParam('build_config', null), 'overwrite_build_config' => (boolean)$this->getParam('overwrite_build_config', true),
'allow_public_status' => (boolean)$this->getParam('allow_public_status', 0), 'build_config' => $this->getParam('build_config', null),
'branch' => $this->getParam('branch', null), 'allow_public_status' => (boolean)$this->getParam('allow_public_status', false),
'default_branch_only' => (boolean)$this->getParam('default_branch_only', 0), 'branch' => $this->getParam('branch', null),
'group' => (integer)$this->getParam('group_id', null), 'default_branch_only' => (boolean)$this->getParam('default_branch_only', false),
'environments' => $this->getParam('environments', null), 'group' => (integer)$this->getParam('group_id', null),
'environments' => $this->getParam('environments', null),
]; ];
/** @var PHPCensor\Model\User $user */ /** @var PHPCensor\Model\User $user */
@ -370,8 +371,6 @@ class ProjectController extends WebController
$this->layout->subtitle = Lang::get('edit_project'); $this->layout->subtitle = Lang::get('edit_project');
$values = $project->getDataArray(); $values = $project->getDataArray();
$values['key'] = $values['ssh_private_key'];
$values['pubkey'] = $values['ssh_public_key'];
$values['environments'] = $project->getEnvironments(); $values['environments'] = $project->getEnvironments();
if (in_array($values['type'], [ if (in_array($values['type'], [
@ -391,18 +390,18 @@ class ProjectController extends WebController
} }
} }
if ($method == 'POST') { if ($method === 'POST') {
$values = $this->getParams(); $values = $this->getParams();
} }
$form = $this->projectForm($values, 'edit/' . $projectId); $form = $this->projectForm($values, 'edit/' . $projectId);
if ($method != 'POST' || ($method == 'POST' && !$form->validate())) { if ($method !== 'POST' || ($method === 'POST' && !$form->validate())) {
$view = new View('Project/edit'); $view = new View('Project/edit');
$view->type = 'edit'; $view->type = 'edit';
$view->project = $project; $view->project = $project;
$view->form = $form; $view->form = $form;
$view->key = $values['pubkey']; $view->key = $values['ssh_public_key'];
return $view->render(); return $view->render();
} }
@ -412,15 +411,16 @@ class ProjectController extends WebController
$type = $this->getParam('type', null); $type = $this->getParam('type', null);
$options = [ $options = [
'ssh_private_key' => $this->getParam('key', null), 'ssh_private_key' => $this->getParam('ssh_private_key', null),
'ssh_public_key' => $this->getParam('pubkey', null), 'ssh_public_key' => $this->getParam('ssh_public_key', null),
'build_config' => $this->getParam('build_config', null), 'overwrite_build_config' => (boolean)$this->getParam('overwrite_build_config', false),
'allow_public_status' => (boolean)$this->getParam('allow_public_status', false), 'build_config' => $this->getParam('build_config', null),
'archived' => (boolean)$this->getParam('archived', false), 'allow_public_status' => (boolean)$this->getParam('allow_public_status', false),
'branch' => $this->getParam('branch', null), 'archived' => (boolean)$this->getParam('archived', false),
'default_branch_only' => (boolean)$this->getParam('default_branch_only', false), 'branch' => $this->getParam('branch', null),
'group' => (integer)$this->getParam('group_id', null), 'default_branch_only' => (boolean)$this->getParam('default_branch_only', false),
'environments' => $this->getParam('environments', null), 'group' => (integer)$this->getParam('group_id', null),
'environments' => $this->getParam('environments', null),
]; ];
$project = $this->projectService->updateProject($project, $title, $type, $reference, $options); $project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
@ -442,7 +442,7 @@ class ProjectController extends WebController
$form->setAction(APP_URL . 'project/' . $type); $form->setAction(APP_URL . 'project/' . $type);
$form->addField(new Form\Element\Csrf('project_form')); $form->addField(new Form\Element\Csrf('project_form'));
$form->addField(new Form\Element\Hidden('pubkey')); $form->addField(new Form\Element\Hidden('ssh_public_key'));
$options = [ $options = [
'choose' => Lang::get('select_repository_type'), 'choose' => Lang::get('select_repository_type'),
@ -457,8 +457,10 @@ class ProjectController extends WebController
Project::TYPE_SVN => 'Svn (Subversion)', Project::TYPE_SVN => 'Svn (Subversion)',
]; ];
$sourcesPattern = sprintf('^(%s)', implode('|', Project::$allowedTypes));
$field = Form\Element\Select::create('type', Lang::get('where_hosted'), true); $field = Form\Element\Select::create('type', Lang::get('where_hosted'), true);
$field->setPattern('^(github|bitbucket|bitbucket-hg|gitlab|gogs|git|local|hg|svn)'); $field->setPattern($sourcesPattern);
$field->setOptions($options); $field->setOptions($options);
$field->setClass('form-control')->setContainerClass('form-group'); $field->setClass('form-control')->setContainerClass('form-group');
$form->addField($field); $form->addField($field);
@ -486,11 +488,21 @@ class ProjectController extends WebController
$field->setValue(0); $field->setValue(0);
$form->addField($field); $form->addField($field);
$field = Form\Element\TextArea::create('key', Lang::get('project_private_key'), false); $field = Form\Element\TextArea::create('ssh_private_key', Lang::get('project_private_key'), false);
$field->setClass('form-control')->setContainerClass('form-group'); $field->setClass('form-control')->setContainerClass('form-group');
$field->setRows(6); $field->setRows(6);
$form->addField($field); $form->addField($field);
$field = Form\Element\Checkbox::create(
'overwrite_build_config',
Lang::get('overwrite_build_config'),
false
);
$field->setContainerClass('form-group');
$field->setCheckedValue(1);
$field->setValue(1);
$form->addField($field);
$field = Form\Element\TextArea::create('build_config', Lang::get('build_config'), false); $field = Form\Element\TextArea::create('build_config', Lang::get('build_config'), false);
$field->setClass('form-control')->setContainerClass('form-group'); $field->setClass('form-control')->setContainerClass('form-group');
$field->setRows(6); $field->setRows(6);
@ -515,7 +527,11 @@ class ProjectController extends WebController
$field->setOptions($groups); $field->setOptions($groups);
$form->addField($field); $form->addField($field);
$field = Form\Element\Checkbox::create('allow_public_status', Lang::get('allow_public_status'), false); $field = Form\Element\Checkbox::create(
'allow_public_status',
Lang::get('allow_public_status'),
false
);
$field->setContainerClass('form-group'); $field->setContainerClass('form-group');
$field->setCheckedValue(1); $field->setCheckedValue(1);
$field->setValue(0); $field->setValue(0);

View file

@ -23,7 +23,10 @@ class SshKey
mkdir($tempPath); mkdir($tempPath);
} }
$return = ['private_key' => '', 'public_key' => '']; $return = [
'ssh_private_key' => '',
'ssh_public_key' => ''
];
$sshStrength = Config::getInstance()->get('php-censor.ssh.strength', 2048); $sshStrength = Config::getInstance()->get('php-censor.ssh.strength', 2048);
$sshComment = Config::getInstance()->get('php-censor.ssh.comment', 'admin@php-censor'); $sshComment = Config::getInstance()->get('php-censor.ssh.comment', 'admin@php-censor');
@ -42,11 +45,11 @@ class SshKey
$prv = file_get_contents($keyFile); $prv = file_get_contents($keyFile);
if (!empty($pub)) { if (!empty($pub)) {
$return['public_key'] = $pub; $return['ssh_public_key'] = $pub;
} }
if (!empty($prv)) { if (!empty($prv)) {
$return['private_key'] = $prv; $return['ssh_private_key'] = $prv;
} }
} }

View file

@ -119,6 +119,7 @@ PHP Censor',
(if you cannot add a .php-censor.yml (.phpci.yml|phpci.yml) file in the project repository)', (if you cannot add a .php-censor.yml (.phpci.yml|phpci.yml) file in the project repository)',
'default_branch' => 'Default branch name', 'default_branch' => 'Default branch name',
'default_branch_only' => 'Build default branch only', 'default_branch_only' => 'Build default branch only',
'overwrite_build_config' => 'Overwrite in-repository file config by in-database config? If checkbox not checked then in-database config will be merged with file config.',
'allow_public_status' => 'Enable public status page and image for this project?', 'allow_public_status' => 'Enable public status page and image for this project?',
'archived' => 'Archived', 'archived' => 'Archived',
'archived_menu' => 'Archived', 'archived_menu' => 'Archived',

View file

@ -115,6 +115,7 @@ PHP Censor',
(если вы не добавили файл .php-censor.yml (.phpci.yml|phpci.yml) в репозиторий вашего проекта)', (если вы не добавили файл .php-censor.yml (.phpci.yml|phpci.yml) в репозиторий вашего проекта)',
'default_branch' => 'Ветка по умолчанию', 'default_branch' => 'Ветка по умолчанию',
'default_branch_only' => 'Собирать только ветку по умолчанию', 'default_branch_only' => 'Собирать только ветку по умолчанию',
'overwrite_build_config' => 'Заменить конфигурацию из файла в проекте конфигурацией из базы данных? Если чекбокс не отмечен, то конфигурации из файла и базы данных будут объединены.',
'allow_public_status' => 'Разрешить публичный статус и изображение (статуса) для проекта', 'allow_public_status' => 'Разрешить публичный статус и изображение (статуса) для проекта',
'archived' => 'Архивный', 'archived' => 'Архивный',
'archived_menu' => 'Архив', 'archived_menu' => 'Архив',

View file

@ -23,9 +23,8 @@ class BuildLogger implements LoggerAwareInterface
protected $build; protected $build;
/** /**
* Set up the BuildLogger class.
* @param LoggerInterface $logger * @param LoggerInterface $logger
* @param Build $build * @param Build $build
*/ */
public function __construct(LoggerInterface $logger, Build $build) public function __construct(LoggerInterface $logger, Build $build)
{ {
@ -35,9 +34,10 @@ class BuildLogger implements LoggerAwareInterface
/** /**
* Add an entry to the build log. * Add an entry to the build log.
*
* @param string|string[] $message * @param string|string[] $message
* @param string $level * @param string $level
* @param mixed[] $context * @param mixed[] $context
*/ */
public function log($message, $level = LogLevel::INFO, $context = []) public function log($message, $level = LogLevel::INFO, $context = [])
{ {
@ -59,9 +59,20 @@ class BuildLogger implements LoggerAwareInterface
} }
} }
/**
* Add a warning-coloured message to the log.
*
* @param string $message
*/
public function logWarning($message)
{
$this->log("\033[0;31m" . $message . "\033[0m", LogLevel::WARNING);
}
/** /**
* Add a success-coloured message to the log. * Add a success-coloured message to the log.
* @param string *
* @param string $message
*/ */
public function logSuccess($message) public function logSuccess($message)
{ {
@ -70,7 +81,8 @@ class BuildLogger implements LoggerAwareInterface
/** /**
* Add a failure-coloured message to the log. * Add a failure-coloured message to the log.
* @param string $message *
* @param string $message
* @param \Exception $exception The exception that caused the error. * @param \Exception $exception The exception that caused the error.
*/ */
public function logFailure($message, \Exception $exception = null) public function logFailure($message, \Exception $exception = null)
@ -88,8 +100,9 @@ class BuildLogger implements LoggerAwareInterface
} }
/** /**
* Add a debug message to the log. * Add a debug-coloured message to the log.
* @param string *
* @param string $message
*/ */
public function logDebug($message) public function logDebug($message)
{ {
@ -105,7 +118,6 @@ class BuildLogger implements LoggerAwareInterface
* Sets a logger instance on the object * Sets a logger instance on the object
* *
* @param LoggerInterface $logger * @param LoggerInterface $logger
* @return null
*/ */
public function setLogger(LoggerInterface $logger) public function setLogger(LoggerInterface $logger)
{ {

View file

@ -0,0 +1,32 @@
<?php
use Phinx\Migration\AbstractMigration;
class AddedOverwriteConfigFieldToProject extends AbstractMigration
{
public function up()
{
if ($this->hasTable('project')) {
$table = $this->table('project');
if (!$table->hasColumn('overwrite_build_config')) {
$table
->addColumn('overwrite_build_config', 'integer', ['default' => 1])
->save();
}
}
}
public function down()
{
if ($this->hasTable('project')) {
$table = $this->table('project');
if ($table->hasColumn('overwrite_build_config')) {
$table
->removeColumn('overwrite_build_config')
->save();
}
}
}
}

View file

@ -28,7 +28,7 @@ class Build extends Model
'commit_id' => null, 'commit_id' => null,
'status' => null, 'status' => null,
'log' => null, 'log' => null,
'branch' => null, 'branch' => 'master',
'tag' => null, 'tag' => null,
'create_date' => null, 'create_date' => null,
'start_date' => null, 'start_date' => null,

View file

@ -29,8 +29,8 @@ class BuildError extends Model
'severity' => null, 'severity' => null,
'message' => null, 'message' => null,
'create_date' => null, 'create_date' => null,
'hash' => null, 'hash' => '',
'is_new' => null, 'is_new' => 0,
]; ];
/** /**

View file

@ -26,27 +26,28 @@ class Project extends Model
* @var array * @var array
*/ */
protected $data = [ protected $data = [
'id' => null, 'id' => null,
'title' => null, 'title' => null,
'reference' => null, 'reference' => null,
'branch' => null, 'branch' => null,
'default_branch_only' => null, 'default_branch_only' => 0,
'ssh_private_key' => null, 'ssh_private_key' => null,
'ssh_public_key' => null, 'ssh_public_key' => null,
'type' => null, 'type' => null,
'access_information' => null, 'access_information' => null,
'build_config' => null, 'build_config' => null,
'allow_public_status' => null, 'overwrite_build_config' => 1,
'archived' => null, 'allow_public_status' => 0,
'group_id' => null, 'archived' => 0,
'create_date' => null, 'group_id' => 1,
'user_id' => 0, 'create_date' => null,
'user_id' => 0,
]; ];
/** /**
* @var array * @var array
*/ */
protected $allowedTypes = [ public static $allowedTypes = [
self::TYPE_LOCAL, self::TYPE_LOCAL,
self::TYPE_GIT, self::TYPE_GIT,
self::TYPE_GITHUB, self::TYPE_GITHUB,
@ -281,9 +282,9 @@ class Project extends Model
$this->validateNotNull('type', $value); $this->validateNotNull('type', $value);
$this->validateString('type', $value); $this->validateString('type', $value);
if (!in_array($value, $this->allowedTypes, true)) { if (!in_array($value, static::$allowedTypes, true)) {
throw new InvalidArgumentException( throw new InvalidArgumentException(
'Column "type" must be one of: ' . join(', ', $this->allowedTypes) . '.' 'Column "type" must be one of: ' . join(', ', static::$allowedTypes) . '.'
); );
} }
@ -359,6 +360,33 @@ class Project extends Model
return $this->setModified('build_config'); return $this->setModified('build_config');
} }
/**
* @return boolean
*/
public function getOverwriteBuildConfig()
{
return (boolean)$this->data['overwrite_build_config'];
}
/**
* @param boolean $value
*
* @return boolean
*/
public function setOverwriteBuildConfig($value)
{
$this->validateNotNull('overwrite_build_config', $value);
$this->validateBoolean('overwrite_build_config', $value);
if ($this->data['overwrite_build_config'] === (integer)$value) {
return false;
}
$this->data['overwrite_build_config'] = (integer)$value;
return $this->setModified('overwrite_build_config');
}
/** /**
* @return boolean * @return boolean
*/ */

View file

@ -18,11 +18,11 @@ class User extends Model
'id' => null, 'id' => null,
'email' => null, 'email' => null,
'hash' => null, 'hash' => null,
'is_admin' => null, 'is_admin' => 0,
'name' => null, 'name' => null,
'language' => null, 'language' => null,
'per_page' => null, 'per_page' => null,
'provider_key' => null, 'provider_key' => 'internal',
'provider_data' => null, 'provider_data' => null,
'remember_key' => null, 'remember_key' => null,
]; ];

View file

@ -6,6 +6,7 @@ use PHPCensor\Builder;
use PHPCensor\Store\Factory; use PHPCensor\Store\Factory;
use PHPCensor\Store\ProjectStore; use PHPCensor\Store\ProjectStore;
use PHPCensor\Store\BuildErrorStore; use PHPCensor\Store\BuildErrorStore;
use Psr\Log\LogLevel;
use Symfony\Component\Filesystem\Filesystem; use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Yaml\Parser as YamlParser; use Symfony\Component\Yaml\Parser as YamlParser;
use PHPCensor\Model\Base\Build as BaseBuild; use PHPCensor\Model\Base\Build as BaseBuild;
@ -200,33 +201,70 @@ class Build extends BaseBuild
/** /**
* @param Builder $builder * @param Builder $builder
* @param string $buildPath
* *
* @return bool * @return bool
*
* @throws \Exception
*/ */
protected function handleConfig(Builder $builder, $buildPath) public function handleConfigBeforeClone(Builder $builder)
{ {
$buildConfig = $this->getProject()->getBuildConfig(); $buildConfig = $this->getProject()->getBuildConfig();
if (empty($buildConfig)) { if ($buildConfig) {
if (file_exists($buildPath . '/.php-censor.yml')) { $yamlParser = new YamlParser();
$buildConfig = file_get_contents($buildPath . '/.php-censor.yml'); $buildConfig = $yamlParser->parse($buildConfig);
} elseif (file_exists($buildPath . '/.phpci.yml')) {
$buildConfig = file_get_contents($buildPath . '/.phpci.yml'); if ($buildConfig && is_array($buildConfig)) {
} elseif (file_exists($buildPath . '/phpci.yml')) { $builder->setConfig($buildConfig);
$buildConfig = file_get_contents($buildPath . '/phpci.yml');
} else {
$buildConfig = $this->getZeroConfigPlugins($builder);
} }
} }
// for YAML configs from files/DB return true;
if (is_string($buildConfig)) { }
$yamlParser = new YamlParser();
$buildConfig = $yamlParser->parse($buildConfig); /**
* @param Builder $builder
* @param string $buildPath
*
* @return bool
*
* @throws \Exception
*/
protected function handleConfig(Builder $builder, $buildPath)
{
$yamlParser = new YamlParser();
$overwriteBuildConfig = $this->getProject()->getOverwriteBuildConfig();
$buildConfig = $builder->getConfig();
$repositoryConfig = $this->getZeroConfigPlugins($builder);
if (file_exists($buildPath . '/.php-censor.yml')) {
$repositoryConfig = $yamlParser->parse(
file_get_contents($buildPath . '/.php-censor.yml')
);
} elseif (file_exists($buildPath . '/.phpci.yml')) {
$repositoryConfig = $yamlParser->parse(
file_get_contents($buildPath . '/.phpci.yml')
);
} elseif (file_exists($buildPath . '/phpci.yml')) {
$repositoryConfig = $yamlParser->parse(
file_get_contents($buildPath . '/phpci.yml')
);
} }
$builder->setConfigArray($buildConfig); if (isset($repositoryConfig['build_settings']['clone_depth'])) {
$builder->logWarning(
'Option "build_settings.clone_depth" supported only in additional DB project config.' .
' Please move this option to DB config from your in-repository config file (".php-censor.yml").'
);
}
if (!$buildConfig) {
$buildConfig = $repositoryConfig;
} elseif ($buildConfig && !$overwriteBuildConfig) {
$buildConfig = array_replace_recursive($repositoryConfig, $buildConfig);
}
$builder->setConfig($buildConfig);
return true; return true;
} }

View file

@ -59,10 +59,10 @@ class GitBuild extends Build
foreach ($branches as $branch) { foreach ($branches as $branch) {
$success = $builder->executeCommand($cmd, $buildPath, $branch); $success = $builder->executeCommand($cmd, $buildPath, $branch);
if (!$success) { if (!$success) {
$builder->log('Fail merge branch origin/'.$branch, LogLevel::ERROR); $builder->log('Fail merge branch origin/' . $branch, LogLevel::ERROR);
return false; return false;
} }
$builder->log('Merged branch origin/'.$branch, LogLevel::INFO); $builder->log('Merged branch origin/' . $branch, LogLevel::INFO);
} }
} }
return true; return true;
@ -75,10 +75,9 @@ class GitBuild extends Build
{ {
$cmd = 'cd .. && git clone --recursive '; $cmd = 'cd .. && git clone --recursive ';
$depth = $builder->getConfig('clone_depth'); $buildSettings = $builder->getConfig('build_settings');
if ($buildSettings && isset($buildSettings['clone_depth'])) {
if (!is_null($depth)) { $cmd .= ' --depth ' . intval($buildSettings['clone_depth']) . ' ';
$cmd .= ' --depth ' . intval($depth) . ' ';
} }
$cmd .= ' -b "%s" "%s" "%s"'; $cmd .= ' -b "%s" "%s" "%s"';
@ -102,10 +101,9 @@ class GitBuild extends Build
// Do the git clone: // Do the git clone:
$cmd = 'cd .. && git clone --recursive '; $cmd = 'cd .. && git clone --recursive ';
$depth = $builder->getConfig('clone_depth'); $buildSettings = $builder->getConfig('build_settings');
if ($buildSettings && isset($buildSettings['clone_depth'])) {
if (!is_null($depth)) { $cmd .= ' --depth ' . intval($buildSettings['clone_depth']) . ' ';
$cmd .= ' --depth ' . intval($depth) . ' ';
} }
$cmd .= ' -b "%s" "%s" "%s"'; $cmd .= ' -b "%s" "%s" "%s"';

View file

@ -23,8 +23,11 @@ class LocalBuild extends Build
// If there's a /config file in the reference directory, it is probably a bare repository // If there's a /config file in the reference directory, it is probably a bare repository
// which we'll extract into our build path directly. // which we'll extract into our build path directly.
if (is_file($reference.'/config') && $this->handleBareRepository($builder, $reference, $buildPath) === true) { if (
return $this->handleConfig($builder, $buildPath) !== false; is_file($reference . '/config') &&
true === $this->handleBareRepository($builder, $reference, $buildPath)
) {
return $this->handleConfig($builder, $buildPath);
} }
$configHandled = $this->handleConfig($builder, $reference); $configHandled = $this->handleConfig($builder, $reference);

View file

@ -50,14 +50,13 @@ class SvnBuild extends Build
$svn = $builder->getConfig('svn'); $svn = $builder->getConfig('svn');
if ($svn) { if ($svn) {
foreach ($svn as $key => $value) { foreach ($svn as $key => $value) {
$cmd .= " --$key $value "; $cmd .= " --${key} ${value} ";
} }
} }
$depth = $builder->getConfig('clone_depth'); $buildSettings = $builder->getConfig('build_settings');
if ($buildSettings && isset($buildSettings['clone_depth'])) {
if (!is_null($depth)) { $cmd .= ' --depth ' . intval($buildSettings['clone_depth']) . ' ';
$cmd .= ' --depth ' . intval($depth) . ' ';
} }
$this->svnCommand = $cmd; $this->svnCommand = $cmd;
@ -68,8 +67,6 @@ class SvnBuild extends Build
*/ */
public function createWorkingCopy(Builder $builder, $buildPath) public function createWorkingCopy(Builder $builder, $buildPath)
{ {
$this->handleConfig($builder, $buildPath);
$this->extendSvnCommandFromConfig($builder); $this->extendSvnCommandFromConfig($builder);
$key = trim($this->getProject()->getSshPrivateKey()); $key = trim($this->getProject()->getSshPrivateKey());

View file

@ -65,6 +65,7 @@ class ProjectService
$project->setReference($reference); $project->setReference($reference);
$project->setAllowPublicStatus(false); $project->setAllowPublicStatus(false);
$project->setDefaultBranchOnly(false); $project->setDefaultBranchOnly(false);
$project->setOverwriteBuildConfig(true);
// Handle extra project options: // Handle extra project options:
if (array_key_exists('ssh_private_key', $options)) { if (array_key_exists('ssh_private_key', $options)) {
@ -75,6 +76,10 @@ class ProjectService
$project->setSshPublicKey($options['ssh_public_key']); $project->setSshPublicKey($options['ssh_public_key']);
} }
if (array_key_exists('overwrite_build_config', $options)) {
$project->setOverwriteBuildConfig($options['overwrite_build_config']);
}
if (array_key_exists('build_config', $options)) { if (array_key_exists('build_config', $options)) {
$project->setBuildConfig($options['build_config']); $project->setBuildConfig($options['build_config']);
} }

View file

@ -13,8 +13,6 @@
lineWrapping: true, lineWrapping: true,
lineNumbers: true lineNumbers: true
}); });
setupProjectForm();
}); });
</script> </script>

View file

@ -20,7 +20,7 @@ class BuildTest extends TestCase
'commit_id' => null, 'commit_id' => null,
'status' => null, 'status' => null,
'log' => null, 'log' => null,
'branch' => null, 'branch' => 'master',
'tag' => null, 'tag' => null,
'create_date' => null, 'create_date' => null,
'start_date' => null, 'start_date' => null,

View file

@ -15,21 +15,22 @@ class ProjectTest extends TestCase
self::assertInstanceOf('PHPCensor\Model\Base\Project', $project); self::assertInstanceOf('PHPCensor\Model\Base\Project', $project);
self::assertEquals([ self::assertEquals([
'id' => null, 'id' => null,
'title' => null, 'title' => null,
'reference' => null, 'reference' => null,
'branch' => null, 'branch' => null,
'default_branch_only' => null, 'default_branch_only' => 0,
'ssh_private_key' => null, 'ssh_private_key' => null,
'ssh_public_key' => null, 'ssh_public_key' => null,
'type' => null, 'type' => null,
'access_information' => null, 'access_information' => null,
'build_config' => null, 'build_config' => null,
'allow_public_status' => null, 'overwrite_build_config' => 1,
'archived' => null, 'allow_public_status' => 0,
'group_id' => null, 'archived' => 0,
'create_date' => null, 'group_id' => 1,
'user_id' => 0, 'create_date' => null,
'user_id' => 0,
], $project->getDataArray()); ], $project->getDataArray());
} }

View file

@ -18,11 +18,11 @@ class UserTest extends TestCase
'id' => null, 'id' => null,
'email' => null, 'email' => null,
'hash' => null, 'hash' => null,
'is_admin' => null, 'is_admin' => 0,
'name' => null, 'name' => null,
'language' => null, 'language' => null,
'per_page' => null, 'per_page' => null,
'provider_key' => null, 'provider_key' => 'internal',
'provider_data' => null, 'provider_data' => null,
'remember_key' => null, 'remember_key' => null,
], $user->getDataArray()); ], $user->getDataArray());