From 4865dbdff1998537fc6e8d167e42907d34701997 Mon Sep 17 00:00:00 2001 From: Mike Riley Date: Sun, 31 Jul 2016 20:54:44 +0000 Subject: [PATCH] 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 --- src/__phutil_library_map__.php | 4 ++ .../query/HarbormasterBuildQuery.php | 13 +++++ .../query/HarbormasterBuildSearchEngine.php | 16 ++++++ .../storage/build/HarbormasterBuild.php | 3 ++ .../HarbormasterBuildInitiatorDatasource.php | 22 +++++++++ .../herald/query/HeraldRuleQuery.php | 13 +++++ .../herald/storage/HeraldRule.php | 5 +- .../herald/typeahead/HeraldRuleDatasource.php | 49 +++++++++++++++++++ 8 files changed, 124 insertions(+), 1 deletion(-) create mode 100644 src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php create mode 100644 src/applications/herald/typeahead/HeraldRuleDatasource.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cb78038bbd..d4599a505c 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -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', diff --git a/src/applications/harbormaster/query/HarbormasterBuildQuery.php b/src/applications/harbormaster/query/HarbormasterBuildQuery.php index 1ee1ecb3a8..cf6db6115b 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildQuery.php @@ -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; } diff --git a/src/applications/harbormaster/query/HarbormasterBuildSearchEngine.php b/src/applications/harbormaster/query/HarbormasterBuildSearchEngine.php index 0b07ca7150..e1d4215019 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildSearchEngine.php +++ b/src/applications/harbormaster/query/HarbormasterBuildSearchEngine.php @@ -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': diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php index 759f9b9fe0..5037e7371e 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -59,6 +59,9 @@ final class HarbormasterBuild extends HarbormasterDAO 'columns' => array('buildablePHID', 'planAutoKey'), 'unique' => true, ), + 'key_initiator' => array( + 'columns' => array('initiatorPHID'), + ), ), ) + parent::getConfiguration(); } diff --git a/src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php b/src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php new file mode 100644 index 0000000000..c66073e25e --- /dev/null +++ b/src/applications/harbormaster/typeahead/HarbormasterBuildInitiatorDatasource.php @@ -0,0 +1,22 @@ +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, diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php index 9902e952ef..19f9b95507 100644 --- a/src/applications/herald/storage/HeraldRule.php +++ b/src/applications/herald/storage/HeraldRule.php @@ -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'), ), diff --git a/src/applications/herald/typeahead/HeraldRuleDatasource.php b/src/applications/herald/typeahead/HeraldRuleDatasource.php new file mode 100644 index 0000000000..c2db05c9ea --- /dev/null +++ b/src/applications/herald/typeahead/HeraldRuleDatasource.php @@ -0,0 +1,49 @@ +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; + } +}