diff --git a/PHPCI/Controller/BuildStatusController.php b/PHPCI/Controller/BuildStatusController.php
index bc5c188d..74a1fbad 100644
--- a/PHPCI/Controller/BuildStatusController.php
+++ b/PHPCI/Controller/BuildStatusController.php
@@ -10,7 +10,9 @@
namespace PHPCI\Controller;
use b8;
+use b8\Exception\HttpException\NotFoundException;
use b8\Store;
+use PHPCI\BuildFactory;
use PHPCI\Model\Project;
use PHPCI\Model\Build;
@@ -26,10 +28,13 @@ class BuildStatusController extends \PHPCI\Controller
* @var \PHPCI\Store\ProjectStore
*/
protected $projectStore;
+ protected $buildStore;
public function init()
{
- $this->projectStore = Store\Factory::getStore('Project');
+ $this->response->disableLayout();
+ $this->buildStore = Store\Factory::getStore('Build');
+ $this->projectStore = Store\Factory::getStore('Project');
}
/**
@@ -41,6 +46,10 @@ class BuildStatusController extends \PHPCI\Controller
$project = $this->projectStore->getById($projectId);
$status = 'ok';
+ if (!$project->getAllowPublicStatus()) {
+ die();
+ }
+
if (isset($project) && $project instanceof Project) {
$build = $project->getLatestBuild($branch, array(2,3));
@@ -52,4 +61,43 @@ class BuildStatusController extends \PHPCI\Controller
header('Content-Type: image/png');
die(file_get_contents(APPLICATION_PATH . 'public/assets/img/build-' . $status . '.png'));
}
+
+ public function view($projectId)
+ {
+ $project = $this->projectStore->getById($projectId);
+ if (!$project) {
+ throw new NotFoundException('Project with id: ' . $projectId . ' not found');
+ }
+
+ if (!$project->getAllowPublicStatus()) {
+ throw new NotFoundException('Project with id: ' . $projectId . ' not found');
+ }
+
+ $builds = $this->getLatestBuilds($projectId);
+
+ if (count($builds)) {
+ $this->view->latest = $builds[0];
+ }
+
+ $this->view->builds = $builds;
+ $this->view->project = $project;
+
+ return $this->view->render();
+ }
+
+ /**
+ * Render latest builds for project as HTML table.
+ */
+ protected function getLatestBuilds($projectId)
+ {
+ $criteria = array('project_id' => $projectId);
+ $order = array('id' => 'DESC');
+ $builds = $this->buildStore->getWhere($criteria, 10, 0, array(), $order);
+
+ foreach ($builds['items'] as &$build) {
+ $build = BuildFactory::getBuild($build);
+ }
+
+ return $builds['items'];
+ }
}
diff --git a/PHPCI/Controller/ProjectController.php b/PHPCI/Controller/ProjectController.php
index fa279eaf..850f6230 100644
--- a/PHPCI/Controller/ProjectController.php
+++ b/PHPCI/Controller/ProjectController.php
@@ -357,6 +357,14 @@ class ProjectController extends \PHPCI\Controller
$field->setRows(6);
$form->addField($field);
+ $field = new Form\Element\Checkbox('allow_public_status');
+ $field->setRequired(false);
+ $field->setLabel('Enable public status page and image for this project?');
+ $field->setContainerClass('form-group');
+ $field->setCheckedValue(1);
+ $field->setValue(1);
+ $form->addField($field);
+
$field = new Form\Element\Submit();
$field->setValue('Save Project');
$field->setContainerClass('form-group');
diff --git a/PHPCI/Model/Base/ProjectBase.php b/PHPCI/Model/Base/ProjectBase.php
index c58f2016..aeeee67c 100644
--- a/PHPCI/Model/Base/ProjectBase.php
+++ b/PHPCI/Model/Base/ProjectBase.php
@@ -43,6 +43,7 @@ class ProjectBase extends Model
'access_information' => null,
'last_commit' => null,
'build_config' => null,
+ 'allow_public_status' => null,
);
/**
@@ -60,6 +61,7 @@ class ProjectBase extends Model
'access_information' => 'getAccessInformation',
'last_commit' => 'getLastCommit',
'build_config' => 'getBuildConfig',
+ 'allow_public_status' => 'getAllowPublicStatus',
// Foreign key getters:
);
@@ -79,6 +81,7 @@ class ProjectBase extends Model
'access_information' => 'setAccessInformation',
'last_commit' => 'setLastCommit',
'build_config' => 'setBuildConfig',
+ 'allow_public_status' => 'setAllowPublicStatus',
// Foreign key setters:
);
@@ -142,6 +145,10 @@ class ProjectBase extends Model
'nullable' => true,
'default' => null,
),
+ 'allow_public_status' => array(
+ 'type' => 'tinyint',
+ 'length' => 4,
+ ),
);
/**
@@ -278,6 +285,18 @@ class ProjectBase extends Model
return $rtn;
}
+ /**
+ * Get the value of AllowPublicStatus / allow_public_status.
+ *
+ * @return int
+ */
+ public function getAllowPublicStatus()
+ {
+ $rtn = $this->data['allow_public_status'];
+
+ return $rtn;
+ }
+
/**
* Set the value of Id / id.
*
@@ -466,6 +485,26 @@ class ProjectBase extends Model
$this->_setModified('build_config');
}
+ /**
+ * Set the value of AllowPublicStatus / allow_public_status.
+ *
+ * Must not be null.
+ * @param $value int
+ */
+ public function setAllowPublicStatus($value)
+ {
+ $this->_validateNotNull('AllowPublicStatus', $value);
+ $this->_validateInt('AllowPublicStatus', $value);
+
+ if ($this->data['allow_public_status'] === $value) {
+ return;
+ }
+
+ $this->data['allow_public_status'] = $value;
+
+ $this->_setModified('allow_public_status');
+ }
+
/**
* Get Build models by ProjectId for this Project.
*
diff --git a/PHPCI/View/BuildStatus/view.phtml b/PHPCI/View/BuildStatus/view.phtml
new file mode 100644
index 00000000..ddc7936a
--- /dev/null
+++ b/PHPCI/View/BuildStatus/view.phtml
@@ -0,0 +1,193 @@
+
+
+
+ getTitle(); ?> - PHPCI
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

+
+
+
+
+
+
getTitle(); ?>
+
+
+ getStatus()) {
+ case 0:
+ $statusClass = 'info';
+ $statusText = 'Pending';
+ break;
+ case 1:
+ $statusClass = 'warning';
+ $statusText = 'Running';
+ break;
+ case 2:
+ $statusClass = 'success';
+ $statusText = 'Success';
+ break;
+ case 3:
+ $statusClass = 'danger';
+ $statusText = 'Failed';
+ break;
+ }
+
+ ?>
+
+
+
+
); ?>?d=mm)
+
+
+
+
+
+ getCommitMessage()): ?>
+
+ getCommitMessage(); ?>
+
+
+
+
Branch: getBranch(); ?>
+
Committer: getCommitterEmail(); ?>
+
+ getCommitId() != 'Manual'): ?>
+
Commit ID: getCommitId(); ?>
+
+
+
+
+
+
+
+
+
+
Builds
+
+
+
+ | ID |
+ Commit |
+ Branch |
+ Status |
+
+
+
+
+
+
+
+ | No builds yet. |
+
+
+
+
+
+ getStatus())
+ {
+ case 0:
+ $cls = 'active';
+ $subcls = 'info';
+ $status = 'Pending';
+
+ break;
+
+ case 1:
+ $cls = 'warning';
+ $subcls = 'warning';
+ $status = 'Running';
+ break;
+
+ case 2:
+ $cls = 'success';
+ $subcls = 'success';
+ $status = 'Success';
+ break;
+
+ case 3:
+ $cls = 'danger';
+ $subcls = 'danger';
+ $status = 'Failed';
+ break;
+ }
+ ?>
+
+ | #getId(), 6, '0', STR_PAD_LEFT); ?> |
+
+
+ getCommitId() !== 'Manual') {
+ print '';
+ }
+ print $build->getCommitId();
+ if ($build->getCommitId() !== 'Manual') {
+ print '';
+ }
+ ?>
+ |
+
+ getBranch(); ?> |
+
+ getPlugins(), true);
+
+ if ( !is_array($plugins) ) {
+ $plugins = array();
+ }
+ if ( 0 === count($plugins) ) {
+ ?>
+ $pluginstatus):
+ $subcls = $pluginstatus?'label label-success':'label label-danger';
+ ?> Build()->formatPluginName($plugin); ?>
+
+ |
+
+
+
+
+
+
+
+
+
+