mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 11:30:55 +01:00
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
This commit is contained in:
parent
00b98eca54
commit
f9134fc331
14 changed files with 300 additions and 103 deletions
48
resources/sql/autopatches/20150708.herald.2.sql
Normal file
48
resources/sql/autopatches/20150708.herald.2.sql
Normal file
|
@ -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';
|
|
@ -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',
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
|
@ -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');
|
||||
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue