Page MenuHomePhabricator

D13600.id32880.diff
No OneTemporary

D13600.id32880.diff

diff --git a/resources/sql/autopatches/20150708.herald.2.sql b/resources/sql/autopatches/20150708.herald.2.sql
new file mode 100644
--- /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
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -616,6 +616,14 @@
'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 @@
'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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefChangeHeraldField.php
@@ -0,0 +1,43 @@
+<?php
+
+final class DiffusionPreCommitRefChangeHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.change';
+
+ public function getHeraldFieldName() {
+ return pht('Ref change type');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $object->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefHeraldField.php
@@ -0,0 +1,17 @@
+<?php
+
+abstract class DiffusionPreCommitRefHeraldField extends HeraldField {
+
+ public function supportsObject($object) {
+ if (!($object instanceof PhabricatorRepositoryPushLog)) {
+ return false;
+ }
+
+ if (!$this->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefNameHeraldField.php
@@ -0,0 +1,24 @@
+<?php
+
+final class DiffusionPreCommitRefNameHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.name';
+
+ public function getHeraldFieldName() {
+ return pht('Ref name');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $object->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherHeraldField.php
@@ -0,0 +1,24 @@
+<?php
+
+final class DiffusionPreCommitRefPusherHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.pusher';
+
+ public function getHeraldFieldName() {
+ return pht('Pusher');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $this->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefPusherProjectsHeraldField.php
@@ -0,0 +1,31 @@
+<?php
+
+final class DiffusionPreCommitRefPusherProjectsHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.pusher.projects';
+
+ public function getHeraldFieldName() {
+ return pht('Pusher projects');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $this->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryHeraldField.php
@@ -0,0 +1,24 @@
+<?php
+
+final class DiffusionPreCommitRefRepositoryHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.repository';
+
+ public function getHeraldFieldName() {
+ return pht('Repository');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $this->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefRepositoryProjectsHeraldField.php
@@ -0,0 +1,32 @@
+<?php
+
+final class DiffusionPreCommitRefRepositoryProjectsHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.repository.projects';
+
+ public function getHeraldFieldName() {
+ return pht('Repository projects');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return PhabricatorEdgeQuery::loadDestinationPHIDs(
+ $this->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
--- /dev/null
+++ b/src/applications/diffusion/herald/DiffusionPreCommitRefTypeHeraldField.php
@@ -0,0 +1,27 @@
+<?php
+
+final class DiffusionPreCommitRefTypeHeraldField
+ extends DiffusionPreCommitRefHeraldField {
+
+ const FIELDCONST = 'diffusion.pre.ref.type';
+
+ public function getHeraldFieldName() {
+ return pht('Ref type');
+ }
+
+ public function getHeraldFieldValue($object) {
+ return $object->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
--- a/src/applications/diffusion/herald/HeraldPreCommitAdapter.php
+++ b/src/applications/diffusion/herald/HeraldPreCommitAdapter.php
@@ -5,6 +5,8 @@
private $log;
private $hookEngine;
+ abstract public function isPreCommitRefAdapter();
+
public function setPushLog(PhabricatorRepositoryPushLog $log) {
$this->log = $log;
return $this;
@@ -92,10 +94,6 @@
}
}
- 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
--- a/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
+++ b/src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
@@ -21,6 +21,10 @@
"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
--- 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 @@
"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
--- a/src/applications/herald/adapter/HeraldAdapter.php
+++ b/src/applications/herald/adapter/HeraldAdapter.php
@@ -1213,26 +1213,13 @@
$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;
}

File Metadata

Mime Type
text/plain
Expires
Tue, Nov 5, 2:21 PM (1 w, 5 d ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6738884
Default Alt Text
D13600.id32880.diff (18 KB)

Event Timeline