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

at recaptime-dev/main 98 lines 2.5 kB view raw
1<?php 2 3abstract class DiffusionAuditorsHeraldAction 4 extends HeraldAction { 5 6 const DO_AUTHORS = 'do.authors'; 7 const DO_ADD_AUDITORS = 'do.add-auditors'; 8 9 public function getActionGroupKey() { 10 return HeraldApplicationActionGroup::ACTIONGROUPKEY; 11 } 12 13 public function supportsObject($object) { 14 return ($object instanceof PhabricatorRepositoryCommit); 15 } 16 17 protected function applyAuditors(array $phids, HeraldRule $rule) { 18 $adapter = $this->getAdapter(); 19 $object = $adapter->getObject(); 20 21 $auditors = $object->getAudits(); 22 23 // Don't try to add commit authors as auditors. 24 $authors = array(); 25 foreach ($phids as $key => $phid) { 26 if ($phid == $object->getAuthorPHID()) { 27 $authors[] = $phid; 28 unset($phids[$key]); 29 } 30 } 31 32 if ($authors) { 33 $this->logEffect(self::DO_AUTHORS, $authors); 34 if (!$phids) { 35 return; 36 } 37 } 38 39 $current = array(); 40 foreach ($auditors as $auditor) { 41 $current[] = $auditor->getAuditorPHID(); 42 } 43 44 $allowed_types = array( 45 PhabricatorPeopleUserPHIDType::TYPECONST, 46 PhabricatorProjectProjectPHIDType::TYPECONST, 47 PhabricatorOwnersPackagePHIDType::TYPECONST, 48 ); 49 50 $targets = $this->loadStandardTargets($phids, $allowed_types, $current); 51 if (!$targets) { 52 return; 53 } 54 55 $phids = array_fuse(array_keys($targets)); 56 57 $xaction = $adapter->newTransaction() 58 ->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE) 59 ->setNewValue( 60 array( 61 '+' => $phids, 62 )); 63 64 $adapter->queueTransaction($xaction); 65 66 $this->logEffect(self::DO_ADD_AUDITORS, $phids); 67 } 68 69 protected function getActionEffectMap() { 70 return array( 71 self::DO_AUTHORS => array( 72 'icon' => 'fa-user', 73 'color' => 'grey', 74 'name' => pht('Commit Author'), 75 ), 76 self::DO_ADD_AUDITORS => array( 77 'icon' => 'fa-user', 78 'color' => 'green', 79 'name' => pht('Added Auditors'), 80 ), 81 ); 82 } 83 84 protected function renderActionEffectDescription($type, $data) { 85 switch ($type) { 86 case self::DO_AUTHORS: 87 return pht( 88 'Declined to add commit author as auditor: %s.', 89 $this->renderHandleList($data)); 90 case self::DO_ADD_AUDITORS: 91 return pht( 92 'Added %s auditor(s): %s.', 93 phutil_count($data), 94 $this->renderHandleList($data)); 95 } 96 } 97 98}