@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

Modernize all Herald DifferentialDiff fields

Summary: Ref T8726. This deals with all the Differential diff fields, same deal as previous changes.

Test Plan:
- Wrote a rule with every field.
- Migrated it.
- Saw the same rule working.
- Rigged the hell out of transcripts (diffs normally do not generate transcripts, because the only action is "block" and they don't exist yet when Herald runs).
- Verified that all fields looked sensible in the transcript.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T8726

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

+425 -174
+55
resources/sql/autopatches/20150707.herald.1.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 = 'differential.diff.affected' 5 + WHERE r.contentType = 'differential.diff' 6 + AND c.fieldName = 'diff-file'; 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 = 'differential.diff.author' 12 + WHERE r.contentType = 'differential.diff' 13 + AND c.fieldName = 'author'; 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 = 'differential.diff.author.projects' 19 + WHERE r.contentType = 'differential.diff' 20 + AND c.fieldName = 'authorprojects'; 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 = 'differential.diff.new' 26 + WHERE r.contentType = 'differential.diff' 27 + AND c.fieldName = 'diff-added-content'; 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 = 'differential.diff.content' 33 + WHERE r.contentType = 'differential.diff' 34 + AND c.fieldName = 'diff-content'; 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 = 'differential.diff.old' 40 + WHERE r.contentType = 'differential.diff' 41 + AND c.fieldName = 'diff-removed-content'; 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 = 'differential.diff.repository' 47 + WHERE r.contentType = 'differential.diff' 48 + AND c.fieldName = 'repository'; 49 + 50 + UPDATE {$NAMESPACE}_herald.herald_condition c 51 + JOIN {$NAMESPACE}_herald.herald_rule r 52 + ON c.ruleID = r.id 53 + SET c.fieldName = 'differential.diff.repository.projects' 54 + WHERE r.contentType = 'differential.diff' 55 + AND c.fieldName = 'repository-projects';
+20 -2
src/__phutil_library_map__.php
··· 350 350 'DifferentialDependenciesField' => 'applications/differential/customfield/DifferentialDependenciesField.php', 351 351 'DifferentialDependsOnField' => 'applications/differential/customfield/DifferentialDependsOnField.php', 352 352 'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php', 353 + 'DifferentialDiffAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialDiffAffectedFilesHeraldField.php', 354 + 'DifferentialDiffAuthorHeraldField' => 'applications/differential/herald/DifferentialDiffAuthorHeraldField.php', 355 + 'DifferentialDiffAuthorProjectsHeraldField' => 'applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php', 356 + 'DifferentialDiffContentAddedHeraldField' => 'applications/differential/herald/DifferentialDiffContentAddedHeraldField.php', 357 + 'DifferentialDiffContentHeraldField' => 'applications/differential/herald/DifferentialDiffContentHeraldField.php', 358 + 'DifferentialDiffContentRemovedHeraldField' => 'applications/differential/herald/DifferentialDiffContentRemovedHeraldField.php', 353 359 'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php', 354 360 'DifferentialDiffEditor' => 'applications/differential/editor/DifferentialDiffEditor.php', 361 + 'DifferentialDiffHeraldField' => 'applications/differential/herald/DifferentialDiffHeraldField.php', 355 362 'DifferentialDiffInlineCommentQuery' => 'applications/differential/query/DifferentialDiffInlineCommentQuery.php', 356 363 'DifferentialDiffPHIDType' => 'applications/differential/phid/DifferentialDiffPHIDType.php', 357 364 'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php', 358 365 'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php', 366 + 'DifferentialDiffRepositoryHeraldField' => 'applications/differential/herald/DifferentialDiffRepositoryHeraldField.php', 367 + 'DifferentialDiffRepositoryProjectsHeraldField' => 'applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php', 359 368 'DifferentialDiffTableOfContentsView' => 'applications/differential/view/DifferentialDiffTableOfContentsView.php', 360 369 'DifferentialDiffTestCase' => 'applications/differential/storage/__tests__/DifferentialDiffTestCase.php', 361 370 'DifferentialDiffTransaction' => 'applications/differential/storage/DifferentialDiffTransaction.php', ··· 960 969 'HeraldController' => 'applications/herald/controller/HeraldController.php', 961 970 'HeraldCustomAction' => 'applications/herald/extension/HeraldCustomAction.php', 962 971 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 963 - 'HeraldDifferentialAdapter' => 'applications/herald/adapter/HeraldDifferentialAdapter.php', 964 - 'HeraldDifferentialDiffAdapter' => 'applications/herald/adapter/HeraldDifferentialDiffAdapter.php', 972 + 'HeraldDifferentialAdapter' => 'applications/differential/herald/HeraldDifferentialAdapter.php', 973 + 'HeraldDifferentialDiffAdapter' => 'applications/differential/herald/HeraldDifferentialDiffAdapter.php', 965 974 'HeraldDifferentialRevisionAdapter' => 'applications/herald/adapter/HeraldDifferentialRevisionAdapter.php', 966 975 'HeraldDisableController' => 'applications/herald/controller/HeraldDisableController.php', 967 976 'HeraldEffect' => 'applications/herald/engine/HeraldEffect.php', ··· 3790 3799 'PhabricatorApplicationTransactionInterface', 3791 3800 'PhabricatorDestructibleInterface', 3792 3801 ), 3802 + 'DifferentialDiffAffectedFilesHeraldField' => 'DifferentialDiffHeraldField', 3803 + 'DifferentialDiffAuthorHeraldField' => 'DifferentialDiffHeraldField', 3804 + 'DifferentialDiffAuthorProjectsHeraldField' => 'DifferentialDiffHeraldField', 3805 + 'DifferentialDiffContentAddedHeraldField' => 'DifferentialDiffHeraldField', 3806 + 'DifferentialDiffContentHeraldField' => 'DifferentialDiffHeraldField', 3807 + 'DifferentialDiffContentRemovedHeraldField' => 'DifferentialDiffHeraldField', 3793 3808 'DifferentialDiffCreateController' => 'DifferentialController', 3794 3809 'DifferentialDiffEditor' => 'PhabricatorApplicationTransactionEditor', 3810 + 'DifferentialDiffHeraldField' => 'HeraldField', 3795 3811 'DifferentialDiffInlineCommentQuery' => 'PhabricatorDiffInlineCommentQuery', 3796 3812 'DifferentialDiffPHIDType' => 'PhabricatorPHIDType', 3797 3813 'DifferentialDiffProperty' => 'DifferentialDAO', 3798 3814 'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3815 + 'DifferentialDiffRepositoryHeraldField' => 'DifferentialDiffHeraldField', 3816 + 'DifferentialDiffRepositoryProjectsHeraldField' => 'DifferentialDiffHeraldField', 3799 3817 'DifferentialDiffTableOfContentsView' => 'AphrontView', 3800 3818 'DifferentialDiffTestCase' => 'PhutilTestCase', 3801 3819 'DifferentialDiffTransaction' => 'PhabricatorApplicationTransaction',
+30
src/applications/differential/herald/DifferentialDiffAffectedFilesHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffAffectedFilesHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.affected'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Affected files'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->loadAffectedPaths(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_TEXT_LIST; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + switch ($condition) { 22 + case HeraldAdapter::CONDITION_EXISTS: 23 + case HeraldAdapter::CONDITION_NOT_EXISTS: 24 + return HeraldAdapter::VALUE_NONE; 25 + default: 26 + return HeraldAdapter::VALUE_TEXT; 27 + } 28 + } 29 + 30 + }
+24
src/applications/differential/herald/DifferentialDiffAuthorHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffAuthorHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.author'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Author'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $object->getAuthorPHID(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_PHID; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_USER; 22 + } 23 + 24 + }
+32
src/applications/differential/herald/DifferentialDiffAuthorProjectsHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffAuthorProjectsHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.author.projects'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht("Author's projects"); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return PhabricatorEdgeQuery::loadDestinationPHIDs( 14 + $object->getAuthorPHID(), 15 + PhabricatorProjectMemberOfProjectEdgeType::EDGECONST); 16 + } 17 + 18 + protected function getHeraldFieldStandardConditions() { 19 + return self::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 + }
+24
src/applications/differential/herald/DifferentialDiffContentAddedHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffContentAddedHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.new'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Added file content'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->loadAddedContentDictionary(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_TEXT_MAP; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TEXT; 22 + } 23 + 24 + }
+24
src/applications/differential/herald/DifferentialDiffContentHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffContentHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.content'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Changed file content'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->loadContentDictionary(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_TEXT_MAP; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TEXT; 22 + } 23 + 24 + }
+24
src/applications/differential/herald/DifferentialDiffContentRemovedHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffContentRemovedHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.old'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Removed file content'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + return $this->getAdapter()->loadRemovedContentDictionary(); 14 + } 15 + 16 + protected function getHeraldFieldStandardConditions() { 17 + return self::STANDARD_TEXT_MAP; 18 + } 19 + 20 + public function getHeraldFieldValueType($condition) { 21 + return HeraldAdapter::VALUE_TEXT; 22 + } 23 + 24 + }
+9
src/applications/differential/herald/DifferentialDiffHeraldField.php
··· 1 + <?php 2 + 3 + abstract class DifferentialDiffHeraldField extends HeraldField { 4 + 5 + public function supportsObject($object) { 6 + return ($object instanceof DifferentialDiff); 7 + } 8 + 9 + }
+36
src/applications/differential/herald/DifferentialDiffRepositoryHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffRepositoryHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.repository'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Repository'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + $repository = $this->getAdapter()->loadRepository(); 14 + 15 + if (!$repository) { 16 + return null; 17 + } 18 + 19 + return $repository->getPHID(); 20 + } 21 + 22 + protected function getHeraldFieldStandardConditions() { 23 + return self::STANDARD_PHID_NULLABLE; 24 + } 25 + 26 + public function getHeraldFieldValueType($condition) { 27 + switch ($condition) { 28 + case HeraldAdapter::CONDITION_EXISTS: 29 + case HeraldAdapter::CONDITION_NOT_EXISTS: 30 + return HeraldAdapter::VALUE_NONE; 31 + default: 32 + return HeraldAdapter::VALUE_REPOSITORY; 33 + } 34 + } 35 + 36 + }
+37
src/applications/differential/herald/DifferentialDiffRepositoryProjectsHeraldField.php
··· 1 + <?php 2 + 3 + final class DifferentialDiffRepositoryProjectsHeraldField 4 + extends DifferentialDiffHeraldField { 5 + 6 + const FIELDCONST = 'differential.diff.repository.projects'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Repository projects'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + $repository = $this->getAdapter()->loadRepository(); 14 + if (!$repository) { 15 + return array(); 16 + } 17 + 18 + return PhabricatorEdgeQuery::loadDestinationPHIDs( 19 + $repository->getPHID(), 20 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 21 + } 22 + 23 + protected function getHeraldFieldStandardConditions() { 24 + return self::STANDARD_LIST; 25 + } 26 + 27 + public function getHeraldFieldValueType($condition) { 28 + switch ($condition) { 29 + case HeraldAdapter::CONDITION_EXISTS: 30 + case HeraldAdapter::CONDITION_NOT_EXISTS: 31 + return HeraldAdapter::VALUE_NONE; 32 + default: 33 + return HeraldAdapter::VALUE_PROJECT; 34 + } 35 + } 36 + 37 + }
+106
src/applications/differential/herald/HeraldDifferentialDiffAdapter.php
··· 1 + <?php 2 + 3 + final class HeraldDifferentialDiffAdapter extends HeraldDifferentialAdapter { 4 + 5 + public function getAdapterApplicationClass() { 6 + return 'PhabricatorDifferentialApplication'; 7 + } 8 + 9 + protected function initializeNewAdapter() { 10 + $this->setDiff(new DifferentialDiff()); 11 + } 12 + 13 + public function isSingleEventAdapter() { 14 + return true; 15 + } 16 + 17 + protected function loadChangesets() { 18 + return $this->loadChangesetsWithHunks(); 19 + } 20 + 21 + protected function loadChangesetsWithHunks() { 22 + return $this->getDiff()->getChangesets(); 23 + } 24 + 25 + public function getObject() { 26 + return $this->getDiff(); 27 + } 28 + 29 + public function getAdapterContentType() { 30 + return 'differential.diff'; 31 + } 32 + 33 + public function getAdapterContentName() { 34 + return pht('Differential Diffs'); 35 + } 36 + 37 + public function getAdapterContentDescription() { 38 + return pht( 39 + "React to new diffs being uploaded, before writes occur.\n". 40 + "These rules can reject diffs before they are written to permanent ". 41 + "storage, to prevent users from accidentally uploading private keys or ". 42 + "other sensitive information."); 43 + } 44 + 45 + public function supportsRuleType($rule_type) { 46 + switch ($rule_type) { 47 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 48 + return true; 49 + case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 50 + case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 51 + default: 52 + return false; 53 + } 54 + } 55 + 56 + public function getRepetitionOptions() { 57 + return array( 58 + HeraldRepetitionPolicyConfig::FIRST, 59 + ); 60 + } 61 + 62 + public function getHeraldName() { 63 + return pht('New Diff'); 64 + } 65 + 66 + public function getActionNameMap($rule_type) { 67 + return array( 68 + self::ACTION_BLOCK => pht('Block diff with message'), 69 + ) + parent::getActionNameMap($rule_type); 70 + } 71 + 72 + public function getActions($rule_type) { 73 + switch ($rule_type) { 74 + case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 75 + return array_merge( 76 + array( 77 + self::ACTION_BLOCK, 78 + self::ACTION_NOTHING, 79 + ), 80 + parent::getActions($rule_type)); 81 + } 82 + } 83 + 84 + public function applyHeraldEffects(array $effects) { 85 + assert_instances_of($effects, 'HeraldEffect'); 86 + 87 + $result = array(); 88 + foreach ($effects as $effect) { 89 + $action = $effect->getAction(); 90 + switch ($action) { 91 + case self::ACTION_BLOCK: 92 + $result[] = new HeraldApplyTranscript( 93 + $effect, 94 + true, 95 + pht('Blocked diff.')); 96 + break; 97 + default: 98 + $result[] = $this->applyStandardEffect($effect); 99 + break; 100 + } 101 + } 102 + 103 + return $result; 104 + } 105 + 106 + }
+4 -5
src/applications/herald/adapter/HeraldDifferentialAdapter.php src/applications/differential/herald/HeraldDifferentialAdapter.php
··· 25 25 $repository = id(new PhabricatorRepositoryQuery()) 26 26 ->setViewer(PhabricatorUser::getOmnipotentUser()) 27 27 ->withPHIDs(array($repository_phid)) 28 - ->needProjectPHIDs(true) 29 28 ->executeOne(); 30 29 } else { 31 30 $repository = null; ··· 38 37 } 39 38 40 39 41 - protected function loadAffectedPaths() { 40 + public function loadAffectedPaths() { 42 41 $changesets = $this->loadChangesets(); 43 42 44 43 $paths = array(); ··· 62 61 return $changeset->getAbsoluteRepositoryPath($repository, $diff); 63 62 } 64 63 65 - protected function loadContentDictionary() { 64 + public function loadContentDictionary() { 66 65 $add_lines = DifferentialHunk::FLAG_LINES_ADDED; 67 66 $rem_lines = DifferentialHunk::FLAG_LINES_REMOVED; 68 67 $mask = ($add_lines | $rem_lines); 69 68 return $this->loadContentWithMask($mask); 70 69 } 71 70 72 - protected function loadAddedContentDictionary() { 71 + public function loadAddedContentDictionary() { 73 72 return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_ADDED); 74 73 } 75 74 76 - protected function loadRemovedContentDictionary() { 75 + public function loadRemovedContentDictionary() { 77 76 return $this->loadContentWithMask(DifferentialHunk::FLAG_LINES_REMOVED); 78 77 } 79 78
-167
src/applications/herald/adapter/HeraldDifferentialDiffAdapter.php
··· 1 - <?php 2 - 3 - final class HeraldDifferentialDiffAdapter extends HeraldDifferentialAdapter { 4 - 5 - public function getAdapterApplicationClass() { 6 - return 'PhabricatorDifferentialApplication'; 7 - } 8 - 9 - protected function initializeNewAdapter() { 10 - $this->setDiff(new DifferentialDiff()); 11 - } 12 - 13 - public function isSingleEventAdapter() { 14 - return true; 15 - } 16 - 17 - protected function loadChangesets() { 18 - return $this->loadChangesetsWithHunks(); 19 - } 20 - 21 - protected function loadChangesetsWithHunks() { 22 - return $this->getDiff()->getChangesets(); 23 - } 24 - 25 - public function getObject() { 26 - return $this->getDiff(); 27 - } 28 - 29 - public function getAdapterContentType() { 30 - return 'differential.diff'; 31 - } 32 - 33 - public function getAdapterContentName() { 34 - return pht('Differential Diffs'); 35 - } 36 - 37 - public function getAdapterContentDescription() { 38 - return pht( 39 - "React to new diffs being uploaded, before writes occur.\n". 40 - "These rules can reject diffs before they are written to permanent ". 41 - "storage, to prevent users from accidentally uploading private keys or ". 42 - "other sensitive information."); 43 - } 44 - 45 - public function supportsRuleType($rule_type) { 46 - switch ($rule_type) { 47 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 48 - return true; 49 - case HeraldRuleTypeConfig::RULE_TYPE_OBJECT: 50 - case HeraldRuleTypeConfig::RULE_TYPE_PERSONAL: 51 - default: 52 - return false; 53 - } 54 - } 55 - 56 - public function getFields() { 57 - return array_merge( 58 - array( 59 - self::FIELD_AUTHOR, 60 - self::FIELD_AUTHOR_PROJECTS, 61 - self::FIELD_REPOSITORY, 62 - self::FIELD_REPOSITORY_PROJECTS, 63 - self::FIELD_DIFF_FILE, 64 - self::FIELD_DIFF_CONTENT, 65 - self::FIELD_DIFF_ADDED_CONTENT, 66 - self::FIELD_DIFF_REMOVED_CONTENT, 67 - ), 68 - parent::getFields()); 69 - } 70 - 71 - public function getRepetitionOptions() { 72 - return array( 73 - HeraldRepetitionPolicyConfig::FIRST, 74 - ); 75 - } 76 - 77 - public function getPHID() { 78 - return $this->getObject()->getPHID(); 79 - } 80 - 81 - public function getHeraldName() { 82 - return pht('New Diff'); 83 - } 84 - 85 - public function getActionNameMap($rule_type) { 86 - return array( 87 - self::ACTION_BLOCK => pht('Block diff with message'), 88 - ) + parent::getActionNameMap($rule_type); 89 - } 90 - 91 - public function getHeraldField($field) { 92 - switch ($field) { 93 - case self::FIELD_AUTHOR: 94 - return $this->getObject()->getAuthorPHID(); 95 - break; 96 - case self::FIELD_AUTHOR_PROJECTS: 97 - $author_phid = $this->getHeraldField(self::FIELD_AUTHOR); 98 - if (!$author_phid) { 99 - return array(); 100 - } 101 - 102 - $projects = id(new PhabricatorProjectQuery()) 103 - ->setViewer(PhabricatorUser::getOmnipotentUser()) 104 - ->withMemberPHIDs(array($author_phid)) 105 - ->execute(); 106 - 107 - return mpull($projects, 'getPHID'); 108 - case self::FIELD_DIFF_FILE: 109 - return $this->loadAffectedPaths(); 110 - case self::FIELD_REPOSITORY: 111 - $repository = $this->loadRepository(); 112 - if (!$repository) { 113 - return null; 114 - } 115 - return $repository->getPHID(); 116 - case self::FIELD_REPOSITORY_PROJECTS: 117 - $repository = $this->loadRepository(); 118 - if (!$repository) { 119 - return array(); 120 - } 121 - return $repository->getProjectPHIDs(); 122 - case self::FIELD_DIFF_CONTENT: 123 - return $this->loadContentDictionary(); 124 - case self::FIELD_DIFF_ADDED_CONTENT: 125 - return $this->loadAddedContentDictionary(); 126 - case self::FIELD_DIFF_REMOVED_CONTENT: 127 - return $this->loadRemovedContentDictionary(); 128 - } 129 - 130 - return parent::getHeraldField($field); 131 - } 132 - 133 - public function getActions($rule_type) { 134 - switch ($rule_type) { 135 - case HeraldRuleTypeConfig::RULE_TYPE_GLOBAL: 136 - return array_merge( 137 - array( 138 - self::ACTION_BLOCK, 139 - self::ACTION_NOTHING, 140 - ), 141 - parent::getActions($rule_type)); 142 - } 143 - } 144 - 145 - public function applyHeraldEffects(array $effects) { 146 - assert_instances_of($effects, 'HeraldEffect'); 147 - 148 - $result = array(); 149 - foreach ($effects as $effect) { 150 - $action = $effect->getAction(); 151 - switch ($action) { 152 - case self::ACTION_BLOCK: 153 - $result[] = new HeraldApplyTranscript( 154 - $effect, 155 - true, 156 - pht('Blocked diff.')); 157 - break; 158 - default: 159 - $result[] = $this->applyStandardEffect($effect); 160 - break; 161 - } 162 - } 163 - 164 - return $result; 165 - } 166 - 167 - }