@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add "Project tags added" and "Project tags removed" fields in Herald

Summary: Ref T13480. These fields don't serve a specific strong use case, but are broadly reasonable capabilities after "state" vs "change" actions were relaxed by T13283.

Test Plan: Wrote rules using the new fields, added and removed projects (and did neither) to fire them / not fire them. Inspected the transcripts to see the project PHIDs making it to the field values.

Maniphest Tasks: T13480

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

+127 -18
+7 -1
src/__phutil_library_map__.php
··· 4382 4382 'PhabricatorProjectSubprojectsProfileMenuItem' => 'applications/project/menuitem/PhabricatorProjectSubprojectsProfileMenuItem.php', 4383 4383 'PhabricatorProjectSubtypeDatasource' => 'applications/project/typeahead/PhabricatorProjectSubtypeDatasource.php', 4384 4384 'PhabricatorProjectSubtypesConfigType' => 'applications/project/config/PhabricatorProjectSubtypesConfigType.php', 4385 + 'PhabricatorProjectTagsAddedField' => 'applications/project/herald/PhabricatorProjectTagsAddedField.php', 4386 + 'PhabricatorProjectTagsField' => 'applications/project/herald/PhabricatorProjectTagsField.php', 4387 + 'PhabricatorProjectTagsRemovedField' => 'applications/project/herald/PhabricatorProjectTagsRemovedField.php', 4385 4388 'PhabricatorProjectTestDataGenerator' => 'applications/project/lipsum/PhabricatorProjectTestDataGenerator.php', 4386 4389 'PhabricatorProjectTransaction' => 'applications/project/storage/PhabricatorProjectTransaction.php', 4387 4390 'PhabricatorProjectTransactionEditor' => 'applications/project/editor/PhabricatorProjectTransactionEditor.php', ··· 7679 7682 'HeraldPreCommitContentAdapter' => 'HeraldPreCommitAdapter', 7680 7683 'HeraldPreCommitRefAdapter' => 'HeraldPreCommitAdapter', 7681 7684 'HeraldPreventActionGroup' => 'HeraldActionGroup', 7682 - 'HeraldProjectsField' => 'HeraldField', 7685 + 'HeraldProjectsField' => 'PhabricatorProjectTagsField', 7683 7686 'HeraldRecursiveConditionsException' => 'Exception', 7684 7687 'HeraldRelatedFieldGroup' => 'HeraldFieldGroup', 7685 7688 'HeraldRemarkupFieldValue' => 'HeraldFieldValue', ··· 10943 10946 'PhabricatorProjectSubprojectsProfileMenuItem' => 'PhabricatorProfileMenuItem', 10944 10947 'PhabricatorProjectSubtypeDatasource' => 'PhabricatorTypeaheadDatasource', 10945 10948 'PhabricatorProjectSubtypesConfigType' => 'PhabricatorJSONConfigType', 10949 + 'PhabricatorProjectTagsAddedField' => 'PhabricatorProjectTagsField', 10950 + 'PhabricatorProjectTagsField' => 'HeraldField', 10951 + 'PhabricatorProjectTagsRemovedField' => 'PhabricatorProjectTagsField', 10946 10952 'PhabricatorProjectTestDataGenerator' => 'PhabricatorTestDataGenerator', 10947 10953 'PhabricatorProjectTransaction' => 'PhabricatorModularTransaction', 10948 10954 'PhabricatorProjectTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
+45
src/applications/herald/field/HeraldField.php
··· 241 241 return false; 242 242 } 243 243 244 + final protected function getAppliedTransactionsOfTypes(array $types) { 245 + $types = array_fuse($types); 246 + $xactions = $this->getAdapter()->getAppliedTransactions(); 247 + 248 + $result = array(); 249 + foreach ($xactions as $key => $xaction) { 250 + $xaction_type = $xaction->getTransactionType(); 251 + if (isset($types[$xaction_type])) { 252 + $result[$key] = $xaction; 253 + } 254 + } 255 + 256 + return $result; 257 + } 258 + 259 + final protected function getAppliedEdgeTransactionOfType($edge_type) { 260 + $edge_xactions = $this->getAppliedTransactionsOfTypes( 261 + array( 262 + PhabricatorTransactions::TYPE_EDGE, 263 + )); 264 + 265 + $results = array(); 266 + foreach ($edge_xactions as $edge_xaction) { 267 + $xaction_edge_type = $edge_xaction->getMetadataValue('edge:type'); 268 + if ($xaction_edge_type == $edge_type) { 269 + $results[] = $edge_xaction; 270 + } 271 + } 272 + 273 + if (count($results) > 1) { 274 + throw new Exception( 275 + pht( 276 + 'Found more than one ("%s") applied edge transactions with given '. 277 + 'edge type ("%s"); expected zero or one.', 278 + phutil_count($results), 279 + $edge_type)); 280 + } 281 + 282 + if ($results) { 283 + return head($results); 284 + } 285 + 286 + return null; 287 + } 288 + 244 289 public function isFieldAvailable() { 245 290 return true; 246 291 }
+2 -17
src/applications/project/herald/HeraldProjectsField.php
··· 1 1 <?php 2 2 3 - final class HeraldProjectsField extends HeraldField { 3 + final class HeraldProjectsField 4 + extends PhabricatorProjectTagsField { 4 5 5 6 const FIELDCONST = 'projects'; 6 7 ··· 8 9 return pht('Project tags'); 9 10 } 10 11 11 - public function getFieldGroupKey() { 12 - return HeraldSupportFieldGroup::FIELDGROUPKEY; 13 - } 14 - 15 - public function supportsObject($object) { 16 - return ($object instanceof PhabricatorProjectInterface); 17 - } 18 - 19 12 public function getHeraldFieldValue($object) { 20 13 return PhabricatorEdgeQuery::loadDestinationPHIDs( 21 14 $object->getPHID(), 22 15 PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 23 - } 24 - 25 - protected function getHeraldFieldStandardType() { 26 - return self::STANDARD_PHID_LIST; 27 - } 28 - 29 - protected function getDatasource() { 30 - return new PhabricatorProjectDatasource(); 31 16 } 32 17 33 18 }
+23
src/applications/project/herald/PhabricatorProjectTagsAddedField.php
··· 1 + <?php 2 + 3 + final class PhabricatorProjectTagsAddedField 4 + extends PhabricatorProjectTagsField { 5 + 6 + const FIELDCONST = 'projects.added'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Project tags added'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + $xaction = $this->getProjectTagsTransaction(); 14 + if (!$xaction) { 15 + return array(); 16 + } 17 + 18 + $record = PhabricatorEdgeChangeRecord::newFromTransaction($xaction); 19 + 20 + return $record->getAddedPHIDs(); 21 + } 22 + 23 + }
+27
src/applications/project/herald/PhabricatorProjectTagsField.php
··· 1 + <?php 2 + 3 + abstract class PhabricatorProjectTagsField 4 + extends HeraldField { 5 + 6 + public function getFieldGroupKey() { 7 + return HeraldSupportFieldGroup::FIELDGROUPKEY; 8 + } 9 + 10 + public function supportsObject($object) { 11 + return ($object instanceof PhabricatorProjectInterface); 12 + } 13 + 14 + protected function getHeraldFieldStandardType() { 15 + return self::STANDARD_PHID_LIST; 16 + } 17 + 18 + protected function getDatasource() { 19 + return new PhabricatorProjectDatasource(); 20 + } 21 + 22 + final protected function getProjectTagsTransaction() { 23 + return $this->getAppliedEdgeTransactionOfType( 24 + PhabricatorProjectObjectHasProjectEdgeType::EDGECONST); 25 + } 26 + 27 + }
+23
src/applications/project/herald/PhabricatorProjectTagsRemovedField.php
··· 1 + <?php 2 + 3 + final class PhabricatorProjectTagsRemovedField 4 + extends PhabricatorProjectTagsField { 5 + 6 + const FIELDCONST = 'projects.removed'; 7 + 8 + public function getHeraldFieldName() { 9 + return pht('Project tags removed'); 10 + } 11 + 12 + public function getHeraldFieldValue($object) { 13 + $xaction = $this->getProjectTagsTransaction(); 14 + if (!$xaction) { 15 + return array(); 16 + } 17 + 18 + $record = PhabricatorEdgeChangeRecord::newFromTransaction($xaction); 19 + 20 + return $record->getRemovedPHIDs(); 21 + } 22 + 23 + }