Add a checkbox to build only the default branch specified in the project.

This requires a new database field, and when a web hook is executed, it checks if it matches the requested branch.
This commit is contained in:
Pat Suwalski 2015-09-09 14:25:53 -04:00
parent 92ee90998a
commit 42a4cff524
5 changed files with 58 additions and 0 deletions

View file

@ -220,6 +220,7 @@ class ProjectController extends PHPCI\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),
);
$project = $this->projectService->createProject($title, $type, $reference, $options);
@ -284,6 +285,7 @@ class ProjectController extends PHPCI\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),
);
$project = $this->projectService->updateProject($project, $title, $type, $reference, $options);
@ -352,6 +354,12 @@ class ProjectController extends PHPCI\Controller
$field->setClass('form-control')->setContainerClass('form-group')->setValue('master');
$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\Checkbox::create('allow_public_status', Lang::get('allow_public_status'), false);
$field->setContainerClass('form-group');
$field->setCheckedValue(1);

View file

@ -362,6 +362,11 @@ class WebhookController extends \b8\Controller
);
}
// Check if this branch is to be built.
if ($project->getDefaultBranchOnly() && $branch != $project->getBranch()) {
return true;
}
// If not, create a new build job for it:
$build = $this->buildService->createBuild($project, $commitId, $branch, $committer, $commitMessage, $extra);
$build = BuildFactory::getBuild($build);

View file

@ -114,6 +114,7 @@ PHPCI',
'build_config' => 'PHPCI build config for this project
(if you cannot add a phpci.yml file in the project repository)',
'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',
'save_project' => 'Save Project',

View file

@ -44,6 +44,7 @@ class ProjectBase extends Model
'build_config' => null,
'ssh_public_key' => null,
'allow_public_status' => null,
'default_branch_only' => null,
'archived' => null,
);
@ -63,6 +64,7 @@ class ProjectBase extends Model
'build_config' => 'getBuildConfig',
'ssh_public_key' => 'getSshPublicKey',
'allow_public_status' => 'getAllowPublicStatus',
'default_branch_only' => 'getDefaultBranchOnly',
'archived' => 'getArchived',
// Foreign key getters:
@ -84,6 +86,7 @@ class ProjectBase extends Model
'build_config' => 'setBuildConfig',
'ssh_public_key' => 'setSshPublicKey',
'allow_public_status' => 'setAllowPublicStatus',
'default_branch_only' => 'setDefaultBranchOnly',
'archived' => 'setArchived',
// Foreign key setters:
@ -151,6 +154,10 @@ class ProjectBase extends Model
'type' => 'int',
'length' => 11,
),
'default_branch_only' => array(
'type' => 'int',
'length' => 11,
),
'archived' => array(
'type' => 'tinyint',
'length' => 4,
@ -305,6 +312,18 @@ class ProjectBase extends Model
return $rtn;
}
/**
* Get the value of DefaultBranchOnly / default_branch_only.
*
* @return int
*/
public function getDefaultBranchOnly()
{
$rtn = $this->data['default_branch_only'];
return $rtn;
}
/**
* Get the value of Archived / archived.
*
@ -527,6 +546,26 @@ class ProjectBase extends Model
$this->_setModified('allow_public_status');
}
/**
* 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 Archived / archived.
*

View file

@ -63,6 +63,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)) {
@ -89,6 +90,10 @@ class ProjectService
$project->setBranch($options['branch']);
}
if (array_key_exists('default_branch_only', $options)) {
$project->setDefaultBranchOnly((int)$options['default_branch_only']);
}
// Allow certain project types to set access information:
$this->processAccessInformation($project);