From b4796d28374c604e9e3cb94877249afebe60b0a0 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 24 Apr 2018 15:31:18 -0700 Subject: [PATCH] Add "Content type" and "Rule type" fields to Herald rules for Herald rules Summary: Depends on D19400. Ref T13130. Currently, when you write Herald rules about other Herald rules, you can't pick a rule type or content type, so there's no way to get notified about edits to just global rules (which is the primary driving use case). Add a "Content type" field to let the rule match rules that affect revisions, tasks, commits, etc. Add a "Rule type" field to let the rule match global, personal, or object rules. Test Plan: - Wrote a global rule for other rules about global Herald rules: {F5540307} {F5540308} - Ran it against itself which matched: {F5540309} - Ran it against another rule (not a global rule about Herald rules), which did not match: {F5540311} - Also reviewed the fields in those transcripts in more detail to make sure they were extracting matching correctly. Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13130 Differential Revision: https://secure.phabricator.com/D19403 --- src/__phutil_library_map__.php | 12 +++++ .../field/rule/HeraldRuleAdapterField.php | 29 ++++++++++++ .../herald/field/rule/HeraldRuleField.php | 14 ++++++ .../field/rule/HeraldRuleFieldGroup.php | 16 +++++++ .../herald/field/rule/HeraldRuleTypeField.php | 28 ++++++++++++ .../typeahead/HeraldAdapterDatasource.php | 45 +++++++++++++++++++ .../typeahead/HeraldRuleTypeDatasource.php | 42 +++++++++++++++++ 7 files changed, 186 insertions(+) create mode 100644 src/applications/herald/field/rule/HeraldRuleAdapterField.php create mode 100644 src/applications/herald/field/rule/HeraldRuleField.php create mode 100644 src/applications/herald/field/rule/HeraldRuleFieldGroup.php create mode 100644 src/applications/herald/field/rule/HeraldRuleTypeField.php create mode 100644 src/applications/herald/typeahead/HeraldAdapterDatasource.php create mode 100644 src/applications/herald/typeahead/HeraldRuleTypeDatasource.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index cccd82e882..9de57b2530 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -1430,6 +1430,7 @@ phutil_register_library_map(array( 'HeraldActionGroup' => 'applications/herald/action/HeraldActionGroup.php', 'HeraldActionRecord' => 'applications/herald/storage/HeraldActionRecord.php', 'HeraldAdapter' => 'applications/herald/adapter/HeraldAdapter.php', + 'HeraldAdapterDatasource' => 'applications/herald/typeahead/HeraldAdapterDatasource.php', 'HeraldAlwaysField' => 'applications/herald/field/HeraldAlwaysField.php', 'HeraldAnotherRuleField' => 'applications/herald/field/HeraldAnotherRuleField.php', 'HeraldApplicationActionGroup' => 'applications/herald/action/HeraldApplicationActionGroup.php', @@ -1486,9 +1487,12 @@ phutil_register_library_map(array( 'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php', 'HeraldRule' => 'applications/herald/storage/HeraldRule.php', 'HeraldRuleAdapter' => 'applications/herald/adapter/HeraldRuleAdapter.php', + 'HeraldRuleAdapterField' => 'applications/herald/field/rule/HeraldRuleAdapterField.php', 'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php', 'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php', 'HeraldRuleEditor' => 'applications/herald/editor/HeraldRuleEditor.php', + 'HeraldRuleField' => 'applications/herald/field/rule/HeraldRuleField.php', + 'HeraldRuleFieldGroup' => 'applications/herald/field/rule/HeraldRuleFieldGroup.php', 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 'HeraldRuleQuery' => 'applications/herald/query/HeraldRuleQuery.php', @@ -1500,6 +1504,8 @@ phutil_register_library_map(array( 'HeraldRuleTransactionComment' => 'applications/herald/storage/HeraldRuleTransactionComment.php', 'HeraldRuleTranscript' => 'applications/herald/storage/transcript/HeraldRuleTranscript.php', 'HeraldRuleTypeConfig' => 'applications/herald/config/HeraldRuleTypeConfig.php', + 'HeraldRuleTypeDatasource' => 'applications/herald/typeahead/HeraldRuleTypeDatasource.php', + 'HeraldRuleTypeField' => 'applications/herald/field/rule/HeraldRuleTypeField.php', 'HeraldRuleViewController' => 'applications/herald/controller/HeraldRuleViewController.php', 'HeraldSchemaSpec' => 'applications/herald/storage/HeraldSchemaSpec.php', 'HeraldSelectFieldValue' => 'applications/herald/value/HeraldSelectFieldValue.php', @@ -6852,6 +6858,7 @@ phutil_register_library_map(array( 'HeraldActionGroup' => 'HeraldGroup', 'HeraldActionRecord' => 'HeraldDAO', 'HeraldAdapter' => 'Phobject', + 'HeraldAdapterDatasource' => 'PhabricatorTypeaheadDatasource', 'HeraldAlwaysField' => 'HeraldField', 'HeraldAnotherRuleField' => 'HeraldField', 'HeraldApplicationActionGroup' => 'HeraldActionGroup', @@ -6921,9 +6928,12 @@ phutil_register_library_map(array( 'PhabricatorSubscribableInterface', ), 'HeraldRuleAdapter' => 'HeraldAdapter', + 'HeraldRuleAdapterField' => 'HeraldRuleField', 'HeraldRuleController' => 'HeraldController', 'HeraldRuleDatasource' => 'PhabricatorTypeaheadDatasource', 'HeraldRuleEditor' => 'PhabricatorApplicationTransactionEditor', + 'HeraldRuleField' => 'HeraldField', + 'HeraldRuleFieldGroup' => 'HeraldFieldGroup', 'HeraldRuleListController' => 'HeraldController', 'HeraldRulePHIDType' => 'PhabricatorPHIDType', 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', @@ -6935,6 +6945,8 @@ phutil_register_library_map(array( 'HeraldRuleTransactionComment' => 'PhabricatorApplicationTransactionComment', 'HeraldRuleTranscript' => 'Phobject', 'HeraldRuleTypeConfig' => 'Phobject', + 'HeraldRuleTypeDatasource' => 'PhabricatorTypeaheadDatasource', + 'HeraldRuleTypeField' => 'HeraldRuleField', 'HeraldRuleViewController' => 'HeraldController', 'HeraldSchemaSpec' => 'PhabricatorConfigSchemaSpec', 'HeraldSelectFieldValue' => 'HeraldFieldValue', diff --git a/src/applications/herald/field/rule/HeraldRuleAdapterField.php b/src/applications/herald/field/rule/HeraldRuleAdapterField.php new file mode 100644 index 0000000000..bcb57f520f --- /dev/null +++ b/src/applications/herald/field/rule/HeraldRuleAdapterField.php @@ -0,0 +1,29 @@ +getContentType(); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID; + } + + protected function getDatasource() { + return new HeraldAdapterDatasource(); + } + + protected function getDatasourceValueMap() { + $adapters = HeraldAdapter::getAllAdapters(); + return mpull($adapters, 'getAdapterContentName', 'getAdapterContentType'); + } + +} diff --git a/src/applications/herald/field/rule/HeraldRuleField.php b/src/applications/herald/field/rule/HeraldRuleField.php new file mode 100644 index 0000000000..00ade268b3 --- /dev/null +++ b/src/applications/herald/field/rule/HeraldRuleField.php @@ -0,0 +1,14 @@ +getRuleType(); + } + + protected function getHeraldFieldStandardType() { + return self::STANDARD_PHID; + } + + protected function getDatasource() { + return new HeraldRuleTypeDatasource(); + } + + protected function getDatasourceValueMap() { + return HeraldRuleTypeConfig::getRuleTypeMap(); + } + +} diff --git a/src/applications/herald/typeahead/HeraldAdapterDatasource.php b/src/applications/herald/typeahead/HeraldAdapterDatasource.php new file mode 100644 index 0000000000..1fffd1bb6b --- /dev/null +++ b/src/applications/herald/typeahead/HeraldAdapterDatasource.php @@ -0,0 +1,45 @@ +buildResults(); + return $this->filterResultsAgainstTokens($results); + } + + protected function renderSpecialTokens(array $values) { + return $this->renderTokensFromResults($this->buildResults(), $values); + } + + private function buildResults() { + $results = array(); + + $adapters = HeraldAdapter::getAllAdapters(); + foreach ($adapters as $adapter) { + $value = $adapter->getAdapterContentType(); + $name = $adapter->getAdapterContentName(); + + $result = id(new PhabricatorTypeaheadResult()) + ->setPHID($value) + ->setName($name); + + $results[$value] = $result; + } + + return $results; + } + +} diff --git a/src/applications/herald/typeahead/HeraldRuleTypeDatasource.php b/src/applications/herald/typeahead/HeraldRuleTypeDatasource.php new file mode 100644 index 0000000000..8dfa7d0f6a --- /dev/null +++ b/src/applications/herald/typeahead/HeraldRuleTypeDatasource.php @@ -0,0 +1,42 @@ +buildResults(); + return $this->filterResultsAgainstTokens($results); + } + + protected function renderSpecialTokens(array $values) { + return $this->renderTokensFromResults($this->buildResults(), $values); + } + + private function buildResults() { + $results = array(); + + $type_map = HeraldRuleTypeConfig::getRuleTypeMap(); + foreach ($type_map as $type => $name) { + $result = id(new PhabricatorTypeaheadResult()) + ->setPHID($type) + ->setName($name); + + $results[$type] = $result; + } + + return $results; + } + +}