Adding commit message to Build

This commit is contained in:
Dan Cryer 2014-02-25 16:43:06 +00:00
parent e888032bdf
commit eaec52b525
14 changed files with 189 additions and 46 deletions

View file

@ -37,7 +37,7 @@ class GenerateCommand extends Command
*/
protected function execute(InputInterface $input, OutputInterface $output)
{
$gen = new CodeGenerator(Database::getConnection(), 'PHPCI', PHPCI_DIR . '/PHPCI/', false);
$gen = new CodeGenerator(Database::getConnection(), ['default' => 'PHPCI'], ['default' => PHPCI_DIR], false);
$gen->generateModels();
$gen->generateStores();
}

View file

@ -54,6 +54,7 @@ class WebhookController extends \PHPCI\Controller
$build->setLog('');
$build->setCreated(new \DateTime());
$build->setBranch($commit['branch']);
$build->setCommitMessage($commit['message']);
$this->buildStore->save($build);
} catch (\Exception $ex) {
}
@ -137,6 +138,7 @@ class WebhookController extends \PHPCI\Controller
$build->setCreated(new \DateTime());
$build->setBranch(str_replace('refs/heads/', '', $payload['ref']));
$build->setCommitterEmail($commit['committer']['email']);
$build->setCommitMessage($commit['message']);
$build = $this->buildStore->save($build);
$build->sendStatusPostback();
}
@ -150,6 +152,8 @@ class WebhookController extends \PHPCI\Controller
$build->setCreated(new \DateTime());
$build->setBranch(str_replace('refs/tags/', 'Tag: ', $payload['ref']));
$build->setCommitterEmail($payload['pusher']['email']);
$build->setCommitMessage($payload['head_commit']['message']);
$build = $this->buildStore->save($build);
$build->sendStatusPostback();
}
@ -185,6 +189,7 @@ class WebhookController extends \PHPCI\Controller
$build->setCreated(new \DateTime());
$build->setBranch(str_replace('refs/heads/', '', $payload['ref']));
$build->setCommitterEmail($commit['author']['email']);
$build->setCommitMessage($commit['message']);
$build = $this->buildStore->save($build);
$build->sendStatusPostback();
}

7
PHPCI/Model.php Normal file
View file

@ -0,0 +1,7 @@
<?php
namespace PHPCI;
abstract class Model extends \b8\Model
{
}

View file

@ -6,7 +6,7 @@
namespace PHPCI\Model\Base;
use b8\Model;
use PHPCI\Model;
use b8\Store\Factory;
/**
@ -44,6 +44,7 @@ class BuildBase extends Model
'finished' => null,
'plugins' => null,
'committer_email' => null,
'commit_message' => null,
);
/**
@ -62,6 +63,7 @@ class BuildBase extends Model
'finished' => 'getFinished',
'plugins' => 'getPlugins',
'committer_email' => 'getCommitterEmail',
'commit_message' => 'getCommitMessage',
// Foreign key getters:
'Project' => 'getProject',
@ -83,6 +85,7 @@ class BuildBase extends Model
'finished' => 'setFinished',
'plugins' => 'setPlugins',
'committer_email' => 'setCommitterEmail',
'commit_message' => 'setCommitMessage',
// Foreign key setters:
'Project' => 'setProject',
@ -113,6 +116,7 @@ class BuildBase extends Model
'status' => array(
'type' => 'tinyint',
'length' => 4,
'default' => null,
),
'log' => array(
'type' => 'longtext',
@ -150,6 +154,11 @@ class BuildBase extends Model
'nullable' => true,
'default' => null,
),
'commit_message' => array(
'type' => 'text',
'nullable' => true,
'default' => null,
),
);
/**
@ -318,6 +327,18 @@ class BuildBase extends Model
return $rtn;
}
/**
* Get the value of CommitMessage / commit_message.
*
* @return string
*/
public function getCommitMessage()
{
$rtn = $this->data['commit_message'];
return $rtn;
}
/**
* Set the value of Id / id.
*
@ -524,6 +545,24 @@ class BuildBase extends Model
$this->_setModified('committer_email');
}
/**
* Set the value of CommitMessage / commit_message.
*
* @param $value string
*/
public function setCommitMessage($value)
{
$this->_validateString('CommitMessage', $value);
if ($this->data['commit_message'] === $value) {
return;
}
$this->data['commit_message'] = $value;
$this->_setModified('commit_message');
}
/**
* Get the Project model for this Build by Id.
*
@ -543,24 +582,13 @@ class BuildBase extends Model
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$rtn = Factory::getStore('Project')->getById($key);
$rtn = Factory::getStore('Project', 'PHPCI')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
return $rtn;
}
/**
* Get the value of the project's Title / title.
*
* @return string
*/
public function getProjectTitle()
{
return $this->getProject()->getTitle();
}
/**
* Set Project - Accepts an ID, an array representing a Project or a Project model.
*
@ -601,6 +629,33 @@ class BuildBase extends Model
*/
public function getBuildBuildMetas()
{
return Factory::getStore('BuildMeta')->getByBuildId($this->getId());
return Factory::getStore('BuildMeta', 'PHPCI')->getByBuildId($this->getId());
}
public static function getByPrimaryKey($value, $useConnection = 'read')
{
return Factory::getStore('Build', 'PHPCI')->getByPrimaryKey($value, $useConnection);
}
public static function getById($value, $useConnection = 'read')
{
return Factory::getStore('Build', 'PHPCI')->getById($value, $useConnection);
}
public static function getByProjectId($value, $limit = null, $useConnection = 'read')
{
return Factory::getStore('Build', 'PHPCI')->getByProjectId($value, $limit, $useConnection);
}
public static function getByStatus($value, $limit = null, $useConnection = 'read')
{
return Factory::getStore('Build', 'PHPCI')->getByStatus($value, $limit, $useConnection);
}
}

View file

@ -6,7 +6,7 @@
namespace PHPCI\Model\Base;
use b8\Model;
use PHPCI\Model;
use b8\Store\Factory;
/**
@ -95,6 +95,7 @@ class BuildMetaBase extends Model
'meta_key' => array(
'type' => 'varchar',
'length' => 255,
'default' => null,
),
'meta_value' => array(
'type' => 'text',
@ -299,7 +300,7 @@ class BuildMetaBase extends Model
$rtn = $this->cache->get($cacheKey, null);
if (empty($rtn)) {
$rtn = Factory::getStore('Build')->getById($key);
$rtn = Factory::getStore('Build', 'PHPCI')->getById($key);
$this->cache->set($cacheKey, $rtn);
}
@ -336,4 +337,26 @@ class BuildMetaBase extends Model
{
return $this->setBuildId($value->getId());
}
public static function getByPrimaryKey($value, $useConnection = 'read')
{
return Factory::getStore('BuildMeta', 'PHPCI')->getByPrimaryKey($value, $useConnection);
}
public static function getById($value, $useConnection = 'read')
{
return Factory::getStore('BuildMeta', 'PHPCI')->getById($value, $useConnection);
}
public static function getByBuildId($value, $limit = null, $useConnection = 'read')
{
return Factory::getStore('BuildMeta', 'PHPCI')->getByBuildId($value, $limit, $useConnection);
}
}

View file

@ -6,7 +6,7 @@
namespace PHPCI\Model\Base;
use b8\Model;
use PHPCI\Model;
use b8\Store\Factory;
/**
@ -91,10 +91,12 @@ class ProjectBase extends Model
'title' => array(
'type' => 'varchar',
'length' => 250,
'default' => null,
),
'reference' => array(
'type' => 'varchar',
'length' => 250,
'default' => null,
),
'git_key' => array(
'type' => 'text',
@ -215,21 +217,11 @@ class ProjectBase extends Model
/**
* Get the value of AccessInformation / access_information.
*
* @param string|null $key Key of desired information
*
* @return string
*/
public function getAccessInformation($key = null)
public function getAccessInformation()
{
$data = unserialize($this->data['access_information']);
if (is_null($key)) {
$rtn = $data;
} else if (isset($data[$key])) {
$rtn = $data[$key];
} else {
$rtn = null;
}
$rtn = $this->data['access_information'];
return $rtn;
}
@ -407,6 +399,28 @@ class ProjectBase extends Model
*/
public function getProjectBuilds()
{
return Factory::getStore('Build')->getByProjectId($this->getId());
return Factory::getStore('Build', 'PHPCI')->getByProjectId($this->getId());
}
public static function getByPrimaryKey($value, $useConnection = 'read')
{
return Factory::getStore('Project', 'PHPCI')->getByPrimaryKey($value, $useConnection);
}
public static function getById($value, $useConnection = 'read')
{
return Factory::getStore('Project', 'PHPCI')->getById($value, $useConnection);
}
public static function getByTitle($value, $limit = null, $useConnection = 'read')
{
return Factory::getStore('Project', 'PHPCI')->getByTitle($value, $limit, $useConnection);
}
}

View file

@ -6,7 +6,7 @@
namespace PHPCI\Model\Base;
use b8\Model;
use PHPCI\Model;
use b8\Store\Factory;
/**
@ -82,14 +82,17 @@ class UserBase extends Model
'email' => array(
'type' => 'varchar',
'length' => 250,
'default' => null,
),
'hash' => array(
'type' => 'varchar',
'length' => 250,
'default' => null,
),
'is_admin' => array(
'type' => 'tinyint',
'length' => 1,
'default' => null,
),
'name' => array(
'type' => 'varchar',
@ -270,4 +273,26 @@ class UserBase extends Model
$this->_setModified('name');
}
public static function getByPrimaryKey($value, $useConnection = 'read')
{
return Factory::getStore('User', 'PHPCI')->getByPrimaryKey($value, $useConnection);
}
public static function getById($value, $useConnection = 'read')
{
return Factory::getStore('User', 'PHPCI')->getById($value, $useConnection);
}
public static function getByEmail($value, $useConnection = 'read')
{
return Factory::getStore('User', 'PHPCI')->getByEmail($value, $useConnection);
}
}

7
PHPCI/Store.php Normal file
View file

@ -0,0 +1,7 @@
<?php
namespace PHPCI;
abstract class Store extends \b8\Store
{
}

View file

@ -8,7 +8,7 @@ namespace PHPCI\Store\Base;
use b8\Database;
use b8\Exception\HttpException;
use b8\Store;
use PHPCI\Store;
use PHPCI\Model\BuildMeta;
/**
@ -31,7 +31,7 @@ class BuildMetaStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM build_meta WHERE id = :id LIMIT 1';
$query = 'SELECT * FROM `build_meta` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':id', $value);
@ -58,7 +58,7 @@ class BuildMetaStoreBase extends Store
$count = null;
$query = 'SELECT * FROM build_meta WHERE build_id = :build_id' . $add;
$query = 'SELECT * FROM `build_meta` WHERE `build_id` = :build_id' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':build_id', $value);

View file

@ -8,7 +8,7 @@ namespace PHPCI\Store\Base;
use b8\Database;
use b8\Exception\HttpException;
use b8\Store;
use PHPCI\Store;
use PHPCI\Model\Build;
/**
@ -31,7 +31,7 @@ class BuildStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM build WHERE id = :id LIMIT 1';
$query = 'SELECT * FROM `build` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':id', $value);
@ -58,7 +58,7 @@ class BuildStoreBase extends Store
$count = null;
$query = 'SELECT * FROM build WHERE project_id = :project_id' . $add;
$query = 'SELECT * FROM `build` WHERE `project_id` = :project_id' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':project_id', $value);
@ -90,7 +90,7 @@ class BuildStoreBase extends Store
$count = null;
$query = 'SELECT * FROM build WHERE status = :status' . $add;
$query = 'SELECT * FROM `build` WHERE `status` = :status' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':status', $value);

View file

@ -8,7 +8,7 @@ namespace PHPCI\Store\Base;
use b8\Database;
use b8\Exception\HttpException;
use b8\Store;
use PHPCI\Store;
use PHPCI\Model\Project;
/**
@ -31,7 +31,7 @@ class ProjectStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM project WHERE id = :id LIMIT 1';
$query = 'SELECT * FROM `project` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':id', $value);
@ -58,7 +58,7 @@ class ProjectStoreBase extends Store
$count = null;
$query = 'SELECT * FROM project WHERE title = :title' . $add;
$query = 'SELECT * FROM `project` WHERE `title` = :title' . $add;
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':title', $value);

View file

@ -8,7 +8,7 @@ namespace PHPCI\Store\Base;
use b8\Database;
use b8\Exception\HttpException;
use b8\Store;
use PHPCI\Store;
use PHPCI\Model\User;
/**
@ -31,7 +31,7 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM user WHERE id = :id LIMIT 1';
$query = 'SELECT * FROM `user` WHERE `id` = :id LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':id', $value);
@ -50,7 +50,7 @@ class UserStoreBase extends Store
throw new HttpException('Value passed to ' . __FUNCTION__ . ' cannot be null.');
}
$query = 'SELECT * FROM user WHERE email = :email LIMIT 1';
$query = 'SELECT * FROM `user` WHERE `email` = :email LIMIT 1';
$stmt = Database::getConnection($useConnection)->prepare($query);
$stmt->bindValue(':email', $value);

View file

@ -1,6 +1,11 @@
<div id="title">
<h1 style="display: inline-block">Build #<?php print $build->getId(); ?></h1>
<h3 style="margin-left: 40px; display: inline-block">Branch: <?php print $build->getBranch(); ?> - <?php print $build->getCommitId() == 'Manual' ? 'Manual Build' : 'Commit: ' . $build->getCommitId(); ?></h3>
<div id="build-info">
<strong>Branch: </strong> <?php print $build->getBranch(); ?><br>
<strong>Commit ID: </strong> <?php print $build->getCommitId() == 'Manual' ? 'HEAD' : $build->getCommitId(); ?><br>
<strong>Commit Message: </strong> <?php print $build->getCommitMessage(); ?>
</div>
</div>
<div class="row">

View file

@ -7,6 +7,8 @@
<div style="font-family: arial, verdana, sans-serif; font-size: 15px">
<p>Your commit <strong><?= $build->getCommitId(); ?></strong> caused a failed build in project <strong><?= $project->getTitle(); ?></strong>.</p>
<p style="margin: 10px; background: #fafafa"><?= $build->getCommitMessage(); ?></p>
<p>Please review <a href="<?= $build->getCommitLink(); ?>">your commit</a> and the <a href="<?= PHPCI_URL . 'build/view/' . $build->getId(); ?>">build log</a>.</p>
</div>
</div>