Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Project Property to Build Default Branch Only #1055

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions PHPCI/Controller/ProjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ public function add()
'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);
Expand Down Expand Up @@ -284,6 +285,7 @@ public function edit($projectId)
'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);
Expand Down Expand Up @@ -352,6 +354,12 @@ protected function projectForm($values, $type = 'add')
$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);
Expand Down
5 changes: 5 additions & 0 deletions PHPCI/Controller/WebhookController.php
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,11 @@ protected function createBuild(
);
}

// 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);
Expand Down
1 change: 1 addition & 0 deletions PHPCI/Languages/lang.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
'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',
Expand Down
30 changes: 30 additions & 0 deletions PHPCI/Migrations/20150901144444_add_default_branch_build.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

use Phinx\Migration\AbstractMigration;

class AddDefaultBranchBuild extends AbstractMigration
{
/**
* Migrate Up.
*/
public function up()
{
$dbAdapter = $this->getAdapter();

if ($dbAdapter instanceof \Phinx\Db\Adapter\PdoAdapter) {
$pdo = $dbAdapter->getConnection();
$pdo->exec('SET foreign_key_checks = 0');
}

$project = $this->table('project');

if (!$project->hasColumn('default_branch_only')) {
$table->addColumn('default_branch_only', 'integer');
}

if ($dbAdapter instanceof \Phinx\Db\Adapter\PdoAdapter) {
$pdo = $dbAdapter->getConnection();
$pdo->exec('SET foreign_key_checks = 1');
}
}
}
39 changes: 39 additions & 0 deletions PHPCI/Model/Base/ProjectBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand All @@ -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:
Expand All @@ -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:
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -305,6 +312,18 @@ public function getAllowPublicStatus()
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.
*
Expand Down Expand Up @@ -527,6 +546,26 @@ public function setAllowPublicStatus($value)
$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.
*
Expand Down
5 changes: 5 additions & 0 deletions PHPCI/Service/ProjectService.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public function updateProject(Project $project, $title, $type, $reference, $opti
$project->setType($type);
$project->setReference($reference);
$project->setAllowPublicStatus(0);
$project->setDefaultBranchOnly(0);

// Handle extra project options:
if (array_key_exists('ssh_private_key', $options)) {
Expand All @@ -89,6 +90,10 @@ public function updateProject(Project $project, $title, $type, $reference, $opti
$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);

Expand Down