2015-07-30 20:39:35 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
abstract class DifferentialReviewersHeraldAction
|
|
|
|
extends HeraldAction {
|
|
|
|
|
|
|
|
const DO_AUTHORS = 'do.authors';
|
|
|
|
const DO_ADD_REVIEWERS = 'do.add-reviewers';
|
|
|
|
const DO_ADD_BLOCKING_REVIEWERS = 'do.add-blocking-reviewers';
|
|
|
|
|
|
|
|
public function getActionGroupKey() {
|
|
|
|
return HeraldApplicationActionGroup::ACTIONGROUPKEY;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function supportsObject($object) {
|
|
|
|
return ($object instanceof DifferentialRevision);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyReviewers(array $phids, $is_blocking) {
|
|
|
|
$adapter = $this->getAdapter();
|
|
|
|
$object = $adapter->getObject();
|
|
|
|
|
|
|
|
$phids = array_fuse($phids);
|
|
|
|
|
|
|
|
// Don't try to add revision authors as reviewers.
|
|
|
|
$authors = array();
|
|
|
|
foreach ($phids as $phid) {
|
|
|
|
if ($phid == $object->getAuthorPHID()) {
|
|
|
|
$authors[] = $phid;
|
|
|
|
unset($phids[$phid]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($authors) {
|
|
|
|
$this->logEffect(self::DO_AUTHORS, $authors);
|
2015-08-03 22:34:31 +02:00
|
|
|
if (!$phids) {
|
|
|
|
return;
|
|
|
|
}
|
2015-07-30 20:39:35 +02:00
|
|
|
}
|
|
|
|
|
2017-03-20 23:04:23 +01:00
|
|
|
$reviewers = $object->getReviewers();
|
2015-07-30 20:39:35 +02:00
|
|
|
|
|
|
|
if ($is_blocking) {
|
|
|
|
$new_status = DifferentialReviewerStatus::STATUS_BLOCKING;
|
|
|
|
} else {
|
|
|
|
$new_status = DifferentialReviewerStatus::STATUS_ADDED;
|
|
|
|
}
|
|
|
|
|
|
|
|
$new_strength = DifferentialReviewerStatus::getStatusStrength(
|
|
|
|
$new_status);
|
|
|
|
|
2015-08-03 22:34:31 +02:00
|
|
|
$current = array();
|
2015-07-30 20:39:35 +02:00
|
|
|
foreach ($phids as $phid) {
|
|
|
|
if (!isset($reviewers[$phid])) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
// If we're applying a stronger status (usually, upgrading a reviewer
|
|
|
|
// into a blocking reviewer), skip this check so we apply the change.
|
|
|
|
$old_strength = DifferentialReviewerStatus::getStatusStrength(
|
2017-03-22 17:46:45 +01:00
|
|
|
$reviewers[$phid]->getReviewerStatus());
|
2015-07-30 20:39:35 +02:00
|
|
|
if ($old_strength <= $new_strength) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2015-08-03 22:34:31 +02:00
|
|
|
$current[] = $phid;
|
2015-07-30 20:39:35 +02:00
|
|
|
}
|
|
|
|
|
2015-08-03 22:34:31 +02:00
|
|
|
$allowed_types = array(
|
|
|
|
PhabricatorPeopleUserPHIDType::TYPECONST,
|
|
|
|
PhabricatorProjectProjectPHIDType::TYPECONST,
|
2016-05-13 20:31:58 +02:00
|
|
|
PhabricatorOwnersPackagePHIDType::TYPECONST,
|
2015-08-03 22:34:31 +02:00
|
|
|
);
|
2015-07-30 20:39:35 +02:00
|
|
|
|
2015-08-03 22:34:31 +02:00
|
|
|
$targets = $this->loadStandardTargets($phids, $allowed_types, $current);
|
|
|
|
if (!$targets) {
|
2015-07-30 20:39:35 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-03 22:34:31 +02:00
|
|
|
$phids = array_fuse(array_keys($targets));
|
2015-07-30 20:39:35 +02:00
|
|
|
|
|
|
|
$value = array();
|
|
|
|
foreach ($phids as $phid) {
|
2017-03-20 16:33:43 +01:00
|
|
|
if ($is_blocking) {
|
|
|
|
$value[] = 'blocking('.$phid.')';
|
|
|
|
} else {
|
|
|
|
$value[] = $phid;
|
|
|
|
}
|
2015-07-30 20:39:35 +02:00
|
|
|
}
|
|
|
|
|
2017-03-20 16:33:43 +01:00
|
|
|
$reviewers_type = DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE;
|
2015-07-30 20:39:35 +02:00
|
|
|
|
|
|
|
$xaction = $adapter->newTransaction()
|
2017-03-20 16:33:43 +01:00
|
|
|
->setTransactionType($reviewers_type)
|
2015-07-30 20:39:35 +02:00
|
|
|
->setNewValue(
|
|
|
|
array(
|
|
|
|
'+' => $value,
|
|
|
|
));
|
|
|
|
|
|
|
|
$adapter->queueTransaction($xaction);
|
|
|
|
|
|
|
|
if ($is_blocking) {
|
|
|
|
$this->logEffect(self::DO_ADD_BLOCKING_REVIEWERS, $phids);
|
|
|
|
} else {
|
|
|
|
$this->logEffect(self::DO_ADD_REVIEWERS, $phids);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getActionEffectMap() {
|
|
|
|
return array(
|
|
|
|
self::DO_AUTHORS => array(
|
|
|
|
'icon' => 'fa-user',
|
|
|
|
'color' => 'grey',
|
|
|
|
'name' => pht('Revision Author'),
|
|
|
|
),
|
|
|
|
self::DO_ADD_REVIEWERS => array(
|
|
|
|
'icon' => 'fa-user',
|
|
|
|
'color' => 'green',
|
|
|
|
'name' => pht('Added Reviewers'),
|
|
|
|
),
|
|
|
|
self::DO_ADD_BLOCKING_REVIEWERS => array(
|
|
|
|
'icon' => 'fa-user',
|
|
|
|
'color' => 'green',
|
|
|
|
'name' => pht('Added Blocking Reviewers'),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2015-08-03 15:01:24 +02:00
|
|
|
protected function renderActionEffectDescription($type, $data) {
|
2015-07-30 20:39:35 +02:00
|
|
|
switch ($type) {
|
|
|
|
case self::DO_AUTHORS:
|
|
|
|
return pht(
|
|
|
|
'Declined to add revision author as reviewer: %s.',
|
|
|
|
$this->renderHandleList($data));
|
|
|
|
case self::DO_ADD_REVIEWERS:
|
|
|
|
return pht(
|
|
|
|
'Added %s reviewer(s): %s.',
|
2015-11-02 20:54:38 +01:00
|
|
|
phutil_count($data),
|
2015-07-30 20:39:35 +02:00
|
|
|
$this->renderHandleList($data));
|
|
|
|
case self::DO_ADD_BLOCKING_REVIEWERS:
|
|
|
|
return pht(
|
|
|
|
'Added %s blocking reviewer(s): %s.',
|
2015-11-02 20:54:38 +01:00
|
|
|
phutil_count($data),
|
2015-07-30 20:39:35 +02:00
|
|
|
$this->renderHandleList($data));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|