@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.

Provide a modular buildable transaction in Diffusion

Summary:
Depends on D19279. Ref T13110. This implements the existing publishing logic for buildables, but does so via ModularTransactions instead of a core transaction type.

Since each application is implementing build transactions independently, this removes the core type.

Next, Differential will get a similar treatment.

Test Plan: Used `bin/harbormaster publish` (with some commenting-out-guard-clauses) to publish a commit Buildable; saw unchanged feed behavior.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13110

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

+159 -105
+2
src/__phutil_library_map__.php
··· 659 659 'DiffusionCommitAutocloseHeraldField' => 'applications/diffusion/herald/DiffusionCommitAutocloseHeraldField.php', 660 660 'DiffusionCommitBranchesController' => 'applications/diffusion/controller/DiffusionCommitBranchesController.php', 661 661 'DiffusionCommitBranchesHeraldField' => 'applications/diffusion/herald/DiffusionCommitBranchesHeraldField.php', 662 + 'DiffusionCommitBuildableTransaction' => 'applications/diffusion/xaction/DiffusionCommitBuildableTransaction.php', 662 663 'DiffusionCommitCommitterHeraldField' => 'applications/diffusion/herald/DiffusionCommitCommitterHeraldField.php', 663 664 'DiffusionCommitCommitterProjectsHeraldField' => 'applications/diffusion/herald/DiffusionCommitCommitterProjectsHeraldField.php', 664 665 'DiffusionCommitConcernTransaction' => 'applications/diffusion/xaction/DiffusionCommitConcernTransaction.php', ··· 5908 5909 'DiffusionCommitAutocloseHeraldField' => 'DiffusionCommitHeraldField', 5909 5910 'DiffusionCommitBranchesController' => 'DiffusionController', 5910 5911 'DiffusionCommitBranchesHeraldField' => 'DiffusionCommitHeraldField', 5912 + 'DiffusionCommitBuildableTransaction' => 'DiffusionCommitTransactionType', 5911 5913 'DiffusionCommitCommitterHeraldField' => 'DiffusionCommitHeraldField', 5912 5914 'DiffusionCommitCommitterProjectsHeraldField' => 'DiffusionCommitHeraldField', 5913 5915 'DiffusionCommitConcernTransaction' => 'DiffusionCommitAuditTransaction',
+34 -1
src/applications/diffusion/harbormaster/DiffusionBuildableEngine.php
··· 1 1 <?php 2 2 3 3 final class DiffusionBuildableEngine 4 - extends HarbormasterBuildableEngine {} 4 + extends HarbormasterBuildableEngine { 5 + 6 + public function publishBuildable( 7 + HarbormasterBuildable $old, 8 + HarbormasterBuildable $new) { 9 + 10 + // Don't publish manual buildables. 11 + if ($new->getIsManualBuildable()) { 12 + return; 13 + } 14 + 15 + // Don't publish anything if the buildable status has not changed. At 16 + // least for now, Diffusion handles buildable status exactly the same 17 + // way that Harbormaster does. 18 + $old_status = $old->getBuildableStatus(); 19 + $new_status = $new->getBuildableStatus(); 20 + if ($old_status === $new_status) { 21 + return; 22 + } 23 + 24 + // Don't publish anything if the buildable is still building. 25 + if ($new->isBuilding()) { 26 + return; 27 + } 28 + 29 + $xaction = $this->newTransaction() 30 + ->setMetadataValue('harbormaster:buildablePHID', $new->getPHID()) 31 + ->setTransactionType(DiffusionCommitBuildableTransaction::TRANSACTIONTYPE) 32 + ->setNewValue($new->getBuildableStatus()); 33 + 34 + $this->applyTransactions(array($xaction)); 35 + } 36 + 37 + }
+89
src/applications/diffusion/xaction/DiffusionCommitBuildableTransaction.php
··· 1 + <?php 2 + 3 + final class DiffusionCommitBuildableTransaction 4 + extends DiffusionCommitTransactionType { 5 + 6 + // NOTE: This uses an older constant for compatibility. We should perhaps 7 + // migrate these at some point. 8 + const TRANSACTIONTYPE = 'harbormaster:buildable'; 9 + 10 + public function generateNewValue($object, $value) { 11 + return $value; 12 + } 13 + 14 + public function generateOldValue($object) { 15 + return null; 16 + } 17 + 18 + public function getIcon() { 19 + return $this->newBuildableStatus()->getIcon(); 20 + } 21 + 22 + public function getColor() { 23 + return $this->newBuildableStatus()->getColor(); 24 + } 25 + 26 + public function getActionName() { 27 + return $this->newBuildableStatus()->getActionName(); 28 + } 29 + 30 + public function shouldHideForFeed() { 31 + return !$this->newBuildableStatus()->isFailed(); 32 + } 33 + 34 + public function shouldHideForMail() { 35 + return !$this->newBuildableStatus()->isFailed(); 36 + } 37 + 38 + public function getTitle() { 39 + $new = $this->getNewValue(); 40 + $buildable_phid = $this->getBuildablePHID(); 41 + 42 + switch ($new) { 43 + case HarbormasterBuildableStatus::STATUS_PASSED: 44 + return pht( 45 + '%s completed building %s.', 46 + $this->renderAuthor(), 47 + $this->renderHandle($buildable_phid)); 48 + case HarbormasterBuildableStatus::STATUS_FAILED: 49 + return pht( 50 + '%s failed to build %s!', 51 + $this->renderAuthor(), 52 + $this->renderHandle($buildable_phid)); 53 + } 54 + 55 + return null; 56 + } 57 + 58 + public function getTitleForFeed() { 59 + $new = $this->getNewValue(); 60 + $buildable_phid = $this->getBuildablePHID(); 61 + 62 + switch ($new) { 63 + case HarbormasterBuildableStatus::STATUS_PASSED: 64 + return pht( 65 + '%s completed building %s for %s.', 66 + $this->renderAuthor(), 67 + $this->renderHandle($buildable_phid), 68 + $this->renderObject()); 69 + case HarbormasterBuildableStatus::STATUS_FAILED: 70 + return pht( 71 + '%s failed to build %s for %s!', 72 + $this->renderAuthor(), 73 + $this->renderHandle($buildable_phid), 74 + $this->renderObject()); 75 + } 76 + 77 + return null; 78 + } 79 + 80 + private function newBuildableStatus() { 81 + $new = $this->getNewValue(); 82 + return HarbormasterBuildableStatus::newBuildableStatusObject($new); 83 + } 84 + 85 + private function getBuildablePHID() { 86 + return $this->getMetadataValue('harbormaster:buildablePHID'); 87 + } 88 + 89 + }
+17
src/applications/harbormaster/constants/HarbormasterBuildableStatus.php
··· 39 39 return $this->getProperty('name'); 40 40 } 41 41 42 + public function getActionName() { 43 + return $this->getProperty('name.action'); 44 + } 45 + 42 46 public function getColor() { 43 47 return $this->getProperty('color'); 44 48 } ··· 47 51 return ($this->key === self::STATUS_PREPARING); 48 52 } 49 53 54 + public function isBuilding() { 55 + return ($this->key === self::STATUS_BUILDING); 56 + } 57 + 58 + public function isFailed() { 59 + return ($this->key === self::STATUS_FAILED); 60 + } 61 + 50 62 public static function getOptionMap() { 51 63 return ipull(self::getSpecifications(), 'name'); 52 64 } ··· 57 69 'name' => pht('Preparing'), 58 70 'color' => 'blue', 59 71 'icon' => 'fa-hourglass-o', 72 + 'name.action' => pht('Build Preparing'), 60 73 ), 61 74 self::STATUS_BUILDING => array( 62 75 'name' => pht('Building'), 63 76 'color' => 'blue', 64 77 'icon' => 'fa-chevron-circle-right', 78 + 'name.action' => pht('Build Started'), 65 79 ), 66 80 self::STATUS_PASSED => array( 67 81 'name' => pht('Passed'), 68 82 'color' => 'green', 69 83 'icon' => 'fa-check-circle', 84 + 'name.action' => pht('Build Passed'), 70 85 ), 71 86 self::STATUS_FAILED => array( 72 87 'name' => pht('Failed'), 73 88 'color' => 'red', 74 89 'icon' => 'fa-times-circle', 90 + 'name.action' => pht('Build Failed'), 75 91 ), 76 92 ); 77 93 } ··· 86 102 'name' => pht('Unknown ("%s")', $status), 87 103 'icon' => 'fa-question-circle', 88 104 'color' => 'bluegrey', 105 + 'name.action' => pht('Build Status'), 89 106 ); 90 107 } 91 108
+1 -1
src/applications/harbormaster/engine/HarbormasterBuildableEngine.php
··· 45 45 return $this->object; 46 46 } 47 47 48 - final public function publishBuildable( 48 + public function publishBuildable( 49 49 HarbormasterBuildable $old, 50 50 HarbormasterBuildable $new) { 51 51 return;
+4
src/applications/harbormaster/storage/HarbormasterBuildable.php
··· 233 233 return $this->getBuildableStatusObject()->isPreparing(); 234 234 } 235 235 236 + public function isBuilding() { 237 + return $this->getBuildableStatusObject()->isBuilding(); 238 + } 239 + 236 240 237 241 /* -( Messages )----------------------------------------------------------- */ 238 242
-1
src/applications/transactions/constants/PhabricatorTransactions.php
··· 9 9 const TYPE_JOIN_POLICY = 'core:join-policy'; 10 10 const TYPE_EDGE = 'core:edge'; 11 11 const TYPE_CUSTOMFIELD = 'core:customfield'; 12 - const TYPE_BUILDABLE = 'harbormaster:buildable'; 13 12 const TYPE_TOKEN = 'token:give'; 14 13 const TYPE_INLINESTATE = 'core:inlinestate'; 15 14 const TYPE_SPACE = 'core:space';
-7
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 313 313 $types[] = PhabricatorTransactions::TYPE_CUSTOMFIELD; 314 314 } 315 315 316 - if ($this->object instanceof HarbormasterBuildableInterface) { 317 - $types[] = PhabricatorTransactions::TYPE_BUILDABLE; 318 - } 319 - 320 316 if ($this->object instanceof PhabricatorTokenReceiverInterface) { 321 317 $types[] = PhabricatorTransactions::TYPE_TOKEN; 322 318 } ··· 469 465 case PhabricatorTransactions::TYPE_VIEW_POLICY: 470 466 case PhabricatorTransactions::TYPE_EDIT_POLICY: 471 467 case PhabricatorTransactions::TYPE_JOIN_POLICY: 472 - case PhabricatorTransactions::TYPE_BUILDABLE: 473 468 case PhabricatorTransactions::TYPE_TOKEN: 474 469 case PhabricatorTransactions::TYPE_INLINESTATE: 475 470 case PhabricatorTransactions::TYPE_SUBTYPE: ··· 610 605 return $field->applyApplicationTransactionInternalEffects($xaction); 611 606 case PhabricatorTransactions::TYPE_CREATE: 612 607 case PhabricatorTransactions::TYPE_SUBTYPE: 613 - case PhabricatorTransactions::TYPE_BUILDABLE: 614 608 case PhabricatorTransactions::TYPE_TOKEN: 615 609 case PhabricatorTransactions::TYPE_VIEW_POLICY: 616 610 case PhabricatorTransactions::TYPE_EDIT_POLICY: ··· 673 667 case PhabricatorTransactions::TYPE_CREATE: 674 668 case PhabricatorTransactions::TYPE_SUBTYPE: 675 669 case PhabricatorTransactions::TYPE_EDGE: 676 - case PhabricatorTransactions::TYPE_BUILDABLE: 677 670 case PhabricatorTransactions::TYPE_TOKEN: 678 671 case PhabricatorTransactions::TYPE_VIEW_POLICY: 679 672 case PhabricatorTransactions::TYPE_EDIT_POLICY:
-95
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 54 54 55 55 public function shouldGenerateOldValue() { 56 56 switch ($this->getTransactionType()) { 57 - case PhabricatorTransactions::TYPE_BUILDABLE: 58 57 case PhabricatorTransactions::TYPE_TOKEN: 59 58 case PhabricatorTransactions::TYPE_CUSTOMFIELD: 60 59 case PhabricatorTransactions::TYPE_INLINESTATE: ··· 339 338 break; 340 339 case PhabricatorTransactions::TYPE_TOKEN: 341 340 break; 342 - case PhabricatorTransactions::TYPE_BUILDABLE: 343 - $phid = $this->getMetadataValue('harbormaster:buildablePHID'); 344 - if ($phid) { 345 - $phids[] = array($phid); 346 - } 347 - break; 348 341 } 349 342 350 343 if ($this->getComment()) { ··· 470 463 return 'fa-ambulance'; 471 464 } 472 465 return 'fa-link'; 473 - case PhabricatorTransactions::TYPE_BUILDABLE: 474 - return 'fa-wrench'; 475 466 case PhabricatorTransactions::TYPE_TOKEN: 476 467 return 'fa-trophy'; 477 468 case PhabricatorTransactions::TYPE_SPACE: ··· 515 506 return 'sky'; 516 507 } 517 508 break; 518 - case PhabricatorTransactions::TYPE_BUILDABLE: 519 - switch ($this->getNewValue()) { 520 - case HarbormasterBuildableStatus::STATUS_PASSED: 521 - return 'green'; 522 - case HarbormasterBuildableStatus::STATUS_FAILED: 523 - return 'red'; 524 - } 525 - break; 526 509 } 527 510 return null; 528 511 } ··· 679 662 switch ($this->getTransactionType()) { 680 663 case PhabricatorTransactions::TYPE_TOKEN: 681 664 return true; 682 - case PhabricatorTransactions::TYPE_BUILDABLE: 683 - switch ($this->getNewValue()) { 684 - case HarbormasterBuildableStatus::STATUS_FAILED: 685 - // For now, only ever send mail when builds fail. We might let 686 - // you customize this later, but in most cases this is probably 687 - // completely uninteresting. 688 - return false; 689 - } 690 - return true; 691 665 case PhabricatorTransactions::TYPE_EDGE: 692 666 $edge_type = $this->getMetadataValue('edge:type'); 693 667 switch ($edge_type) { ··· 741 715 742 716 switch ($this->getTransactionType()) { 743 717 case PhabricatorTransactions::TYPE_TOKEN: 744 - return true; 745 - case PhabricatorTransactions::TYPE_BUILDABLE: 746 - switch ($this->getNewValue()) { 747 - case HarbormasterBuildableStatus::STATUS_FAILED: 748 - // For now, don't notify on build passes either. These are pretty 749 - // high volume and annoying, with very little present value. We 750 - // might want to turn them back on in the specific case of 751 - // build successes on the current document? 752 - return false; 753 - } 754 718 return true; 755 719 case PhabricatorTransactions::TYPE_EDGE: 756 720 $edge_type = $this->getMetadataValue('edge:type'); ··· 1027 991 $this->renderHandleLink($author_phid)); 1028 992 } 1029 993 1030 - case PhabricatorTransactions::TYPE_BUILDABLE: 1031 - switch ($this->getNewValue()) { 1032 - case HarbormasterBuildableStatus::STATUS_BUILDING: 1033 - return pht( 1034 - '%s started building %s.', 1035 - $this->renderHandleLink($author_phid), 1036 - $this->renderHandleLink( 1037 - $this->getMetadataValue('harbormaster:buildablePHID'))); 1038 - case HarbormasterBuildableStatus::STATUS_PASSED: 1039 - return pht( 1040 - '%s completed building %s.', 1041 - $this->renderHandleLink($author_phid), 1042 - $this->renderHandleLink( 1043 - $this->getMetadataValue('harbormaster:buildablePHID'))); 1044 - case HarbormasterBuildableStatus::STATUS_FAILED: 1045 - return pht( 1046 - '%s failed to build %s!', 1047 - $this->renderHandleLink($author_phid), 1048 - $this->renderHandleLink( 1049 - $this->getMetadataValue('harbormaster:buildablePHID'))); 1050 - default: 1051 - return null; 1052 - } 1053 - 1054 994 case PhabricatorTransactions::TYPE_INLINESTATE: 1055 995 $done = 0; 1056 996 $undone = 0; ··· 1239 1179 $this->renderHandleLink($author_phid), 1240 1180 $this->renderHandleLink($object_phid)); 1241 1181 } 1242 - case PhabricatorTransactions::TYPE_BUILDABLE: 1243 - switch ($this->getNewValue()) { 1244 - case HarbormasterBuildableStatus::STATUS_BUILDING: 1245 - return pht( 1246 - '%s started building %s for %s.', 1247 - $this->renderHandleLink($author_phid), 1248 - $this->renderHandleLink( 1249 - $this->getMetadataValue('harbormaster:buildablePHID')), 1250 - $this->renderHandleLink($object_phid)); 1251 - case HarbormasterBuildableStatus::STATUS_PASSED: 1252 - return pht( 1253 - '%s completed building %s for %s.', 1254 - $this->renderHandleLink($author_phid), 1255 - $this->renderHandleLink( 1256 - $this->getMetadataValue('harbormaster:buildablePHID')), 1257 - $this->renderHandleLink($object_phid)); 1258 - case HarbormasterBuildableStatus::STATUS_FAILED: 1259 - return pht( 1260 - '%s failed to build %s for %s.', 1261 - $this->renderHandleLink($author_phid), 1262 - $this->renderHandleLink( 1263 - $this->getMetadataValue('harbormaster:buildablePHID')), 1264 - $this->renderHandleLink($object_phid)); 1265 - default: 1266 - return null; 1267 - } 1268 1182 1269 1183 case PhabricatorTransactions::TYPE_COLUMNS: 1270 1184 $moves = $this->getInterestingMoves($new); ··· 1421 1335 return pht('Changed Policy'); 1422 1336 case PhabricatorTransactions::TYPE_SUBSCRIBERS: 1423 1337 return pht('Changed Subscribers'); 1424 - case PhabricatorTransactions::TYPE_BUILDABLE: 1425 - switch ($this->getNewValue()) { 1426 - case HarbormasterBuildableStatus::STATUS_PASSED: 1427 - return pht('Build Passed'); 1428 - case HarbormasterBuildableStatus::STATUS_FAILED: 1429 - return pht('Build Failed'); 1430 - default: 1431 - return pht('Build Status'); 1432 - } 1433 1338 default: 1434 1339 return pht('Updated'); 1435 1340 }
+8
src/applications/transactions/storage/PhabricatorModularTransaction.php
··· 100 100 return parent::shouldHideForFeed(); 101 101 } 102 102 103 + /* final */ public function shouldHideForMail(array $xactions) { 104 + if ($this->getTransactionImplementation()->shouldHideForMail()) { 105 + return true; 106 + } 107 + 108 + return parent::shouldHideForMail($xactions); 109 + } 110 + 103 111 /* final */ public function getIcon() { 104 112 $icon = $this->getTransactionImplementation()->getIcon(); 105 113 if ($icon !== null) {
+4
src/applications/transactions/storage/PhabricatorModularTransactionType.php
··· 51 51 return false; 52 52 } 53 53 54 + public function shouldHideForMail() { 55 + return false; 56 + } 57 + 54 58 public function getIcon() { 55 59 return null; 56 60 }