From 00b98eca541cc5d8a34161b249a966d49f2d95f9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Wed, 8 Jul 2015 12:25:48 -0700 Subject: [PATCH] Modularize all DifferentialRevision fields Summary: Ref T8726. Make all the DifferentialRevision stuff modular. Test Plan: - Created a rule with all fields. - Ran upgrade. - Saw all fields preserved with new modular versions. - Used test console to run rule with all fields, verified field values as broadly sensible. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T8726 Differential Revision: https://secure.phabricator.com/D13598 --- .../sql/autopatches/20150708.herald.1.sql | 90 ++++++++++++++++ src/__phutil_library_map__.php | 30 +++++- ...entialRevisionAffectedFilesHeraldField.php | 30 ++++++ .../DifferentialRevisionAuthorHeraldField.php | 24 +++++ ...ntialRevisionAuthorProjectsHeraldField.php | 32 ++++++ ...rentialRevisionContentAddedHeraldField.php | 24 +++++ ...DifferentialRevisionContentHeraldField.php | 24 +++++ ...ntialRevisionContentRemovedHeraldField.php | 24 +++++ .../DifferentialRevisionHeraldField.php | 9 ++ ...DifferentialRevisionPackageHeraldField.php | 31 ++++++ ...rentialRevisionPackageOwnerHeraldField.php | 36 +++++++ ...ferentialRevisionRepositoryHeraldField.php | 36 +++++++ ...lRevisionRepositoryProjectsHeraldField.php | 37 +++++++ ...fferentialRevisionReviewersHeraldField.php | 30 ++++++ ...DifferentialRevisionSummaryHeraldField.php | 27 +++++ .../DifferentialRevisionTitleHeraldField.php | 24 +++++ .../HeraldDifferentialRevisionAdapter.php | 100 ++---------------- ...DiffusionCommitPackageOwnerHeraldField.php | 2 +- .../herald/adapter/HeraldAdapter.php | 5 - 19 files changed, 518 insertions(+), 97 deletions(-) create mode 100644 resources/sql/autopatches/20150708.herald.1.sql create mode 100644 src/applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionContentHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionPackageHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionSummaryHeraldField.php create mode 100644 src/applications/differential/herald/DifferentialRevisionTitleHeraldField.php rename src/applications/{herald/adapter => differential/herald}/HeraldDifferentialRevisionAdapter.php (68%) diff --git a/resources/sql/autopatches/20150708.herald.1.sql b/resources/sql/autopatches/20150708.herald.1.sql new file mode 100644 index 0000000000..678fad4690 --- /dev/null +++ b/resources/sql/autopatches/20150708.herald.1.sql @@ -0,0 +1,90 @@ +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.diff.affected' + WHERE r.contentType = 'differential' + AND c.fieldName = 'diff-file'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.author' + WHERE r.contentType = 'differential' + AND c.fieldName = 'author'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.author.projects' + WHERE r.contentType = 'differential' + AND c.fieldName = 'authorprojects'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.diff.new' + WHERE r.contentType = 'differential' + AND c.fieldName = 'diff-added-content'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.diff.content' + WHERE r.contentType = 'differential' + AND c.fieldName = 'diff-content'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.diff.old' + WHERE r.contentType = 'differential' + AND c.fieldName = 'diff-removed-content'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.package' + WHERE r.contentType = 'differential' + AND c.fieldName = 'affected-package'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.repository' + WHERE r.contentType = 'differential' + AND c.fieldName = 'repository'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.repository.projects' + WHERE r.contentType = 'differential' + 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 = 'differential.revision.reviewers' + WHERE r.contentType = 'differential' + AND c.fieldName = 'reviewers'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.summary' + WHERE r.contentType = 'differential' + AND c.fieldName = 'body'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.title' + WHERE r.contentType = 'differential' + AND c.fieldName = 'title'; + +UPDATE {$NAMESPACE}_herald.herald_condition c + JOIN {$NAMESPACE}_herald.herald_rule r + ON c.ruleID = r.id + SET c.fieldName = 'differential.revision.package.owners' + WHERE r.contentType = 'differential' + AND c.fieldName = 'affected-package-owner'; diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 19f5b18f45..ccf961c0ea 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -436,7 +436,13 @@ phutil_register_library_map(array( 'DifferentialReviewersField' => 'applications/differential/customfield/DifferentialReviewersField.php', 'DifferentialReviewersView' => 'applications/differential/view/DifferentialReviewersView.php', 'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php', + 'DifferentialRevisionAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php', + 'DifferentialRevisionAuthorHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorHeraldField.php', + 'DifferentialRevisionAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php', 'DifferentialRevisionCloseDetailsController' => 'applications/differential/controller/DifferentialRevisionCloseDetailsController.php', + 'DifferentialRevisionContentAddedHeraldField' => 'applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php', + 'DifferentialRevisionContentHeraldField' => 'applications/differential/herald/DifferentialRevisionContentHeraldField.php', + 'DifferentialRevisionContentRemovedHeraldField' => 'applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php', 'DifferentialRevisionControlSystem' => 'applications/differential/constants/DifferentialRevisionControlSystem.php', 'DifferentialRevisionDependedOnByRevisionEdgeType' => 'applications/differential/edge/DifferentialRevisionDependedOnByRevisionEdgeType.php', 'DifferentialRevisionDependsOnRevisionEdgeType' => 'applications/differential/edge/DifferentialRevisionDependsOnRevisionEdgeType.php', @@ -445,15 +451,23 @@ phutil_register_library_map(array( 'DifferentialRevisionHasCommitEdgeType' => 'applications/differential/edge/DifferentialRevisionHasCommitEdgeType.php', 'DifferentialRevisionHasReviewerEdgeType' => 'applications/differential/edge/DifferentialRevisionHasReviewerEdgeType.php', 'DifferentialRevisionHasTaskEdgeType' => 'applications/differential/edge/DifferentialRevisionHasTaskEdgeType.php', + 'DifferentialRevisionHeraldField' => 'applications/differential/herald/DifferentialRevisionHeraldField.php', 'DifferentialRevisionIDField' => 'applications/differential/customfield/DifferentialRevisionIDField.php', 'DifferentialRevisionLandController' => 'applications/differential/controller/DifferentialRevisionLandController.php', 'DifferentialRevisionListController' => 'applications/differential/controller/DifferentialRevisionListController.php', 'DifferentialRevisionListView' => 'applications/differential/view/DifferentialRevisionListView.php', 'DifferentialRevisionMailReceiver' => 'applications/differential/mail/DifferentialRevisionMailReceiver.php', 'DifferentialRevisionPHIDType' => 'applications/differential/phid/DifferentialRevisionPHIDType.php', + 'DifferentialRevisionPackageHeraldField' => 'applications/differential/herald/DifferentialRevisionPackageHeraldField.php', + 'DifferentialRevisionPackageOwnerHeraldField' => 'applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php', 'DifferentialRevisionQuery' => 'applications/differential/query/DifferentialRevisionQuery.php', + 'DifferentialRevisionRepositoryHeraldField' => 'applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php', + 'DifferentialRevisionRepositoryProjectsHeraldField' => 'applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php', + 'DifferentialRevisionReviewersHeraldField' => 'applications/differential/herald/DifferentialRevisionReviewersHeraldField.php', 'DifferentialRevisionSearchEngine' => 'applications/differential/query/DifferentialRevisionSearchEngine.php', 'DifferentialRevisionStatus' => 'applications/differential/constants/DifferentialRevisionStatus.php', + 'DifferentialRevisionSummaryHeraldField' => 'applications/differential/herald/DifferentialRevisionSummaryHeraldField.php', + 'DifferentialRevisionTitleHeraldField' => 'applications/differential/herald/DifferentialRevisionTitleHeraldField.php', 'DifferentialRevisionUpdateHistoryView' => 'applications/differential/view/DifferentialRevisionUpdateHistoryView.php', 'DifferentialRevisionViewController' => 'applications/differential/controller/DifferentialRevisionViewController.php', 'DifferentialSchemaSpec' => 'applications/differential/storage/DifferentialSchemaSpec.php', @@ -971,7 +985,7 @@ phutil_register_library_map(array( 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 'HeraldDifferentialAdapter' => 'applications/differential/herald/HeraldDifferentialAdapter.php', 'HeraldDifferentialDiffAdapter' => 'applications/differential/herald/HeraldDifferentialDiffAdapter.php', - 'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php', + 'HeraldDifferentialRevisionAdapter' => 'applications/differential/herald/HeraldDifferentialRevisionAdapter.php', 'HeraldDisableController' => 'applications/herald/controller/HeraldDisableController.php', 'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php', 'HeraldEngine' => 'applications/herald/engine/HeraldEngine.php', @@ -3905,7 +3919,13 @@ phutil_register_library_map(array( 'PhabricatorDestructibleInterface', 'PhabricatorProjectInterface', ), + 'DifferentialRevisionAffectedFilesHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionAuthorHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionAuthorProjectsHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionCloseDetailsController' => 'DifferentialController', + 'DifferentialRevisionContentAddedHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionContentHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionContentRemovedHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionControlSystem' => 'Phobject', 'DifferentialRevisionDependedOnByRevisionEdgeType' => 'PhabricatorEdgeType', 'DifferentialRevisionDependsOnRevisionEdgeType' => 'PhabricatorEdgeType', @@ -3914,15 +3934,23 @@ phutil_register_library_map(array( 'DifferentialRevisionHasCommitEdgeType' => 'PhabricatorEdgeType', 'DifferentialRevisionHasReviewerEdgeType' => 'PhabricatorEdgeType', 'DifferentialRevisionHasTaskEdgeType' => 'PhabricatorEdgeType', + 'DifferentialRevisionHeraldField' => 'HeraldField', 'DifferentialRevisionIDField' => 'DifferentialCustomField', 'DifferentialRevisionLandController' => 'DifferentialController', 'DifferentialRevisionListController' => 'DifferentialController', 'DifferentialRevisionListView' => 'AphrontView', 'DifferentialRevisionMailReceiver' => 'PhabricatorObjectMailReceiver', 'DifferentialRevisionPHIDType' => 'PhabricatorPHIDType', + 'DifferentialRevisionPackageHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionPackageOwnerHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', + 'DifferentialRevisionRepositoryHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionRepositoryProjectsHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionReviewersHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionSearchEngine' => 'PhabricatorApplicationSearchEngine', 'DifferentialRevisionStatus' => 'Phobject', + 'DifferentialRevisionSummaryHeraldField' => 'DifferentialRevisionHeraldField', + 'DifferentialRevisionTitleHeraldField' => 'DifferentialRevisionHeraldField', 'DifferentialRevisionUpdateHistoryView' => 'AphrontView', 'DifferentialRevisionViewController' => 'DifferentialController', 'DifferentialSchemaSpec' => 'PhabricatorConfigSchemaSpec', diff --git a/src/applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php new file mode 100644 index 0000000000..c39d852fc0 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php @@ -0,0 +1,30 @@ +getAdapter()->loadAffectedPaths(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT_LIST; + } + + public function getHeraldFieldValueType($condition) { + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return HeraldAdapter::VALUE_NONE; + default: + return HeraldAdapter::VALUE_TEXT; + } + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php new file mode 100644 index 0000000000..eb23c2a4ac --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionAuthorHeraldField.php @@ -0,0 +1,24 @@ +getAuthorPHID(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_PHID; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_USER; + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php b/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php new file mode 100644 index 0000000000..e50a8b3f85 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionAuthorProjectsHeraldField.php @@ -0,0 +1,32 @@ +getAuthorPHID(), + PhabricatorProjectMemberOfProjectEdgeType::EDGECONST); + } + + protected function getHeraldFieldStandardConditions() { + return self::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/differential/herald/DifferentialRevisionContentAddedHeraldField.php b/src/applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php new file mode 100644 index 0000000000..fcab6b66c4 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionContentAddedHeraldField.php @@ -0,0 +1,24 @@ +getAdapter()->loadAddedContentDictionary(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT_MAP; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionContentHeraldField.php b/src/applications/differential/herald/DifferentialRevisionContentHeraldField.php new file mode 100644 index 0000000000..42f84665a0 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionContentHeraldField.php @@ -0,0 +1,24 @@ +getAdapter()->loadContentDictionary(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT_MAP; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php b/src/applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php new file mode 100644 index 0000000000..73017c3925 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionContentRemovedHeraldField.php @@ -0,0 +1,24 @@ +getAdapter()->loadRemovedContentDictionary(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT_MAP; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionHeraldField.php b/src/applications/differential/herald/DifferentialRevisionHeraldField.php new file mode 100644 index 0000000000..845c933f5d --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionHeraldField.php @@ -0,0 +1,9 @@ +getAdapter()->loadAffectedPackages(); + return mpull($packages, 'getPHID'); + } + + protected function getHeraldFieldStandardConditions() { + return self::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_OWNERS_PACKAGE; + } + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php b/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php new file mode 100644 index 0000000000..89e2383e47 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionPackageOwnerHeraldField.php @@ -0,0 +1,36 @@ +getAdapter()->loadAffectedPackages(); + if (!$packages) { + return array(); + } + + $owners = PhabricatorOwnersOwner::loadAllForPackages($packages); + return mpull($owners, 'getUserPHID'); + } + + protected function getHeraldFieldStandardConditions() { + return self::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_USER_OR_PROJECT; + } + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php b/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php new file mode 100644 index 0000000000..00d0575ed1 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionRepositoryHeraldField.php @@ -0,0 +1,36 @@ +getAdapter()->loadRepository(); + + if (!$repository) { + return null; + } + + return $repository->getPHID(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_PHID_NULLABLE; + } + + public function getHeraldFieldValueType($condition) { + switch ($condition) { + case HeraldAdapter::CONDITION_EXISTS: + case HeraldAdapter::CONDITION_NOT_EXISTS: + return HeraldAdapter::VALUE_NONE; + default: + return HeraldAdapter::VALUE_REPOSITORY; + } + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php b/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php new file mode 100644 index 0000000000..948a7eb2ea --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionRepositoryProjectsHeraldField.php @@ -0,0 +1,37 @@ +getAdapter()->loadRepository(); + if (!$repository) { + return array(); + } + + return PhabricatorEdgeQuery::loadDestinationPHIDs( + $repository->getPHID(), + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); + } + + protected function getHeraldFieldStandardConditions() { + return self::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/differential/herald/DifferentialRevisionReviewersHeraldField.php b/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php new file mode 100644 index 0000000000..57ae95de03 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionReviewersHeraldField.php @@ -0,0 +1,30 @@ +getAdapter()->loadReviewers(); + } + + protected function getHeraldFieldStandardConditions() { + return self::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_USER_OR_PROJECT; + } + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionSummaryHeraldField.php b/src/applications/differential/herald/DifferentialRevisionSummaryHeraldField.php new file mode 100644 index 0000000000..e0d0cd7ccf --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionSummaryHeraldField.php @@ -0,0 +1,27 @@ +getSummary()."\n\n".$object->getTestPlan(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/differential/herald/DifferentialRevisionTitleHeraldField.php b/src/applications/differential/herald/DifferentialRevisionTitleHeraldField.php new file mode 100644 index 0000000000..5e7eecd515 --- /dev/null +++ b/src/applications/differential/herald/DifferentialRevisionTitleHeraldField.php @@ -0,0 +1,24 @@ +getTitle(); + } + + protected function getHeraldFieldStandardConditions() { + return self::STANDARD_TEXT; + } + + public function getHeraldFieldValueType($condition) { + return HeraldAdapter::VALUE_TEXT; + } + +} diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php similarity index 68% rename from src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php rename to src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php index 2c2e1f2e09..d3264860d6 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/differential/herald/HeraldDifferentialRevisionAdapter.php @@ -3,7 +3,6 @@ final class HeraldDifferentialRevisionAdapter extends HeraldDifferentialAdapter { - protected $diff; protected $revision; protected $explicitReviewers; @@ -32,10 +31,6 @@ final class HeraldDifferentialRevisionAdapter return $this->revision; } - public function getDiff() { - return $this->diff; - } - public function getAdapterContentType() { return 'differential'; } @@ -62,26 +57,6 @@ final class HeraldDifferentialRevisionAdapter } } - public function getFields() { - return array_merge( - array( - self::FIELD_TITLE, - self::FIELD_BODY, - self::FIELD_AUTHOR, - self::FIELD_AUTHOR_PROJECTS, - self::FIELD_REVIEWERS, - self::FIELD_REPOSITORY, - self::FIELD_REPOSITORY_PROJECTS, - self::FIELD_DIFF_FILE, - self::FIELD_DIFF_CONTENT, - self::FIELD_DIFF_ADDED_CONTENT, - self::FIELD_DIFF_REMOVED_CONTENT, - self::FIELD_AFFECTED_PACKAGE, - self::FIELD_AFFECTED_PACKAGE_OWNER, - ), - parent::getFields()); - } - public function getRepetitionOptions() { return array( HeraldRepetitionPolicyConfig::EVERY, @@ -103,7 +78,7 @@ final class HeraldDifferentialRevisionAdapter ->executeOne(); $object->revision = $revision; - $object->diff = $diff; + $object->setDiff($diff); return $object; } @@ -129,17 +104,13 @@ final class HeraldDifferentialRevisionAdapter return $this->buildPlans; } - public function getPHID() { - return $this->revision->getPHID(); - } - public function getHeraldName() { return $this->revision->getTitle(); } protected function loadChangesets() { if ($this->changesets === null) { - $this->changesets = $this->diff->loadChangesets(); + $this->changesets = $this->getDiff()->loadChangesets(); } return $this->changesets; } @@ -175,66 +146,15 @@ final class HeraldDifferentialRevisionAdapter return $this->affectedPackages; } - public function getHeraldField($field) { - switch ($field) { - case self::FIELD_TITLE: - return $this->revision->getTitle(); - break; - case self::FIELD_BODY: - return $this->revision->getSummary()."\n". - $this->revision->getTestPlan(); - break; - case self::FIELD_AUTHOR: - return $this->revision->getAuthorPHID(); - break; - case self::FIELD_AUTHOR_PROJECTS: - $author_phid = $this->revision->getAuthorPHID(); - if (!$author_phid) { - return array(); - } - - $projects = id(new PhabricatorProjectQuery()) - ->setViewer(PhabricatorUser::getOmnipotentUser()) - ->withMemberPHIDs(array($author_phid)) - ->execute(); - - return mpull($projects, 'getPHID'); - case self::FIELD_DIFF_FILE: - return $this->loadAffectedPaths(); - case self::FIELD_REVIEWERS: - if (isset($this->explicitReviewers)) { - return array_keys($this->explicitReviewers); - } else { - return $this->revision->getReviewers(); - } - case self::FIELD_REPOSITORY: - $repository = $this->loadRepository(); - if (!$repository) { - return null; - } - return $repository->getPHID(); - case self::FIELD_REPOSITORY_PROJECTS: - $repository = $this->loadRepository(); - if (!$repository) { - return array(); - } - return $repository->getProjectPHIDs(); - case self::FIELD_DIFF_CONTENT: - return $this->loadContentDictionary(); - case self::FIELD_DIFF_ADDED_CONTENT: - return $this->loadAddedContentDictionary(); - case self::FIELD_DIFF_REMOVED_CONTENT: - return $this->loadRemovedContentDictionary(); - case self::FIELD_AFFECTED_PACKAGE: - $packages = $this->loadAffectedPackages(); - return mpull($packages, 'getPHID'); - case self::FIELD_AFFECTED_PACKAGE_OWNER: - $packages = $this->loadAffectedPackages(); - return PhabricatorOwnersOwner::loadAffiliatedUserPHIDs( - mpull($packages, 'getID')); + public function loadReviewers() { + // TODO: This can probably go away as I believe it's just a performance + // optimization, just retaining it while modularizing fields to limit the + // scope of that change. + if (isset($this->explicitReviewers)) { + return array_keys($this->explicitReviewers); + } else { + return $this->revision->getReviewers(); } - - return parent::getHeraldField($field); } public function getActions($rule_type) { diff --git a/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php b/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php index 6646cd86b1..917afe58fe 100644 --- a/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php +++ b/src/applications/diffusion/herald/DiffusionCommitPackageOwnerHeraldField.php @@ -30,7 +30,7 @@ final class DiffusionCommitPackageOwnerHeraldField case HeraldAdapter::CONDITION_NOT_EXISTS: return HeraldAdapter::VALUE_NONE; default: - return HeraldAdapter::VALUE_USER; + return HeraldAdapter::VALUE_USER_OR_PROJECT; } } diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index da4281c215..bafb22d367 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -6,7 +6,6 @@ abstract class HeraldAdapter extends Phobject { const FIELD_BODY = 'body'; const FIELD_AUTHOR = 'author'; const FIELD_REVIEWER = 'reviewer'; - const FIELD_REVIEWERS = 'reviewers'; const FIELD_COMMITTER = 'committer'; const FIELD_DIFF_FILE = 'diff-file'; const FIELD_DIFF_CONTENT = 'diff-content'; @@ -367,7 +366,6 @@ abstract class HeraldAdapter extends Phobject { self::FIELD_AUTHOR => pht('Author'), self::FIELD_COMMITTER => pht('Committer'), self::FIELD_REVIEWER => pht('Reviewer'), - self::FIELD_REVIEWERS => pht('Reviewers'), self::FIELD_DIFF_FILE => pht('Any changed filename'), self::FIELD_DIFF_CONTENT => pht('Any changed file content'), self::FIELD_DIFF_ADDED_CONTENT => pht('Any added file content'), @@ -459,7 +457,6 @@ abstract class HeraldAdapter extends Phobject { self::CONDITION_EXISTS, self::CONDITION_NOT_EXISTS, ); - case self::FIELD_REVIEWERS: case self::FIELD_AUTHOR_PROJECTS: case self::FIELD_AFFECTED_PACKAGE: case self::FIELD_AFFECTED_PACKAGE_OWNER: @@ -922,8 +919,6 @@ abstract class HeraldAdapter extends Phobject { case self::FIELD_PUSHER_PROJECTS: case self::FIELD_REPOSITORY_PROJECTS: return self::VALUE_PROJECT; - case self::FIELD_REVIEWERS: - return self::VALUE_USER_OR_PROJECT; default: return self::VALUE_USER; }