1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

Search builds based on who kicked them off

Summary:
It's only natural for users to be interested their own builds. We are also building in support for other sources of builds, the only formally supported way to run a build right now is via Herald.

In our third party codebase, we designate an application as the "thing" that started builds which are scheduled and managed automatically by phabricator. I believe this is a common practice elsewhere in the codebase when you're at a loss for a real human identity and you need to apply some transactions.

Test Plan: Ran some builds manually and saw them show up under the list of things I've run.  Looking up builds based on those that had been started by a herald rule.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Differential Revision: https://secure.phabricator.com/D16353
This commit is contained in:
Mike Riley 2016-07-31 20:54:44 +00:00 committed by yelirekim
parent cd8a9fd61e
commit 4865dbdff1
8 changed files with 124 additions and 1 deletions

View file

@ -1106,6 +1106,7 @@ phutil_register_library_map(array(
'HarbormasterBuildEngine' => 'applications/harbormaster/engine/HarbormasterBuildEngine.php', 'HarbormasterBuildEngine' => 'applications/harbormaster/engine/HarbormasterBuildEngine.php',
'HarbormasterBuildFailureException' => 'applications/harbormaster/exception/HarbormasterBuildFailureException.php', 'HarbormasterBuildFailureException' => 'applications/harbormaster/exception/HarbormasterBuildFailureException.php',
'HarbormasterBuildGraph' => 'applications/harbormaster/engine/HarbormasterBuildGraph.php', 'HarbormasterBuildGraph' => 'applications/harbormaster/engine/HarbormasterBuildGraph.php',
'HarbormasterBuildInitiatorDatasource' => 'applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php',
'HarbormasterBuildLintMessage' => 'applications/harbormaster/storage/build/HarbormasterBuildLintMessage.php', 'HarbormasterBuildLintMessage' => 'applications/harbormaster/storage/build/HarbormasterBuildLintMessage.php',
'HarbormasterBuildListController' => 'applications/harbormaster/controller/HarbormasterBuildListController.php', 'HarbormasterBuildListController' => 'applications/harbormaster/controller/HarbormasterBuildListController.php',
'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php', 'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php',
@ -1281,6 +1282,7 @@ phutil_register_library_map(array(
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php', 'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
'HeraldRule' => 'applications/herald/storage/HeraldRule.php', 'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php',
'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php',
'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php', 'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php',
'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php',
'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php',
@ -5651,6 +5653,7 @@ phutil_register_library_map(array(
'HarbormasterBuildEngine' => 'Phobject', 'HarbormasterBuildEngine' => 'Phobject',
'HarbormasterBuildFailureException' => 'Exception', 'HarbormasterBuildFailureException' => 'Exception',
'HarbormasterBuildGraph' => 'AbstractDirectedGraph', 'HarbormasterBuildGraph' => 'AbstractDirectedGraph',
'HarbormasterBuildInitiatorDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
'HarbormasterBuildLintMessage' => 'HarbormasterDAO', 'HarbormasterBuildLintMessage' => 'HarbormasterDAO',
'HarbormasterBuildListController' => 'HarbormasterController', 'HarbormasterBuildListController' => 'HarbormasterController',
'HarbormasterBuildLog' => array( 'HarbormasterBuildLog' => array(
@ -5865,6 +5868,7 @@ phutil_register_library_map(array(
'PhabricatorSubscribableInterface', 'PhabricatorSubscribableInterface',
), ),
'HeraldRuleController' => 'HeraldController', 'HeraldRuleController' => 'HeraldController',
'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource',
'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor', 'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor',
'HeraldRuleListController' => 'HeraldController', 'HeraldRuleListController' => 'HeraldController',
'HeraldRulePHIDType' => 'PhabricatorPHIDType', 'HeraldRulePHIDType' => 'PhabricatorPHIDType',

View file

@ -8,6 +8,7 @@ final class HarbormasterBuildQuery
private $buildStatuses; private $buildStatuses;
private $buildablePHIDs; private $buildablePHIDs;
private $buildPlanPHIDs; private $buildPlanPHIDs;
private $initiatorPHIDs;
private $needBuildTargets; private $needBuildTargets;
public function withIDs(array $ids) { public function withIDs(array $ids) {
@ -35,6 +36,11 @@ final class HarbormasterBuildQuery
return $this; return $this;
} }
public function withInitiatorPHIDs(array $initiator_phids) {
$this->initiatorPHIDs = $initiator_phids;
return $this;
}
public function needBuildTargets($need_targets) { public function needBuildTargets($need_targets) {
$this->needBuildTargets = $need_targets; $this->needBuildTargets = $need_targets;
return $this; return $this;
@ -167,6 +173,13 @@ final class HarbormasterBuildQuery
$this->buildPlanPHIDs); $this->buildPlanPHIDs);
} }
if ($this->initiatorPHIDs !== null) {
$where[] = qsprintf(
$conn,
'initiatorPHID IN (%Ls)',
$this->initiatorPHIDs);
}
return $where; return $where;
} }

View file

@ -31,6 +31,14 @@ final class HarbormasterBuildSearchEngine
->setDescription( ->setDescription(
pht('Search for builds with given statuses.')) pht('Search for builds with given statuses.'))
->setDatasource(new HarbormasterBuildStatusDatasource()), ->setDatasource(new HarbormasterBuildStatusDatasource()),
id(new PhabricatorSearchDatasourceField())
->setLabel(pht('Initiators'))
->setKey('initiators')
->setAliases(array('initiator'))
->setDescription(
pht(
'Search for builds started by someone or something in particular.'))
->setDatasource(new HarbormasterBuildInitiatorDatasource()),
); );
} }
@ -45,6 +53,10 @@ final class HarbormasterBuildSearchEngine
$query->withBuildStatuses($map['statuses']); $query->withBuildStatuses($map['statuses']);
} }
if ($map['initiators']) {
$query->withInitiatorPHIDs($map['initiators']);
}
return $query; return $query;
} }
@ -54,6 +66,7 @@ final class HarbormasterBuildSearchEngine
protected function getBuiltinQueryNames() { protected function getBuiltinQueryNames() {
return array( return array(
'initiated' => pht('My Builds'),
'all' => pht('All Builds'), 'all' => pht('All Builds'),
'waiting' => pht('Waiting'), 'waiting' => pht('Waiting'),
'active' => pht('Active'), 'active' => pht('Active'),
@ -66,6 +79,9 @@ final class HarbormasterBuildSearchEngine
$query->setQueryKey($query_key); $query->setQueryKey($query_key);
switch ($query_key) { switch ($query_key) {
case 'initiated':
$viewer = $this->requireViewer();
return $query->setParameter('initiators', array($viewer->getPHID()));
case 'all': case 'all':
return $query; return $query;
case 'waiting': case 'waiting':

View file

@ -59,6 +59,9 @@ final class HarbormasterBuild extends HarbormasterDAO
'columns' => array('buildablePHID', 'planAutoKey'), 'columns' => array('buildablePHID', 'planAutoKey'),
'unique' => true, 'unique' => true,
), ),
'key_initiator' => array(
'columns' => array('initiatorPHID'),
),
), ),
) + parent::getConfiguration(); ) + parent::getConfiguration();
} }

View file

@ -0,0 +1,22 @@
<?php
final class HarbormasterBuildInitiatorDatasource
extends PhabricatorTypeaheadCompositeDatasource {
public function getBrowseTitle() {
return pht('Browse Build Initiators');
}
public function getPlaceholderText() {
return pht('Type the name of a user, application or Herald rule...');
}
public function getComponentDatasources() {
return array(
new PhabricatorApplicationDatasource(),
new PhabricatorPeopleUserFunctionDatasource(),
new HeraldRuleDatasource(),
);
}
}

View file

@ -8,6 +8,7 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
private $ruleTypes; private $ruleTypes;
private $contentTypes; private $contentTypes;
private $disabled; private $disabled;
private $datasourceQuery;
private $triggerObjectPHIDs; private $triggerObjectPHIDs;
private $needConditionsAndActions; private $needConditionsAndActions;
@ -49,6 +50,11 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
return $this; return $this;
} }
public function withDatasourceQuery($query) {
$this->datasourceQuery = $query;
return $this;
}
public function withTriggerObjectPHIDs(array $phids) { public function withTriggerObjectPHIDs(array $phids) {
$this->triggerObjectPHIDs = $phids; $this->triggerObjectPHIDs = $phids;
return $this; return $this;
@ -219,6 +225,13 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
(int)$this->disabled); (int)$this->disabled);
} }
if ($this->datasourceQuery) {
$where[] = qsprintf(
$conn_r,
'rule.name LIKE %>',
$this->datasourceQuery);
}
if ($this->triggerObjectPHIDs) { if ($this->triggerObjectPHIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,

View file

@ -34,7 +34,7 @@ final class HeraldRule extends HeraldDAO
return array( return array(
self::CONFIG_AUX_PHID => true, self::CONFIG_AUX_PHID => true,
self::CONFIG_COLUMN_SCHEMA => array( self::CONFIG_COLUMN_SCHEMA => array(
'name' => 'text255', 'name' => 'sort255',
'contentType' => 'text255', 'contentType' => 'text255',
'mustMatchAll' => 'bool', 'mustMatchAll' => 'bool',
'configVersion' => 'uint32', 'configVersion' => 'uint32',
@ -47,6 +47,9 @@ final class HeraldRule extends HeraldDAO
'repetitionPolicy' => 'uint32?', 'repetitionPolicy' => 'uint32?',
), ),
self::CONFIG_KEY_SCHEMA => array( self::CONFIG_KEY_SCHEMA => array(
'key_name' => array(
'columns' => array('name(128)'),
),
'key_author' => array( 'key_author' => array(
'columns' => array('authorPHID'), 'columns' => array('authorPHID'),
), ),

View file

@ -0,0 +1,49 @@
<?php
final class HeraldRuleDatasource
extends PhabricatorTypeaheadDatasource {
public function getPlaceholderText() {
return pht('Type a Herald rule name...');
}
public function getBrowseTitle() {
return pht('Browse Herald Rules');
}
public function getDatasourceApplicationClass() {
return 'PhabricatorHeraldApplication';
}
public function loadResults() {
$viewer = $this->getViewer();
$raw_query = $this->getRawQuery();
$rules = id(new HeraldRuleQuery())
->setViewer($viewer)
->withDatasourceQuery($raw_query)
->execute();
$handles = id(new PhabricatorHandleQuery())
->setViewer($viewer)
->withPHIDs(mpull($rules, 'getPHID'))
->execute();
$results = array();
foreach ($rules as $rule) {
$handle = $handles[$rule->getPHID()];
$result = id(new PhabricatorTypeaheadResult())
->setName($handle->getFullName())
->setPHID($handle->getPHID());
if ($rule->getIsDisabled()) {
$result->setClosed(pht('Archived'));
}
$results[] = $result;
}
return $results;
}
}