Path: blob/master/src/applications/differential/herald/DifferentialReviewersHeraldAction.php
12256 views
<?php12abstract class DifferentialReviewersHeraldAction3extends HeraldAction {45const DO_AUTHORS = 'do.authors';6const DO_ADD_REVIEWERS = 'do.add-reviewers';7const DO_ADD_BLOCKING_REVIEWERS = 'do.add-blocking-reviewers';89public function getActionGroupKey() {10return HeraldApplicationActionGroup::ACTIONGROUPKEY;11}1213public function supportsObject($object) {14return ($object instanceof DifferentialRevision);15}1617protected function applyReviewers(array $phids, $is_blocking) {18$adapter = $this->getAdapter();19$object = $adapter->getObject();2021$phids = array_fuse($phids);2223// Don't try to add revision authors as reviewers.24$authors = array();25foreach ($phids as $phid) {26if ($phid == $object->getAuthorPHID()) {27$authors[] = $phid;28unset($phids[$phid]);29}30}3132if ($authors) {33$this->logEffect(self::DO_AUTHORS, $authors);34if (!$phids) {35return;36}37}3839$reviewers = $object->getReviewers();4041if ($is_blocking) {42$new_status = DifferentialReviewerStatus::STATUS_BLOCKING;43} else {44$new_status = DifferentialReviewerStatus::STATUS_ADDED;45}4647$new_strength = DifferentialReviewerStatus::getStatusStrength(48$new_status);4950$current = array();51foreach ($phids as $phid) {52if (!isset($reviewers[$phid])) {53continue;54}5556// If we're applying a stronger status (usually, upgrading a reviewer57// into a blocking reviewer), skip this check so we apply the change.58$old_strength = DifferentialReviewerStatus::getStatusStrength(59$reviewers[$phid]->getReviewerStatus());60if ($old_strength <= $new_strength) {61continue;62}6364$current[] = $phid;65}6667$allowed_types = array(68PhabricatorPeopleUserPHIDType::TYPECONST,69PhabricatorProjectProjectPHIDType::TYPECONST,70PhabricatorOwnersPackagePHIDType::TYPECONST,71);7273$targets = $this->loadStandardTargets($phids, $allowed_types, $current);74if (!$targets) {75return;76}7778$phids = array_fuse(array_keys($targets));7980$value = array();81foreach ($phids as $phid) {82if ($is_blocking) {83$value[] = 'blocking('.$phid.')';84} else {85$value[] = $phid;86}87}8889$reviewers_type = DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE;9091$xaction = $adapter->newTransaction()92->setTransactionType($reviewers_type)93->setNewValue(94array(95'+' => $value,96));9798$adapter->queueTransaction($xaction);99100if ($is_blocking) {101$this->logEffect(self::DO_ADD_BLOCKING_REVIEWERS, $phids);102} else {103$this->logEffect(self::DO_ADD_REVIEWERS, $phids);104}105}106107protected function getActionEffectMap() {108return array(109self::DO_AUTHORS => array(110'icon' => 'fa-user',111'color' => 'grey',112'name' => pht('Revision Author'),113),114self::DO_ADD_REVIEWERS => array(115'icon' => 'fa-user',116'color' => 'green',117'name' => pht('Added Reviewers'),118),119self::DO_ADD_BLOCKING_REVIEWERS => array(120'icon' => 'fa-user',121'color' => 'green',122'name' => pht('Added Blocking Reviewers'),123),124);125}126127protected function renderActionEffectDescription($type, $data) {128switch ($type) {129case self::DO_AUTHORS:130return pht(131'Declined to add revision author as reviewer: %s.',132$this->renderHandleList($data));133case self::DO_ADD_REVIEWERS:134return pht(135'Added %s reviewer(s): %s.',136phutil_count($data),137$this->renderHandleList($data));138case self::DO_ADD_BLOCKING_REVIEWERS:139return pht(140'Added %s blocking reviewer(s): %s.',141phutil_count($data),142$this->renderHandleList($data));143}144}145146147}148149150