@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator

Modularize all Herald pre-commit ref fields

Summary: Ref T8726. Just (pre-commit content) one more left.

Test Plan:
- Created a big rule with every field.
- Migrated it.
- Verified the rule was still the same.
- Pushed a bunch of changes and reviewed the transcripts.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8726

Differential Revision: https://secure.phabricator.com/D13600

+300 -103
+48
resources/sql/autopatches/20150708.herald.2.sql
··· 1 + UPDATE {$NAMESPACE}_herald.herald_condition c 2 + JOIN {$NAMESPACE}_herald.herald_rule r 3 + ON c.ruleID = r.id 4 + SET c.fieldName = 'diffusion.pre.ref.type' 5 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 6 + AND c.fieldName = 'ref-type'; 7 + 8 + UPDATE {$NAMESPACE}_herald.herald_condition c 9 + JOIN {$NAMESPACE}_herald.herald_rule r 10 + ON c.ruleID = r.id 11 + SET c.fieldName = 'diffusion.pre.ref.name' 12 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 13 + AND c.fieldName = 'ref-name'; 14 + 15 + UPDATE {$NAMESPACE}_herald.herald_condition c 16 + JOIN {$NAMESPACE}_herald.herald_rule r 17 + ON c.ruleID = r.id 18 + SET c.fieldName = 'diffusion.pre.ref.change' 19 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 20 + AND c.fieldName = 'ref-change'; 21 + 22 + UPDATE {$NAMESPACE}_herald.herald_condition c 23 + JOIN {$NAMESPACE}_herald.herald_rule r 24 + ON c.ruleID = r.id 25 + SET c.fieldName = 'diffusion.pre.ref.repository' 26 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 27 + AND c.fieldName = 'repository'; 28 + 29 + UPDATE {$NAMESPACE}_herald.herald_condition c 30 + JOIN {$NAMESPACE}_herald.herald_rule r 31 + ON c.ruleID = r.id 32 + SET c.fieldName = 'diffusion.pre.ref.repository.projects' 33 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 34 + AND c.fieldName = 'repository-projects'; 35 + 36 + UPDATE {$NAMESPACE}_herald.herald_condition c 37 + JOIN {$NAMESPACE}_herald.herald_rule r 38 + ON c.ruleID = r.id 39 + SET c.fieldName = 'diffusion.pre.ref.pusher' 40 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 41 + AND c.fieldName = 'pusher'; 42 + 43 + UPDATE {$NAMESPACE}_herald.herald_condition c 44 + JOIN {$NAMESPACE}_herald.herald_rule r 45 + ON c.ruleID = r.id 46 + SET c.fieldName = 'diffusion.pre.ref.pusher.projects' 47 + WHERE r.contentType = 'HeraldPreCommitRefAdapter' 48 + AND c.fieldName = 'pusher-projects';
+16
src/__phutil_library_map__.php
··· 616 616 'DiffusionPathTreeController' => 'applications/diffusion/controller/DiffusionPathTreeController.php', 617 617 'DiffusionPathValidateController' => 'applications/diffusion/controller/DiffusionPathValidateController.php', 618 618 'DiffusionPhpExternalSymbolsSource' => 'applications/diffusion/symbol/DiffusionPhpExternalSymbolsSource.php', 619 + 'DiffusionPreCommitRefChangeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php', 620 + 'DiffusionPreCommitRefHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php', 621 + 'DiffusionPreCommitRefNameHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php', 622 + 'DiffusionPreCommitRefPusherHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php', 623 + 'DiffusionPreCommitRefPusherProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php', 624 + 'DiffusionPreCommitRefRepositoryHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php', 625 + 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php', 626 + 'DiffusionPreCommitRefTypeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php', 619 627 'DiffusionPushCapability' => 'applications/diffusion/capability/DiffusionPushCapability.php', 620 628 'DiffusionPushEventViewController' => 'applications/diffusion/controller/DiffusionPushEventViewController.php', 621 629 'DiffusionPushLogController' => 'applications/diffusion/controller/DiffusionPushLogController.php', ··· 4099 4107 'DiffusionPathTreeController' => 'DiffusionController', 4100 4108 'DiffusionPathValidateController' => 'DiffusionController', 4101 4109 'DiffusionPhpExternalSymbolsSource' => 'DiffusionExternalSymbolsSource', 4110 + 'DiffusionPreCommitRefChangeHeraldField' => 'DiffusionPreCommitRefHeraldField', 4111 + 'DiffusionPreCommitRefHeraldField' => 'HeraldField', 4112 + 'DiffusionPreCommitRefNameHeraldField' => 'DiffusionPreCommitRefHeraldField', 4113 + 'DiffusionPreCommitRefPusherHeraldField' => 'DiffusionPreCommitRefHeraldField', 4114 + 'DiffusionPreCommitRefPusherProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField', 4115 + 'DiffusionPreCommitRefRepositoryHeraldField' => 'DiffusionPreCommitRefHeraldField', 4116 + 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField', 4117 + 'DiffusionPreCommitRefTypeHeraldField' => 'DiffusionPreCommitRefHeraldField', 4102 4118 'DiffusionPushCapability' => 'PhabricatorPolicyCapability', 4103 4119 'DiffusionPushEventViewController' => 'DiffusionPushLogController', 4104 4120 'DiffusionPushLogController' => 'DiffusionController',
+43
src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefChangeHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.change'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Ref change type'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getChangeFlags(); 14 + } 15 + 16 + public function getHeraldFieldConditions() { 17 + return array( 18 + HeraldAdapter::CONDITION_HAS_BIT, 19 + HeraldAdapter::CONDITION_NOT_BIT, 20 + ); 21 + } 22 + 23 + public function getHeraldFieldValueType($condition) { 24 + return HeraldPreCommitRefAdapter::VALUE_REF_CHANGE; 25 + } 26 + 27 + public function renderConditionValue( 28 + PhabricatorUser $viewer, 29 + $value) { 30 + 31 + $change_map = 32 + PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); 33 + foreach ($value as $index => $val) { 34 + $name = idx($change_map, $val); 35 + if ($name) { 36 + $value[$index] = $name; 37 + } 38 + } 39 + 40 + return phutil_implode_html(', ', $value); 41 + } 42 + 43 + }
+17
src/applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php
··· 1 + <?php 2 + 3 + abstract class DiffusionPreCommitRefHeraldField extends HeraldField { 4 + 5 + public function supportsObject($object) { 6 + if (!($object instanceof PhabricatorRepositoryPushLog)) { 7 + return false; 8 + } 9 + 10 + if (!$this->getAdapter()->isPreCommitRefAdapter()) { 11 + return false; 12 + } 13 + 14 + return true; 15 + } 16 + 17 + }
+24
src/applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefNameHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.name'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Ref name'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getRefName(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return HeraldField::STANDARD_TEXT; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TEXT; 22 + } 23 + 24 + }
+24
src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefPusherHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.pusher'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Pusher'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->getHookEngine()->getViewer()->getPHID(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return HeraldField::STANDARD_PHID; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_USER; 22 + } 23 + 24 + }
+31
src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefPusherProjectsHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.pusher.projects'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Pusher projects'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter() 14 + ->getHookEngine() 15 + ->loadViewerProjectPHIDsForHerald(); 16 + } 17 + 18 + protected function getHeraldFieldStandardConditions() { 19 + return HeraldField::STANDARD_LIST; 20 + } 21 + 22 + public function getHeraldFieldValueType($condition) { 23 + switch ($condition) { 24 + case HeraldAdapter::CONDITION_EXISTS: 25 + case HeraldAdapter::CONDITION_NOT_EXISTS: 26 + return HeraldAdapter::VALUE_NONE; 27 + default: 28 + return HeraldAdapter::VALUE_PROJECT; 29 + } 30 + } 31 + }
+24
src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefRepositoryHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.repository'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Repository'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->getHookEngine()->getRepository()->getPHID(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return HeraldField::STANDARD_PHID; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_REPOSITORY; 22 + } 23 + 24 + }
+32
src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefRepositoryProjectsHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.repository.projects'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Repository projects'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return PhabricatorEdgeQuery::loadDestinationPHIDs( 14 + $this->getAdapter()->getHookEngine()->getRepository()->getPHID(), 15 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 16 + } 17 + 18 + protected function getHeraldFieldStandardConditions() { 19 + return HeraldField::STANDARD_LIST; 20 + } 21 + 22 + public function getHeraldFieldValueType($condition) { 23 + switch ($condition) { 24 + case HeraldAdapter::CONDITION_EXISTS: 25 + case HeraldAdapter::CONDITION_NOT_EXISTS: 26 + return HeraldAdapter::VALUE_NONE; 27 + default: 28 + return HeraldAdapter::VALUE_PROJECT; 29 + } 30 + } 31 + 32 + }
+27
src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php
··· 1 + <?php 2 + 3 + final class DiffusionPreCommitRefTypeHeraldField 4 + extends DiffusionPreCommitRefHeraldField { 5 + 6 + const FIELDCONST = 'diffusion.pre.ref.type'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Ref type'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getRefType(); 14 + } 15 + 16 + public function getHeraldFieldConditions() { 17 + return array( 18 + HeraldAdapter::CONDITION_IS, 19 + HeraldAdapter::CONDITION_IS_NOT, 20 + ); 21 + } 22 + 23 + public function getHeraldFieldValueType($condition) { 24 + return HeraldPreCommitRefAdapter::VALUE_REF_TYPE; 25 + } 26 + 27 + }
+2 -4
src/applications/diffusion/herald/HeraldPreCommitAdapter.php
··· 5 5 private $log; 6 6 private $hookEngine; 7 7 8 + abstract public function isPreCommitRefAdapter(); 9 + 8 10 public function setPushLog(PhabricatorRepositoryPushLog $log) { 9 11 $this->log = $log; 10 12 return $this; ··· 90 92 ), 91 93 parent::getActions($rule_type)); 92 94 } 93 - } 94 - 95 - public function getPHID() { 96 - return $this->getObject()->getPHID(); 97 95 } 98 96 99 97 public function applyHeraldEffects(array $effects) {
+4
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 21 21 "Hook rules can block changes and send push summary mail."); 22 22 } 23 23 24 + public function isPreCommitRefAdapter() { 25 + return false; 26 + } 27 + 24 28 public function getFields() { 25 29 return array_merge( 26 30 array(
+2 -80
src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
··· 2 2 3 3 final class HeraldPreCommitRefAdapter extends HeraldPreCommitAdapter { 4 4 5 - const FIELD_REF_TYPE = 'ref-type'; 6 - const FIELD_REF_NAME = 'ref-name'; 7 - const FIELD_REF_CHANGE = 'ref-change'; 8 - 9 5 const VALUE_REF_TYPE = 'value-ref-type'; 10 6 const VALUE_REF_CHANGE = 'value-ref-change'; 11 7 ··· 23 19 "Hook rules can block changes and send push summary mail."); 24 20 } 25 21 26 - public function getFieldNameMap() { 27 - return array( 28 - self::FIELD_REF_TYPE => pht('Ref type'), 29 - self::FIELD_REF_NAME => pht('Ref name'), 30 - self::FIELD_REF_CHANGE => pht('Ref change type'), 31 - ) + parent::getFieldNameMap(); 32 - } 33 - 34 - public function getFields() { 35 - return array_merge( 36 - array( 37 - self::FIELD_REF_TYPE, 38 - self::FIELD_REF_NAME, 39 - self::FIELD_REF_CHANGE, 40 - self::FIELD_REPOSITORY, 41 - self::FIELD_REPOSITORY_PROJECTS, 42 - self::FIELD_PUSHER, 43 - self::FIELD_PUSHER_PROJECTS, 44 - ), 45 - parent::getFields()); 46 - } 47 - 48 - public function getConditionsForField($field) { 49 - switch ($field) { 50 - case self::FIELD_REF_NAME: 51 - return array( 52 - self::CONDITION_IS, 53 - self::CONDITION_IS_NOT, 54 - self::CONDITION_CONTAINS, 55 - self::CONDITION_REGEXP, 56 - ); 57 - case self::FIELD_REF_TYPE: 58 - return array( 59 - self::CONDITION_IS, 60 - self::CONDITION_IS_NOT, 61 - ); 62 - case self::FIELD_REF_CHANGE: 63 - return array( 64 - self::CONDITION_HAS_BIT, 65 - self::CONDITION_NOT_BIT, 66 - ); 67 - } 68 - return parent::getConditionsForField($field); 69 - } 70 - 71 - public function getValueTypeForFieldAndCondition($field, $condition) { 72 - switch ($field) { 73 - case self::FIELD_REF_TYPE: 74 - return self::VALUE_REF_TYPE; 75 - case self::FIELD_REF_CHANGE: 76 - return self::VALUE_REF_CHANGE; 77 - } 78 - 79 - return parent::getValueTypeForFieldAndCondition($field, $condition); 22 + public function isPreCommitRefAdapter() { 23 + return true; 80 24 } 81 25 82 26 public function getHeraldName() { 83 27 return pht('Push Log (Ref)'); 84 - } 85 - 86 - public function getHeraldField($field) { 87 - $log = $this->getObject(); 88 - switch ($field) { 89 - case self::FIELD_REF_TYPE: 90 - return $log->getRefType(); 91 - case self::FIELD_REF_NAME: 92 - return $log->getRefName(); 93 - case self::FIELD_REF_CHANGE: 94 - return $log->getChangeFlags(); 95 - case self::FIELD_REPOSITORY: 96 - return $this->getHookEngine()->getRepository()->getPHID(); 97 - case self::FIELD_REPOSITORY_PROJECTS: 98 - return $this->getHookEngine()->getRepository()->getProjectPHIDs(); 99 - case self::FIELD_PUSHER: 100 - return $this->getHookEngine()->getViewer()->getPHID(); 101 - case self::FIELD_PUSHER_PROJECTS: 102 - return $this->getHookEngine()->loadViewerProjectPHIDsForHerald(); 103 - } 104 - 105 - return parent::getHeraldField($field); 106 28 } 107 29 108 30 }
+6 -19
src/applications/herald/adapter/HeraldAdapter.php
··· 1213 1213 $value = array($value); 1214 1214 } 1215 1215 1216 - switch ($condition->getFieldName()) { 1217 - case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: 1218 - $change_map = 1219 - PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); 1220 - foreach ($value as $index => $val) { 1221 - $name = idx($change_map, $val); 1222 - if ($name) { 1223 - $value[$index] = $name; 1224 - } 1225 - } 1226 - break; 1227 - default: 1228 - foreach ($value as $index => $val) { 1229 - $handle = $handles->getHandleIfExists($val); 1230 - if ($handle) { 1231 - $value[$index] = $handle->renderLink(); 1232 - } 1233 - } 1234 - break; 1216 + foreach ($value as $index => $val) { 1217 + $handle = $handles->getHandleIfExists($val); 1218 + if ($handle) { 1219 + $value[$index] = $handle->renderLink(); 1220 + } 1235 1221 } 1222 + 1236 1223 $value = phutil_implode_html(', ', $value); 1237 1224 return $value; 1238 1225 }