Path: blob/master/src/applications/diffusion/herald/DiffusionAuditorsHeraldAction.php
12242 views
<?php12abstract class DiffusionAuditorsHeraldAction3extends HeraldAction {45const DO_AUTHORS = 'do.authors';6const DO_ADD_AUDITORS = 'do.add-auditors';78public function getActionGroupKey() {9return HeraldApplicationActionGroup::ACTIONGROUPKEY;10}1112public function supportsObject($object) {13return ($object instanceof PhabricatorRepositoryCommit);14}1516protected function applyAuditors(array $phids, HeraldRule $rule) {17$adapter = $this->getAdapter();18$object = $adapter->getObject();1920$auditors = $object->getAudits();2122// Don't try to add commit authors as auditors.23$authors = array();24foreach ($phids as $key => $phid) {25if ($phid == $object->getAuthorPHID()) {26$authors[] = $phid;27unset($phids[$key]);28}29}3031if ($authors) {32$this->logEffect(self::DO_AUTHORS, $authors);33if (!$phids) {34return;35}36}3738$current = array();39foreach ($auditors as $auditor) {40$current[] = $auditor->getAuditorPHID();41}4243$allowed_types = array(44PhabricatorPeopleUserPHIDType::TYPECONST,45PhabricatorProjectProjectPHIDType::TYPECONST,46PhabricatorOwnersPackagePHIDType::TYPECONST,47);4849$targets = $this->loadStandardTargets($phids, $allowed_types, $current);50if (!$targets) {51return;52}5354$phids = array_fuse(array_keys($targets));5556$xaction = $adapter->newTransaction()57->setTransactionType(DiffusionCommitAuditorsTransaction::TRANSACTIONTYPE)58->setNewValue(59array(60'+' => $phids,61));6263$adapter->queueTransaction($xaction);6465$this->logEffect(self::DO_ADD_AUDITORS, $phids);66}6768protected function getActionEffectMap() {69return array(70self::DO_AUTHORS => array(71'icon' => 'fa-user',72'color' => 'grey',73'name' => pht('Commit Author'),74),75self::DO_ADD_AUDITORS => array(76'icon' => 'fa-user',77'color' => 'green',78'name' => pht('Added Auditors'),79),80);81}8283protected function renderActionEffectDescription($type, $data) {84switch ($type) {85case self::DO_AUTHORS:86return pht(87'Declined to add commit author as auditor: %s.',88$this->renderHandleList($data));89case self::DO_ADD_AUDITORS:90return pht(91'Added %s auditor(s): %s.',92phutil_count($data),93$this->renderHandleList($data));94}95}9697}9899100