1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-27 07:50:57 +01:00

Replace Harbormaster "BuildItem" with Lint/Unit messages

Summary:
Ref T8095.

Harbormaster has a `BuildItem` class, but it has no table and is unused. This was an earlier idea about representing lint/unit results and some other possible types of messages, but I think we want to be more specific than this.

Remove `BuildItem` and add `Lint` and `Unit` storage. These tables roughly parallel how we store lint/unit messages today, with some guesses about how where they'll go in the future.

Test Plan: Ran `bin/storage upgrade` and got a clean adjust out of it.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: hach-que, epriestley

Maniphest Tasks: T8095

Differential Revision: https://secure.phabricator.com/D13329
This commit is contained in:
epriestley 2015-06-21 09:00:00 -07:00
parent f9e838024c
commit 7ad4c9c056
8 changed files with 229 additions and 118 deletions

View file

@ -0,0 +1,14 @@
CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_buildlintmessage (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
buildTargetPHID VARBINARY(64) NOT NULL,
path LONGTEXT NOT NULL,
line INT UNSIGNED,
characterOffset INT UNSIGNED,
code VARCHAR(32) COLLATE {$COLLATE_TEXT} NOT NULL,
severity VARCHAR(32) COLLATE {$COLLATE_TEXT} NOT NULL,
name VARCHAR(255) COLLATE {$COLLATE_TEXT} NOT NULL,
properties LONGTEXT COLLATE {$COLLATE_TEXT} NOT NULL,
dateCreated INT UNSIGNED NOT NULL,
dateModified INT UNSIGNED NOT NULL,
KEY `key_target` (buildTargetPHID)
) ENGINE=INNODB, COLLATE {$COLLATE_TEXT};

View file

@ -0,0 +1,13 @@
CREATE TABLE {$NAMESPACE}_harbormaster.harbormaster_buildunitmessage (
id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
buildTargetPHID VARBINARY(64) NOT NULL,
engine VARCHAR(255) COLLATE {$COLLATE_TEXT} NOT NULL,
namespace VARCHAR(255) COLLATE {$COLLATE_TEXT} NOT NULL,
name VARCHAR(255) COLLATE {$COLLATE_TEXT} NOT NULL,
result VARCHAR(32) COLLATE {$COLLATE_TEXT} NOT NULL,
duration DOUBLE,
properties LONGTEXT COLLATE {$COLLATE_TEXT} NOT NULL,
dateCreated INT UNSIGNED NOT NULL,
dateModified INT UNSIGNED NOT NULL,
KEY `key_target` (buildTargetPHID)
) ENGINE=INNODB, COLLATE {$COLLATE_TEXT};

View file

@ -833,9 +833,7 @@ phutil_register_library_map(array(
'HarbormasterBuildEngine' => 'applications/harbormaster/engine/HarbormasterBuildEngine.php',
'HarbormasterBuildFailureException' => 'applications/harbormaster/exception/HarbormasterBuildFailureException.php',
'HarbormasterBuildGraph' => 'applications/harbormaster/engine/HarbormasterBuildGraph.php',
'HarbormasterBuildItem' => 'applications/harbormaster/storage/build/HarbormasterBuildItem.php',
'HarbormasterBuildItemPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildItemPHIDType.php',
'HarbormasterBuildItemQuery' => 'applications/harbormaster/query/HarbormasterBuildItemQuery.php',
'HarbormasterBuildLintMessage' => 'applications/harbormaster/storage/build/HarbormasterBuildLintMessage.php',
'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php',
'HarbormasterBuildLogPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildLogPHIDType.php',
'HarbormasterBuildLogQuery' => 'applications/harbormaster/query/HarbormasterBuildLogQuery.php',
@ -867,6 +865,7 @@ phutil_register_library_map(array(
'HarbormasterBuildTransaction' => 'applications/harbormaster/storage/HarbormasterBuildTransaction.php',
'HarbormasterBuildTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php',
'HarbormasterBuildTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildTransactionQuery.php',
'HarbormasterBuildUnitMessage' => 'applications/harbormaster/storage/build/HarbormasterBuildUnitMessage.php',
'HarbormasterBuildViewController' => 'applications/harbormaster/controller/HarbormasterBuildViewController.php',
'HarbormasterBuildWorker' => 'applications/harbormaster/worker/HarbormasterBuildWorker.php',
'HarbormasterBuildable' => 'applications/harbormaster/storage/HarbormasterBuildable.php',
@ -4253,9 +4252,7 @@ phutil_register_library_map(array(
'HarbormasterBuildEngine' => 'Phobject',
'HarbormasterBuildFailureException' => 'Exception',
'HarbormasterBuildGraph' => 'AbstractDirectedGraph',
'HarbormasterBuildItem' => 'HarbormasterDAO',
'HarbormasterBuildItemPHIDType' => 'PhabricatorPHIDType',
'HarbormasterBuildItemQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'HarbormasterBuildLintMessage' => 'HarbormasterDAO',
'HarbormasterBuildLog' => array(
'HarbormasterDAO',
'PhabricatorPolicyInterface',
@ -4309,6 +4306,7 @@ phutil_register_library_map(array(
'HarbormasterBuildTransaction' => 'PhabricatorApplicationTransaction',
'HarbormasterBuildTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
'HarbormasterBuildTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
'HarbormasterBuildUnitMessage' => 'HarbormasterDAO',
'HarbormasterBuildViewController' => 'HarbormasterController',
'HarbormasterBuildWorker' => 'HarbormasterWorker',
'HarbormasterBuildable' => array(

View file

@ -1,33 +0,0 @@
<?php
final class HarbormasterBuildItemPHIDType extends PhabricatorPHIDType {
const TYPECONST = 'HMBI';
public function getTypeName() {
return pht('Build Item');
}
public function newObject() {
return new HarbormasterBuildItem();
}
protected function buildQueryForObjects(
PhabricatorObjectQuery $query,
array $phids) {
return id(new HarbormasterBuildItemQuery())
->withPHIDs($phids);
}
public function loadHandles(
PhabricatorHandleQuery $query,
array $handles,
array $objects) {
foreach ($handles as $phid => $handle) {
$build_item = $objects[$phid];
}
}
}

View file

@ -1,60 +0,0 @@
<?php
final class HarbormasterBuildItemQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $phids;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withPHIDs(array $phids) {
$this->phids = $phids;
return $this;
}
protected function loadPage() {
$table = new HarbormasterBuildItem();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
return $table->loadAllFromArray($data);
}
protected function buildWhereClause(AphrontDatabaseConnection $conn_r) {
$where = array();
if ($this->ids) {
$where[] = qsprintf(
$conn_r,
'id IN (%Ld)',
$this->ids);
}
if ($this->phids) {
$where[] = qsprintf(
$conn_r,
'phid in (%Ls)',
$this->phids);
}
$where[] = $this->buildPagingClause($conn_r);
return $this->formatWhereClause($where);
}
public function getQueryApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
}

View file

@ -1,19 +0,0 @@
<?php
final class HarbormasterBuildItem extends HarbormasterDAO {
protected $name;
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
self::CONFIG_NO_TABLE => true,
) + parent::getConfiguration();
}
public function generatePHID() {
return PhabricatorPHID::generateNewPHID(
HarbormasterBuildItemPHIDType::TYPECONST);
}
}

View file

@ -0,0 +1,98 @@
<?php
final class HarbormasterBuildLintMessage
extends HarbormasterDAO {
protected $buildTargetPHID;
protected $path;
protected $line;
protected $characterOffset;
protected $code;
protected $severity;
protected $name;
protected $properties = array();
private $buildTarget = self::ATTACHABLE;
public static function initializeNewLintMessage(
HarbormasterBuildTarget $build_target) {
return id(new HarbormasterBuildLintMessage())
->setBuildTargetPHID($build_target->getPHID());
}
public static function newFromDictionary(
HarbormasterBuildTarget $build_target,
array $dict) {
$obj = self::initializeNewLintMessage($build_target);
$spec = array(
'path' => 'string',
'line' => 'optional int',
'char' => 'optional int',
'code' => 'string',
'severity' => 'string',
'name' => 'string',
'description' => 'optional string',
);
// We're just going to ignore extra keys for now, to make it easier to
// add stuff here later on.
$dict = array_select_keys($dict, array_keys($spec));
PhutilTypeSpec::checkMap($dict, $spec);
$obj->setPath($dict['path']);
$obj->setLine(idx($dict, 'line'));
$obj->setCharacterOffset(idx($dict, 'char'));
$obj->setCode($dict['code']);
$obj->setSeverity($dict['severity']);
$obj->setName($dict['name']);
$description = idx($dict, 'description');
if (strlen($description)) {
$obj->setProperty('description', $description);
}
return $obj;
}
protected function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'properties' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'path' => 'text',
'line' => 'uint32?',
'characterOffset' => 'uint32?',
'code' => 'text32',
'severity' => 'text32',
'name' => 'text255',
),
self::CONFIG_KEY_SCHEMA => array(
'key_target' => array(
'columns' => array('buildTargetPHID'),
),
),
) + parent::getConfiguration();
}
public function attachBuildTarget(HarbormasterBuildTarget $build_target) {
$this->buildTarget = $build_target;
return $this;
}
public function getBuildTarget() {
return $this->assertAttached($this->buildTarget);
}
public function getProperty($key, $default = null) {
return idx($this->properties, $key, $default);
}
public function setProperty($key, $value) {
$this->properties[$key] = $value;
return $this;
}
}

View file

@ -0,0 +1,100 @@
<?php
final class HarbormasterBuildUnitMessage
extends HarbormasterDAO {
protected $buildTargetPHID;
protected $engine;
protected $namespace;
protected $name;
protected $result;
protected $duration;
protected $properties = array();
private $buildTarget = self::ATTACHABLE;
public static function initializeNewUnitMessage(
HarbormasterBuildTarget $build_target) {
return id(new HarbormasterBuildLintMessage())
->setBuildTargetPHID($build_target->getPHID());
}
public static function newFromDictionary(
HarbormasterBuildTarget $build_target,
array $dict) {
$obj = self::initializeNewUnitMessage($build_target);
$spec = array(
'engine' => 'optional string',
'namespace' => 'optional string',
'name' => 'string',
'result' => 'string',
'duration' => 'optional float',
'path' => 'optional string',
'coverage' => 'optional string',
);
// We're just going to ignore extra keys for now, to make it easier to
// add stuff here later on.
$dict = array_select_keys($dict, array_keys($spec));
PhutilTypeSpec::checkMap($dict, $spec);
$obj->setEngine(idx($dict, 'engine', ''));
$obj->setNamespace(idx($dict, 'namespace', ''));
$obj->setName($dict['name']);
$obj->setResult($dict['result']);
$obj->setDuration(idx($dict, 'duration'));
$path = idx($dict, 'path');
if (strlen($path)) {
$obj->setProperty('path', $path);
}
$coverage = idx($dict, 'coverage');
if (strlen($coverage)) {
$obj->setProperty('coverage', $coverage);
}
return $obj;
}
protected function getConfiguration() {
return array(
self::CONFIG_SERIALIZATION => array(
'properties' => self::SERIALIZATION_JSON,
),
self::CONFIG_COLUMN_SCHEMA => array(
'engine' => 'text255',
'namespace' => 'text255',
'name' => 'text255',
'result' => 'text32',
'duration' => 'double?',
),
self::CONFIG_KEY_SCHEMA => array(
'key_target' => array(
'columns' => array('buildTargetPHID'),
),
),
) + parent::getConfiguration();
}
public function attachBuildTarget(HarbormasterBuildTarget $build_target) {
$this->buildTarget = $build_target;
return $this;
}
public function getBuildTarget() {
return $this->assertAttached($this->buildTarget);
}
public function getProperty($key, $default = null) {
return idx($this->properties, $key, $default);
}
public function setProperty($key, $value) {
$this->properties[$key] = $value;
return $this;
}
}