mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-22 13:30:55 +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:
parent
cd8a9fd61e
commit
4865dbdff1
8 changed files with 124 additions and 1 deletions
|
@ -1106,6 +1106,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterBuildEngine' => 'applications/harbormaster/engine/HarbormasterBuildEngine.php',
|
||||
'HarbormasterBuildFailureException' => 'applications/harbormaster/exception/HarbormasterBuildFailureException.php',
|
||||
'HarbormasterBuildGraph' => 'applications/harbormaster/engine/HarbormasterBuildGraph.php',
|
||||
'HarbormasterBuildInitiatorDatasource' => 'applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php',
|
||||
'HarbormasterBuildLintMessage' => 'applications/harbormaster/storage/build/HarbormasterBuildLintMessage.php',
|
||||
'HarbormasterBuildListController' => 'applications/harbormaster/controller/HarbormasterBuildListController.php',
|
||||
'HarbormasterBuildLog' => 'applications/harbormaster/storage/build/HarbormasterBuildLog.php',
|
||||
|
@ -1281,6 +1282,7 @@ phutil_register_library_map(array(
|
|||
'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
|
||||
'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
|
||||
'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php',
|
||||
'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php',
|
||||
'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php',
|
||||
'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php',
|
||||
'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php',
|
||||
|
@ -5651,6 +5653,7 @@ phutil_register_library_map(array(
|
|||
'HarbormasterBuildEngine' => 'Phobject',
|
||||
'HarbormasterBuildFailureException' => 'Exception',
|
||||
'HarbormasterBuildGraph' => 'AbstractDirectedGraph',
|
||||
'HarbormasterBuildInitiatorDatasource' => 'PhabricatorTypeaheadCompositeDatasource',
|
||||
'HarbormasterBuildLintMessage' => 'HarbormasterDAO',
|
||||
'HarbormasterBuildListController' => 'HarbormasterController',
|
||||
'HarbormasterBuildLog' => array(
|
||||
|
@ -5865,6 +5868,7 @@ phutil_register_library_map(array(
|
|||
'PhabricatorSubscribableInterface',
|
||||
),
|
||||
'HeraldRuleController' => 'HeraldController',
|
||||
'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'HeraldRuleListController' => 'HeraldController',
|
||||
'HeraldRulePHIDType' => 'PhabricatorPHIDType',
|
||||
|
|
|
@ -8,6 +8,7 @@ final class HarbormasterBuildQuery
|
|||
private $buildStatuses;
|
||||
private $buildablePHIDs;
|
||||
private $buildPlanPHIDs;
|
||||
private $initiatorPHIDs;
|
||||
private $needBuildTargets;
|
||||
|
||||
public function withIDs(array $ids) {
|
||||
|
@ -35,6 +36,11 @@ final class HarbormasterBuildQuery
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withInitiatorPHIDs(array $initiator_phids) {
|
||||
$this->initiatorPHIDs = $initiator_phids;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function needBuildTargets($need_targets) {
|
||||
$this->needBuildTargets = $need_targets;
|
||||
return $this;
|
||||
|
@ -167,6 +173,13 @@ final class HarbormasterBuildQuery
|
|||
$this->buildPlanPHIDs);
|
||||
}
|
||||
|
||||
if ($this->initiatorPHIDs !== null) {
|
||||
$where[] = qsprintf(
|
||||
$conn,
|
||||
'initiatorPHID IN (%Ls)',
|
||||
$this->initiatorPHIDs);
|
||||
}
|
||||
|
||||
return $where;
|
||||
}
|
||||
|
||||
|
|
|
@ -31,6 +31,14 @@ final class HarbormasterBuildSearchEngine
|
|||
->setDescription(
|
||||
pht('Search for builds with given statuses.'))
|
||||
->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']);
|
||||
}
|
||||
|
||||
if ($map['initiators']) {
|
||||
$query->withInitiatorPHIDs($map['initiators']);
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -54,6 +66,7 @@ final class HarbormasterBuildSearchEngine
|
|||
|
||||
protected function getBuiltinQueryNames() {
|
||||
return array(
|
||||
'initiated' => pht('My Builds'),
|
||||
'all' => pht('All Builds'),
|
||||
'waiting' => pht('Waiting'),
|
||||
'active' => pht('Active'),
|
||||
|
@ -66,6 +79,9 @@ final class HarbormasterBuildSearchEngine
|
|||
$query->setQueryKey($query_key);
|
||||
|
||||
switch ($query_key) {
|
||||
case 'initiated':
|
||||
$viewer = $this->requireViewer();
|
||||
return $query->setParameter('initiators', array($viewer->getPHID()));
|
||||
case 'all':
|
||||
return $query;
|
||||
case 'waiting':
|
||||
|
|
|
@ -59,6 +59,9 @@ final class HarbormasterBuild extends HarbormasterDAO
|
|||
'columns' => array('buildablePHID', 'planAutoKey'),
|
||||
'unique' => true,
|
||||
),
|
||||
'key_initiator' => array(
|
||||
'columns' => array('initiatorPHID'),
|
||||
),
|
||||
),
|
||||
) + parent::getConfiguration();
|
||||
}
|
||||
|
|
|
@ -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(),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
|
@ -8,6 +8,7 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
private $ruleTypes;
|
||||
private $contentTypes;
|
||||
private $disabled;
|
||||
private $datasourceQuery;
|
||||
private $triggerObjectPHIDs;
|
||||
|
||||
private $needConditionsAndActions;
|
||||
|
@ -49,6 +50,11 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
return $this;
|
||||
}
|
||||
|
||||
public function withDatasourceQuery($query) {
|
||||
$this->datasourceQuery = $query;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function withTriggerObjectPHIDs(array $phids) {
|
||||
$this->triggerObjectPHIDs = $phids;
|
||||
return $this;
|
||||
|
@ -219,6 +225,13 @@ final class HeraldRuleQuery extends PhabricatorCursorPagedPolicyAwareQuery {
|
|||
(int)$this->disabled);
|
||||
}
|
||||
|
||||
if ($this->datasourceQuery) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
'rule.name LIKE %>',
|
||||
$this->datasourceQuery);
|
||||
}
|
||||
|
||||
if ($this->triggerObjectPHIDs) {
|
||||
$where[] = qsprintf(
|
||||
$conn_r,
|
||||
|
|
|
@ -34,7 +34,7 @@ final class HeraldRule extends HeraldDAO
|
|||
return array(
|
||||
self::CONFIG_AUX_PHID => true,
|
||||
self::CONFIG_COLUMN_SCHEMA => array(
|
||||
'name' => 'text255',
|
||||
'name' => 'sort255',
|
||||
'contentType' => 'text255',
|
||||
'mustMatchAll' => 'bool',
|
||||
'configVersion' => 'uint32',
|
||||
|
@ -47,6 +47,9 @@ final class HeraldRule extends HeraldDAO
|
|||
'repetitionPolicy' => 'uint32?',
|
||||
),
|
||||
self::CONFIG_KEY_SCHEMA => array(
|
||||
'key_name' => array(
|
||||
'columns' => array('name(128)'),
|
||||
),
|
||||
'key_author' => array(
|
||||
'columns' => array('authorPHID'),
|
||||
),
|
||||
|
|
49
src/applications/herald/typeahead/HeraldRuleDatasource.php
Normal file
49
src/applications/herald/typeahead/HeraldRuleDatasource.php
Normal 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;
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue