mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-11 15:21:03 +01:00
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
This commit is contained in:
parent
2319d2ede2
commit
b4796d2837
7 changed files with 186 additions and 0 deletions
|
@ -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',
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<?php
|
||||
|
||||
final class HeraldRuleAdapterField
|
||||
extends HeraldRuleField {
|
||||
|
||||
const FIELDCONST = 'adapter';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Content type');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->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');
|
||||
}
|
||||
|
||||
}
|
14
src/applications/herald/field/rule/HeraldRuleField.php
Normal file
14
src/applications/herald/field/rule/HeraldRuleField.php
Normal file
|
@ -0,0 +1,14 @@
|
|||
<?php
|
||||
|
||||
abstract class HeraldRuleField
|
||||
extends HeraldField {
|
||||
|
||||
public function getFieldGroupKey() {
|
||||
return ManiphestTaskHeraldFieldGroup::FIELDGROUPKEY;
|
||||
}
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof HeraldRule);
|
||||
}
|
||||
|
||||
}
|
16
src/applications/herald/field/rule/HeraldRuleFieldGroup.php
Normal file
16
src/applications/herald/field/rule/HeraldRuleFieldGroup.php
Normal file
|
@ -0,0 +1,16 @@
|
|||
<?php
|
||||
|
||||
final class HeraldRuleFieldGroup
|
||||
extends HeraldFieldGroup {
|
||||
|
||||
const FIELDGROUPKEY = 'herald.rule';
|
||||
|
||||
public function getGroupLabel() {
|
||||
return pht('Rule Fields');
|
||||
}
|
||||
|
||||
protected function getGroupOrder() {
|
||||
return 500;
|
||||
}
|
||||
|
||||
}
|
28
src/applications/herald/field/rule/HeraldRuleTypeField.php
Normal file
28
src/applications/herald/field/rule/HeraldRuleTypeField.php
Normal file
|
@ -0,0 +1,28 @@
|
|||
<?php
|
||||
|
||||
final class HeraldRuleTypeField
|
||||
extends HeraldRuleField {
|
||||
|
||||
const FIELDCONST = 'rule-type';
|
||||
|
||||
public function getHeraldFieldName() {
|
||||
return pht('Rule type');
|
||||
}
|
||||
|
||||
public function getHeraldFieldValue($object) {
|
||||
return $object->getRuleType();
|
||||
}
|
||||
|
||||
protected function getHeraldFieldStandardType() {
|
||||
return self::STANDARD_PHID;
|
||||
}
|
||||
|
||||
protected function getDatasource() {
|
||||
return new HeraldRuleTypeDatasource();
|
||||
}
|
||||
|
||||
protected function getDatasourceValueMap() {
|
||||
return HeraldRuleTypeConfig::getRuleTypeMap();
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
<?php
|
||||
|
||||
final class HeraldAdapterDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getBrowseTitle() {
|
||||
return pht('Browse Herald Adapters');
|
||||
}
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type an adapter name...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorHeraldApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$results = $this->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;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
<?php
|
||||
|
||||
final class HeraldRuleTypeDatasource
|
||||
extends PhabricatorTypeaheadDatasource {
|
||||
|
||||
public function getBrowseTitle() {
|
||||
return pht('Browse Rule Types');
|
||||
}
|
||||
|
||||
public function getPlaceholderText() {
|
||||
return pht('Type a rule type...');
|
||||
}
|
||||
|
||||
public function getDatasourceApplicationClass() {
|
||||
return 'PhabricatorHeraldApplication';
|
||||
}
|
||||
|
||||
public function loadResults() {
|
||||
$results = $this->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;
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue