diff --git a/PHPCI/Command/PollCommand.php b/PHPCI/Command/PollCommand.php index 76ea1dfb..61fe0909 100644 --- a/PHPCI/Command/PollCommand.php +++ b/PHPCI/Command/PollCommand.php @@ -87,7 +87,7 @@ class PollCommand extends Command $build->setProjectId($project->getId()); $build->setCommitId($last_commit); $build->setStatus(Build::STATUS_NEW); - $build->setBranch($project->getType() === 'hg' ? 'default' : 'master'); + $build->setBranch($project->getBranch()); $build->setCreated(new \DateTime()); if (!empty($last_committer)) { $build->setCommitterEmail($last_committer); diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php index 76f794c7..924f7a8c 100644 --- a/PHPCI/Controller/ProjectController.php +++ b/PHPCI/Controller/ProjectController.php @@ -85,7 +85,7 @@ class ProjectController extends \PHPCI\Controller $build->setProjectId($projectId); $build->setCommitId('Manual'); $build->setStatus(Build::STATUS_NEW); - $build->setBranch($project->getType() === 'hg' ? 'default' : 'master'); + $build->setBranch($project->getBranch()); $build->setCreated(new \DateTime()); $build->setCommitterEmail($_SESSION['user']->getEmail()); @@ -312,6 +312,14 @@ class ProjectController extends \PHPCI\Controller $field->setContainerClass('form-group'); $form->addField($field); + $field = new Form\Element\Text('branch'); + $field->setRequired(true); + $field->setValidator($this->getReferenceValidator($values)); + $field->setLabel('Branch name'); + $field->setClass('form-control'); + $field->setContainerClass('form-group'); + $form->addField($field); + $field = new Form\Element\Text('title'); $field->setRequired(true); $field->setLabel('Project Title'); diff --git a/PHPCI/Migrations/20140611170618_choose_branch.php b/PHPCI/Migrations/20140611170618_choose_branch.php new file mode 100644 index 00000000..5945c241 --- /dev/null +++ b/PHPCI/Migrations/20140611170618_choose_branch.php @@ -0,0 +1,40 @@ +table('project'); + $project->addColumn('branch', 'string', array( + 'after' => 'reference', + 'limit' => 250 + ))->save(); + } + + /** + * Migrate Down. + */ + public function down() + { + $project = $this->table('project'); + $project->removeColumn('branch')->save(); + } +} \ No newline at end of file diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php index 00bee23a..b56279b5 100644 --- a/PHPCI/Model/Base/ProjectBase.php +++ b/PHPCI/Model/Base/ProjectBase.php @@ -53,6 +53,7 @@ class ProjectBase extends Model 'id' => 'getId', 'title' => 'getTitle', 'reference' => 'getReference', + 'branch' => 'getBranch', 'ssh_private_key' => 'getSshPrivateKey', 'ssh_public_key' => 'getSshPublicKey', 'type' => 'getType', @@ -72,6 +73,7 @@ class ProjectBase extends Model 'id' => 'setId', 'title' => 'setTitle', 'reference' => 'setReference', + 'branch' => 'setBranch', 'ssh_private_key' => 'setSshPrivateKey', 'ssh_public_key' => 'setSshPublicKey', 'type' => 'setType', @@ -104,6 +106,11 @@ class ProjectBase extends Model 'length' => 250, 'default' => null, ), + 'branch' => array( + 'type' => 'varchar', + 'length' => 250, + 'default' => null, + ), 'ssh_private_key' => array( 'type' => 'text', 'nullable' => true, @@ -192,6 +199,20 @@ class ProjectBase extends Model return $rtn; } + /** + * Get the value of Branch / branch. + * + * @return string + */ + public function getBranch() + { + if (empty($this->data['branch'])) { + return $this->getType() === 'hg' ? 'default' : 'master'; + } else { + return $this->data['branch']; + } + } + /** * Get the value of SshPrivateKey / ssh_private_key. * @@ -336,6 +357,25 @@ class ProjectBase extends Model $this->_setModified('reference'); } + /** + * Set the value of Branch / branch. + * + * Must not be null. + * @param $value string + */ + public function setBranch($value) + { + $this->_validateString('Branch', $value); + + if ($this->data['branch'] === $value) { + return; + } + + $this->data['branch'] = $value; + + $this->_setModified('branch'); + } + /** * Set the value of SshPrivateKey / ssh_private_key. *