diff --git a/resources/sql/autopatches/20150708.herald.2.sql b/resources/sql/autopatches/20150708.herald.2.sql new file mode 100644 index 0000000000..ad59936728 --- /dev/null +++ b/resources/sql/autopatches/20150708.herald.2.sql @@ -0,0 +1,48 @@ +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.type' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'ref-type'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.name' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'ref-name'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.change' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'ref-change'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.repository' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'repository'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.repository.projects' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'repository-projects'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.pusher' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'pusher'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'diffusion.pre.ref.pusher.projects' + WHERE r.contentType = 'HeraldPreCommitRefAdapter' + AND c.fieldName = 'pusher-projects'; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index ccf961c0ea..665235b544 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -616,6 +616,14 @@ phutil_register_library_map(array( 'DiffusionPathTreeController' => 'applications/diffusion/controller/DiffusionPathTreeController.php', 'DiffusionPathValidateController' => 'applications/diffusion/controller/DiffusionPathValidateController.php', 'DiffusionPhpExternalSymbolsSource' => 'applications/diffusion/symbol/DiffusionPhpExternalSymbolsSource.php', + 'DiffusionPreCommitRefChangeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php', + 'DiffusionPreCommitRefHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php', + 'DiffusionPreCommitRefNameHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php', + 'DiffusionPreCommitRefPusherHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php', + 'DiffusionPreCommitRefPusherProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php', + 'DiffusionPreCommitRefRepositoryHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php', + 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php', + 'DiffusionPreCommitRefTypeHeraldField' => 'applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php', 'DiffusionPushCapability' => 'applications/diffusion/capability/DiffusionPushCapability.php', 'DiffusionPushEventViewController' => 'applications/diffusion/controller/DiffusionPushEventViewController.php', 'DiffusionPushLogController' => 'applications/diffusion/controller/DiffusionPushLogController.php', @@ -4099,6 +4107,14 @@ phutil_register_library_map(array( 'DiffusionPathTreeController' => 'DiffusionController', 'DiffusionPathValidateController' => 'DiffusionController', 'DiffusionPhpExternalSymbolsSource' => 'DiffusionExternalSymbolsSource', + 'DiffusionPreCommitRefChangeHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefHeraldField' => 'HeraldField', + 'DiffusionPreCommitRefNameHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefPusherHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefPusherProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefRepositoryHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefRepositoryProjectsHeraldField' => 'DiffusionPreCommitRefHeraldField', + 'DiffusionPreCommitRefTypeHeraldField' => 'DiffusionPreCommitRefHeraldField', 'DiffusionPushCapability' => 'PhabricatorPolicyCapability', 'DiffusionPushEventViewController' => 'DiffusionPushLogController', 'DiffusionPushLogController' => 'DiffusionController', diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php new file mode 100644 index 0000000000..61942409ba --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php @@ -0,0 +1,43 @@ +getChangeFlags(); + } + + public function getHeraldFieldConditions() { + return array( + HeraldAdapter::CONDITION_HAS_BIT, + HeraldAdapter::CONDITION_NOT_BIT, + ); + } + + public function getHeraldFieldValueType($condition) { + return HeraldPreCommitRefAdapter::VALUE_REF_CHANGE; + } + + public function renderConditionValue( + PhabricatorUser $viewer, + $value) { + + $change_map = + PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); + foreach ($value as $index => $val) { + $name = idx($change_map, $val); + if ($name) { + $value[$index] = $name; + } + } + + return phutil_implode_html(', ', $value); + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php new file mode 100644 index 0000000000..516027e6e3 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php @@ -0,0 +1,17 @@ +getAdapter()->isPreCommitRefAdapter()) { + return false; + } + + return true; + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php new file mode 100644 index 0000000000..28711a1b3e --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php @@ -0,0 +1,24 @@ +getRefName(); + } + + protected function getHeraldFieldStandardConditions() { + return HeraldField::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php new file mode 100644 index 0000000000..b34cb6f236 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php @@ -0,0 +1,24 @@ +getAdapter()->getHookEngine()->getViewer()->getPHID(); + } + + protected function getHeraldFieldStandardConditions() { + return HeraldField::STANDARD_PHID; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_USER; + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php new file mode 100644 index 0000000000..c77d63a7d8 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php @@ -0,0 +1,31 @@ +getAdapter() + ->getHookEngine() + ->loadViewerProjectPHIDsForHerald(); + } + + protected function getHeraldFieldStandardConditions() { + return HeraldField::STANDARD_LIST; + } + + public function getHeraldFieldValueType($condition) { + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return HeraldAdapter::VALUE_NONE; + default: + return HeraldAdapter::VALUE_PROJECT; + } + } +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php new file mode 100644 index 0000000000..9b850c6847 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php @@ -0,0 +1,24 @@ +getAdapter()->getHookEngine()->getRepository()->getPHID(); + } + + protected function getHeraldFieldStandardConditions() { + return HeraldField::STANDARD_PHID; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_REPOSITORY; + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php new file mode 100644 index 0000000000..f91d1abd14 --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php @@ -0,0 +1,32 @@ +getAdapter()->getHookEngine()->getRepository()->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); + } + + protected function getHeraldFieldStandardConditions() { + return HeraldField::STANDARD_LIST; + } + + public function getHeraldFieldValueType($condition) { + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return HeraldAdapter::VALUE_NONE; + default: + return HeraldAdapter::VALUE_PROJECT; + } + } + +} diff --git a/src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php b/src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php new file mode 100644 index 0000000000..1daae7bc4b --- /dev/null +++ b/src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php @@ -0,0 +1,27 @@ +getRefType(); + } + + public function getHeraldFieldConditions() { + return array( + HeraldAdapter::CONDITION_IS, + HeraldAdapter::CONDITION_IS_NOT, + ); + } + + public function getHeraldFieldValueType($condition) { + return HeraldPreCommitRefAdapter::VALUE_REF_TYPE; + } + +} diff --git a/src/applications/diffusion/herald/HeraldPreCommitAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitAdapter.php index d7c967a93f..07f1f0d2c7 100644 --- a/src/applications/diffusion/herald/HeraldPreCommitAdapter.php +++ b/src/applications/diffusion/herald/HeraldPreCommitAdapter.php @@ -5,6 +5,8 @@ abstract class HeraldPreCommitAdapter extends HeraldAdapter { private $log; private $hookEngine; + abstract public function isPreCommitRefAdapter(); + public function setPushLog(PhabricatorRepositoryPushLog $log) { $this->log = $log; return $this; @@ -92,10 +94,6 @@ abstract class HeraldPreCommitAdapter extends HeraldAdapter { } } - public function getPHID() { - return $this->getObject()->getPHID(); - } - public function applyHeraldEffects(array $effects) { assert_instances_of($effects, 'HeraldEffect'); diff --git a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php index 5786cecda4..05674eb230 100644 --- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php +++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php @@ -21,6 +21,10 @@ final class HeraldPreCommitContentAdapter extends HeraldPreCommitAdapter { "Hook rules can block changes and send push summary mail."); } + public function isPreCommitRefAdapter() { + return false; + } + public function getFields() { return array_merge( array( diff --git a/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php b/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php index a21eb6b0b0..bdb19f2e53 100644 --- a/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php +++ b/src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php @@ -2,10 +2,6 @@ final class HeraldPreCommitRefAdapter extends HeraldPreCommitAdapter { - const FIELD_REF_TYPE = 'ref-type'; - const FIELD_REF_NAME = 'ref-name'; - const FIELD_REF_CHANGE = 'ref-change'; - const VALUE_REF_TYPE = 'value-ref-type'; const VALUE_REF_CHANGE = 'value-ref-change'; @@ -23,86 +19,12 @@ final class HeraldPreCommitRefAdapter extends HeraldPreCommitAdapter { "Hook rules can block changes and send push summary mail."); } - public function getFieldNameMap() { - return array( - self::FIELD_REF_TYPE => pht('Ref type'), - self::FIELD_REF_NAME => pht('Ref name'), - self::FIELD_REF_CHANGE => pht('Ref change type'), - ) + parent::getFieldNameMap(); - } - - public function getFields() { - return array_merge( - array( - self::FIELD_REF_TYPE, - self::FIELD_REF_NAME, - self::FIELD_REF_CHANGE, - self::FIELD_REPOSITORY, - self::FIELD_REPOSITORY_PROJECTS, - self::FIELD_PUSHER, - self::FIELD_PUSHER_PROJECTS, - ), - parent::getFields()); - } - - public function getConditionsForField($field) { - switch ($field) { - case self::FIELD_REF_NAME: - return array( - self::CONDITION_IS, - self::CONDITION_IS_NOT, - self::CONDITION_CONTAINS, - self::CONDITION_REGEXP, - ); - case self::FIELD_REF_TYPE: - return array( - self::CONDITION_IS, - self::CONDITION_IS_NOT, - ); - case self::FIELD_REF_CHANGE: - return array( - self::CONDITION_HAS_BIT, - self::CONDITION_NOT_BIT, - ); - } - return parent::getConditionsForField($field); - } - - public function getValueTypeForFieldAndCondition($field, $condition) { - switch ($field) { - case self::FIELD_REF_TYPE: - return self::VALUE_REF_TYPE; - case self::FIELD_REF_CHANGE: - return self::VALUE_REF_CHANGE; - } - - return parent::getValueTypeForFieldAndCondition($field, $condition); + public function isPreCommitRefAdapter() { + return true; } public function getHeraldName() { return pht('Push Log (Ref)'); } - public function getHeraldField($field) { - $log = $this->getObject(); - switch ($field) { - case self::FIELD_REF_TYPE: - return $log->getRefType(); - case self::FIELD_REF_NAME: - return $log->getRefName(); - case self::FIELD_REF_CHANGE: - return $log->getChangeFlags(); - case self::FIELD_REPOSITORY: - return $this->getHookEngine()->getRepository()->getPHID(); - case self::FIELD_REPOSITORY_PROJECTS: - return $this->getHookEngine()->getRepository()->getProjectPHIDs(); - case self::FIELD_PUSHER: - return $this->getHookEngine()->getViewer()->getPHID(); - case self::FIELD_PUSHER_PROJECTS: - return $this->getHookEngine()->loadViewerProjectPHIDsForHerald(); - } - - return parent::getHeraldField($field); - } - } diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index bafb22d367..d6f0aa007a 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -1213,26 +1213,13 @@ abstract class HeraldAdapter extends Phobject { $value = array($value); } - switch ($condition->getFieldName()) { - case HeraldPreCommitRefAdapter::FIELD_REF_CHANGE: - $change_map = - PhabricatorRepositoryPushLog::getHeraldChangeFlagConditionOptions(); - foreach ($value as $index => $val) { - $name = idx($change_map, $val); - if ($name) { - $value[$index] = $name; - } - } - break; - default: - foreach ($value as $index => $val) { - $handle = $handles->getHandleIfExists($val); - if ($handle) { - $value[$index] = $handle->renderLink(); - } - } - break; + foreach ($value as $index => $val) { + $handle = $handles->getHandleIfExists($val); + if ($handle) { + $value[$index] = $handle->renderLink(); + } } + $value = phutil_implode_html(', ', $value); return $value; }