Fixed branches for SVN build. Issue #65.

This commit is contained in:
Dmitry Khomutov 2017-05-17 21:46:55 +07:00
parent 2b3c387f18
commit e071088bba
No known key found for this signature in database
GPG key ID: 7EB36C9576F9ECB9
4 changed files with 52 additions and 36 deletions

View file

@ -432,8 +432,7 @@ function setupProjectForm()
$('#element-reference').trigger('change');
});
$('#element-github').change(function()
{
$('#element-github').change(function() {
var val = $('#element-github').val();
if(val != 'choose') {
@ -443,11 +442,9 @@ function setupProjectForm()
$('label[for=element-reference]').hide();
$('label[for=element-type]').hide();
$('#element-reference').hide();
$('#element-type').hide();
$('#element-token').val(window.github_token);
$('#element-title').val(val);
}
else {
} else {
$('label[for=element-reference]').show();
$('label[for=element-type]').show();
$('#element-reference').show();

View file

@ -137,12 +137,16 @@ class ProjectController extends PHPCensor\Controller
*/
public function build($projectId)
{
$type = $this->getParam('type', 'branch');
$id = $this->getParam('id', 'master');
$debug = (boolean)$this->getParam('debug', false);
/* @var \PHPCensor\Model\Project $project */
$project = $this->projectStore->getById($projectId);
$project = $this->projectStore->getById($projectId);
if (empty($project) || $project->getArchived()) {
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
}
$type = $this->getParam('type', 'branch');
$id = $this->getParam('id');
$debug = (boolean)$this->getParam('debug', false);
$environment = null;
$branch = null;
@ -155,10 +159,6 @@ class ProjectController extends PHPCensor\Controller
break;
}
if (empty($project) || $project->getArchived()) {
throw new NotFoundException(Lang::get('project_x_not_found', $projectId));
}
if (empty($branch)) {
$branch = $project->getBranch();
}
@ -443,6 +443,10 @@ class ProjectController extends PHPCensor\Controller
$field->setClass('form-control')->setContainerClass('form-group');
$form->addField($field);
$field = Form\Element\Text::create('branch', Lang::get('default_branch'), false);
$field->setClass('form-control')->setContainerClass('form-group')->setValue('');
$form->addField($field);
$field = Form\Element\TextArea::create('key', Lang::get('project_private_key'), false);
$field->setClass('form-control')->setContainerClass('form-group');
$field->setRows(6);
@ -453,10 +457,6 @@ class ProjectController extends PHPCensor\Controller
$field->setRows(6);
$form->addField($field);
$field = Form\Element\Text::create('branch', Lang::get('default_branch'), true);
$field->setClass('form-control')->setContainerClass('form-group')->setValue('master');
$form->addField($field);
$field = Form\Element\TextArea::create('environments', Lang::get('environments_label'), false);
$field->setClass('form-control')->setContainerClass('form-group');
$field->setRows(6);

View file

@ -739,7 +739,19 @@ class Project extends Model
public function getBranch()
{
if (empty($this->data['branch'])) {
return $this->getType() === 'hg' ? 'default' : 'master';
$projectType = $this->getType();
switch ($projectType) {
case 'hg':
$branch = 'default';
break;
case 'svn':
$branch = 'trunk';
break;
default:
$branch = 'master';
}
return $branch;
} else {
return $this->data['branch'];
}
@ -795,7 +807,7 @@ class Project extends Model
}
$cacheKey = 'Cache.ProjectEnvironments.' . $key;
$rtn = $this->cache->get($cacheKey, null);
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$store = $this->getEnvironmentStore();
@ -813,12 +825,13 @@ class Project extends Model
*/
public function getEnvironmentsNames()
{
$environments = $this->getEnvironmentsObjects();
$environments = $this->getEnvironmentsObjects();
$environments_names = [];
foreach($environments['items'] as $environment) {
/** @var Environment $environment */
$environments_names[] = $environment->getName();
}
return $environments_names;
}
@ -829,14 +842,16 @@ class Project extends Model
*/
public function getEnvironments()
{
$environments = $this->getEnvironmentsObjects();
$environments = $this->getEnvironmentsObjects();
$environments_config = [];
foreach($environments['items'] as $environment) {
/** @var Environment $environment */
$environments_config[$environment->getName()] = $environment->getBranches();
}
$yaml_dumper = new YamlDumper();
$value = $yaml_dumper->dump($environments_config, 10, 0, true, false);
$value = $yaml_dumper->dump($environments_config, 10, 0, true, false);
return $value;
}
@ -847,12 +862,11 @@ class Project extends Model
*/
public function setEnvironments($value)
{
$yaml_parser = new YamlParser();
$environments_config = $yaml_parser->parse($value);
$environments_names = !empty($environments_config) ? array_keys($environments_config) : [];
$yaml_parser = new YamlParser();
$environments_config = $yaml_parser->parse($value);
$environments_names = !empty($environments_config) ? array_keys($environments_config) : [];
$current_environments = $this->getEnvironmentsObjects();
$store = $this->getEnvironmentStore();
$store = $this->getEnvironmentStore();
foreach ($current_environments['items'] as $environment) {
/** @var Environment $environment */
$key = array_search($environment->getName(), $environments_names);
@ -866,6 +880,7 @@ class Project extends Model
$store->delete($environment);
}
}
if (!empty($environments_names)) {
// add
foreach ($environments_names as $environment_name) {
@ -880,29 +895,32 @@ class Project extends Model
/**
* @param string $branch
*
* @return string[]
*/
public function getEnvironmentsNamesByBranch($branch)
{
$environments_names = [];
$environments = $this->getEnvironmentsObjects();
$default_branch = ($branch == $this->getBranch());
$environments = $this->getEnvironmentsObjects();
$default_branch = ($branch == $this->getBranch());
foreach($environments['items'] as $environment) {
/** @var Environment $environment */
if ($default_branch || in_array($branch, $environment->getBranches())) {
$environments_names[] = $environment->getName();
}
}
return $environments_names;
}
/**
* @param string $environment_name
*
* @return string[]
*/
public function getBranchesByEnvironment($environment_name)
{
$branches = [];
$branches = [];
$environments = $this->getEnvironmentsObjects();
foreach($environments['items'] as $environment) {
/** @var Environment $environment */
@ -910,6 +928,7 @@ class Project extends Model
return $environment->getBranches();
}
}
return $branches;
}
}

View file

@ -64,28 +64,28 @@ class BuildService
$branches = $project->getBranchesByEnvironment($environment);
$build->setExtraValue('branches', $branches);
if (!is_null($commitId)) {
if (!empty($commitId)) {
$build->setCommitId($commitId);
} else {
$build->setCommitId('Manual');
$build->setCommitMessage('Manual');
}
if (!is_null($branch)) {
if (!empty($branch)) {
$build->setBranch($branch);
} else {
$build->setBranch($project->getBranch());
}
if (!is_null($tag)) {
if (!empty($tag)) {
$build->setTag($tag);
}
if (!is_null($committerEmail)) {
if (!empty($committerEmail)) {
$build->setCommitterEmail($committerEmail);
}
if (!is_null($commitMessage)) {
if (!empty($commitMessage)) {
$build->setCommitMessage($commitMessage);
}