Added a checkbox to build only the default branch specified in the project.
This commit is contained in:
parent
bc1ee39467
commit
bbbd9b3cf2
|
@ -317,6 +317,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
'build_config' => $this->getParam('build_config', null),
|
||||
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
||||
'branch' => $this->getParam('branch', null),
|
||||
'default_branch_only' => $this->getParam('default_branch_only', 0),
|
||||
'group' => $this->getParam('group_id', null),
|
||||
'environments' => $this->getParam('environments', null),
|
||||
];
|
||||
|
@ -385,6 +386,7 @@ class ProjectController extends PHPCensor\Controller
|
|||
'allow_public_status' => $this->getParam('allow_public_status', 0),
|
||||
'archived' => $this->getParam('archived', 0),
|
||||
'branch' => $this->getParam('branch', null),
|
||||
'default_branch_only' => $this->getParam('default_branch_only', 0),
|
||||
'group' => $this->getParam('group_id', null),
|
||||
'environments' => $this->getParam('environments', null),
|
||||
];
|
||||
|
@ -450,6 +452,16 @@ class ProjectController extends PHPCensor\Controller
|
|||
$field->setClass('form-control')->setContainerClass('form-group')->setValue('');
|
||||
$form->addField($field);
|
||||
|
||||
$field = Form\Element\Checkbox::create(
|
||||
'default_branch_only',
|
||||
Lang::get('default_branch_only'),
|
||||
false
|
||||
);
|
||||
$field->setContainerClass('form-group');
|
||||
$field->setCheckedValue(1);
|
||||
$field->setValue(0);
|
||||
$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);
|
||||
|
|
|
@ -636,6 +636,14 @@ class WebhookController extends Controller
|
|||
}
|
||||
}
|
||||
|
||||
// Check if this branch is to be built.
|
||||
if ($project->getDefaultBranchOnly() && ($branch !== $project->getBranch())) {
|
||||
return [
|
||||
'status' => 'ignored',
|
||||
'message' => 'The branch is not a branch by default. Build is allowed only for the branch by default.'
|
||||
];
|
||||
}
|
||||
|
||||
$environments = $project->getEnvironmentsObjects();
|
||||
if ($environments['count']) {
|
||||
$created_builds = [];
|
||||
|
|
|
@ -115,12 +115,13 @@ PHP Censor',
|
|||
(leave blank for local and/or anonymous remotes)',
|
||||
'build_config' => 'PHP Censor build config for this project
|
||||
(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',
|
||||
'allow_public_status' => 'Enable public status page and image for this project?',
|
||||
'archived' => 'Archived',
|
||||
'archived_menu' => 'Archived',
|
||||
'save_project' => 'Save Project',
|
||||
'environments_label' => 'Environments (yaml)',
|
||||
'archived' => 'Archived',
|
||||
'archived_menu' => 'Archived',
|
||||
'save_project' => 'Save Project',
|
||||
'environments_label' => 'Environments (yaml)',
|
||||
|
||||
'error_mercurial' => 'Mercurial repository URL must be start with http:// or https://',
|
||||
'error_remote' => 'Repository URL must be start with git://, http:// or https://',
|
||||
|
|
|
@ -112,12 +112,13 @@ PHP Censor',
|
|||
(оставьте поле пустым для локального использования и/или анонимного доступа)',
|
||||
'build_config' => 'Конфигурация сборки проекта для PHP Censor
|
||||
(если вы не добавили файл .php-censor.yml (.phpci.yml|phpci.yml) в репозиторий вашего проекта)',
|
||||
'default_branch' => 'Ветка по умолчанию',
|
||||
'default_branch' => 'Ветка по умолчанию',
|
||||
'default_branch_only' => 'Собирать только ветку по умолчанию',
|
||||
'allow_public_status' => 'Разрешить публичный статус и изображение (статуса) для проекта',
|
||||
'archived' => 'Архивный',
|
||||
'archived_menu' => 'Архив',
|
||||
'save_project' => 'Сохранить проект',
|
||||
'environments_label' => 'Окружения (yaml)',
|
||||
'archived' => 'Архивный',
|
||||
'archived_menu' => 'Архив',
|
||||
'save_project' => 'Сохранить проект',
|
||||
'environments_label' => 'Окружения (yaml)',
|
||||
|
||||
'error_mercurial' => 'URL репозитория Mercurial должен начинаться с http:// или https://',
|
||||
'error_remote' => 'URL репозитория должен начинаться с git://, http:// или https://',
|
||||
|
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
use Phinx\Migration\AbstractMigration;
|
||||
|
||||
class AddedDefaultBranchOnly extends AbstractMigration
|
||||
{
|
||||
public function up()
|
||||
{
|
||||
$project = $this->table('project');
|
||||
|
||||
if (!$project->hasColumn('default_branch_only')) {
|
||||
$project->addColumn('default_branch_only', 'integer');
|
||||
}
|
||||
}
|
||||
|
||||
public function down()
|
||||
{
|
||||
$project = $this->table('project');
|
||||
|
||||
if ($project->hasColumn('default_branch_only')) {
|
||||
$project->removeColumn('default_branch_only')->save();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -37,6 +37,7 @@ class Project extends Model
|
|||
'title' => null,
|
||||
'reference' => null,
|
||||
'branch' => null,
|
||||
'default_branch_only' => null,
|
||||
'ssh_private_key' => null,
|
||||
'type' => null,
|
||||
'access_information' => null,
|
||||
|
@ -57,6 +58,7 @@ class Project extends Model
|
|||
'title' => 'getTitle',
|
||||
'reference' => 'getReference',
|
||||
'branch' => 'getBranch',
|
||||
'default_branch_only' => 'getDefaultBranchOnly',
|
||||
'ssh_private_key' => 'getSshPrivateKey',
|
||||
'type' => 'getType',
|
||||
'access_information' => 'getAccessInformation',
|
||||
|
@ -79,6 +81,7 @@ class Project extends Model
|
|||
'title' => 'setTitle',
|
||||
'reference' => 'setReference',
|
||||
'branch' => 'setBranch',
|
||||
'default_branch_only' => 'setDefaultBranchOnly',
|
||||
'ssh_private_key' => 'setSshPrivateKey',
|
||||
'type' => 'setType',
|
||||
'access_information' => 'setAccessInformation',
|
||||
|
@ -118,6 +121,10 @@ class Project extends Model
|
|||
'length' => 250,
|
||||
'default' => 'master',
|
||||
],
|
||||
'default_branch_only' => [
|
||||
'type' => 'int',
|
||||
'length' => 11,
|
||||
],
|
||||
'ssh_private_key' => [
|
||||
'type' => 'text',
|
||||
'nullable' => true,
|
||||
|
@ -303,7 +310,7 @@ class Project extends Model
|
|||
*/
|
||||
public function getArchived()
|
||||
{
|
||||
$rtn = $this->data['archived'];
|
||||
$rtn = $this->data['archived'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -315,7 +322,19 @@ class Project extends Model
|
|||
*/
|
||||
public function getGroupId()
|
||||
{
|
||||
$rtn = $this->data['group_id'];
|
||||
$rtn = $this->data['group_id'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the value of DefaultBranchOnly / default_branch_only.
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function getDefaultBranchOnly()
|
||||
{
|
||||
$rtn = $this->data['default_branch_only'];
|
||||
|
||||
return $rtn;
|
||||
}
|
||||
|
@ -400,6 +419,26 @@ class Project extends Model
|
|||
$this->setModified('branch');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of DefaultBranchOnly / default_branch_only.
|
||||
*
|
||||
* Must not be null.
|
||||
* @param $value int
|
||||
*/
|
||||
public function setDefaultBranchOnly($value)
|
||||
{
|
||||
$this->validateNotNull('DefaultBranchOnly', $value);
|
||||
$this->validateInt('DefaultBranchOnly', $value);
|
||||
|
||||
if ($this->data['default_branch_only'] === $value) {
|
||||
return;
|
||||
}
|
||||
|
||||
$this->data['default_branch_only'] = $value;
|
||||
|
||||
$this->setModified('default_branch_only');
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of SshPrivateKey / ssh_private_key.
|
||||
*
|
||||
|
|
|
@ -54,6 +54,7 @@ class ProjectService
|
|||
$project->setType($type);
|
||||
$project->setReference($reference);
|
||||
$project->setAllowPublicStatus(0);
|
||||
$project->setDefaultBranchOnly(0);
|
||||
|
||||
// Handle extra project options:
|
||||
if (array_key_exists('ssh_private_key', $options)) {
|
||||
|
@ -80,6 +81,10 @@ class ProjectService
|
|||
$project->setBranch($options['branch']);
|
||||
}
|
||||
|
||||
if (array_key_exists('default_branch_only', $options)) {
|
||||
$project->setDefaultBranchOnly((int)$options['default_branch_only']);
|
||||
}
|
||||
|
||||
if (array_key_exists('group', $options)) {
|
||||
$project->setGroup($options['group']);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue