Skip to content

Commit a335004

Browse files
author
epriestley
committed
Modularize Differential Reviewer actions in Herald
Ref T8726. Modularizes the "Add Reviewers" and "Add Blocking Reviewers" Herald actions.
1 parent 8d8ee18 commit a335004

15 files changed

+426
-136
lines changed

resources/sql/autopatches/20150724.herald.1.sql renamed to resources/sql/autopatches/20150730.herald.1.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,25 @@
1-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
1+
UPDATE {$NAMESPACE}_herald.herald_action a
22
JOIN {$NAMESPACE}_herald.herald_rule r
33
ON a.ruleID = r.id
44
SET a.action = 'subscribers.add'
55
WHERE r.ruleType != 'personal'
66
AND a.action = 'addcc';
77

8-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
8+
UPDATE {$NAMESPACE}_herald.herald_action a
99
JOIN {$NAMESPACE}_herald.herald_rule r
1010
ON a.ruleID = r.id
1111
SET a.action = 'subscribers.self.add'
1212
WHERE r.ruleType = 'personal'
1313
AND a.action = 'addcc';
1414

15-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
15+
UPDATE {$NAMESPACE}_herald.herald_action a
1616
JOIN {$NAMESPACE}_herald.herald_rule r
1717
ON a.ruleID = r.id
1818
SET a.action = 'subscribers.remove'
1919
WHERE r.ruleType != 'personal'
2020
AND a.action = 'remcc';
2121

22-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
22+
UPDATE {$NAMESPACE}_herald.herald_action a
2323
JOIN {$NAMESPACE}_herald.herald_rule r
2424
ON a.ruleID = r.id
2525
SET a.action = 'subscribers.self.remove'

resources/sql/autopatches/20150724.herald.2.sql renamed to resources/sql/autopatches/20150730.herald.2.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
1+
UPDATE {$NAMESPACE}_herald.herald_action a
22
JOIN {$NAMESPACE}_herald.herald_rule r
33
ON a.ruleID = r.id
44
SET a.action = 'email.other'
55
WHERE r.ruleType != 'personal'
66
AND a.action = 'email';
77

8-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
8+
UPDATE {$NAMESPACE}_herald.herald_action a
99
JOIN {$NAMESPACE}_herald.herald_rule r
1010
ON a.ruleID = r.id
1111
SET a.action = 'email.self'

resources/sql/autopatches/20150724.herald.3.sql renamed to resources/sql/autopatches/20150730.herald.3.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
1+
UPDATE {$NAMESPACE}_herald.herald_action a
22
JOIN {$NAMESPACE}_herald.herald_rule r
33
ON a.ruleID = r.id
44
SET a.action = 'projects.add'
55
WHERE a.action = 'addprojects';
66

7-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
7+
UPDATE {$NAMESPACE}_herald.herald_action a
88
JOIN {$NAMESPACE}_herald.herald_rule r
99
ON a.ruleID = r.id
1010
SET a.action = 'projects.remove'

resources/sql/autopatches/20150724.herald.4.sql renamed to resources/sql/autopatches/20150730.herald.4.sql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
1+
UPDATE {$NAMESPACE}_herald.herald_action a
22
JOIN {$NAMESPACE}_herald.herald_rule r
33
ON a.ruleID = r.id
44
SET a.action = 'maniphest.assign.other'
55
WHERE r.ruleType != 'personal'
66
AND a.action = 'assigntask';
77

8-
UPDATE {$NAMESPACE}_herald.herald_actionrecord a
8+
UPDATE {$NAMESPACE}_herald.herald_action a
99
JOIN {$NAMESPACE}_herald.herald_rule r
1010
ON a.ruleID = r.id
1111
SET a.action = 'maniphest.assign.self'
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
UPDATE {$NAMESPACE}_herald.herald_action a
2+
JOIN {$NAMESPACE}_herald.herald_rule r
3+
ON a.ruleID = r.id
4+
SET a.action = 'differential.reviewers.blocking'
5+
WHERE r.ruleType != 'personal'
6+
AND a.action = 'addreviewers';
7+
8+
UPDATE {$NAMESPACE}_herald.herald_action a
9+
JOIN {$NAMESPACE}_herald.herald_rule r
10+
ON a.ruleID = r.id
11+
SET a.action = 'differential.reviewers.self.blocking'
12+
WHERE r.ruleType = 'personal'
13+
AND a.action = 'addreviewers';
14+
15+
UPDATE {$NAMESPACE}_herald.herald_action a
16+
JOIN {$NAMESPACE}_herald.herald_rule r
17+
ON a.ruleID = r.id
18+
SET a.action = 'differential.reviewers.add'
19+
WHERE r.ruleType != 'personal'
20+
AND a.action = 'addblockingreviewers';
21+
22+
UPDATE {$NAMESPACE}_herald.herald_action a
23+
JOIN {$NAMESPACE}_herald.herald_rule r
24+
ON a.ruleID = r.id
25+
SET a.action = 'differential.reviewers.self.add'
26+
WHERE r.ruleType = 'personal'
27+
AND a.action = 'addblockingreviewers';

src/__phutil_library_map__.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,12 @@
435435
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
436436
'DifferentialReviewerForRevisionEdgeType' => 'applications/differential/edge/DifferentialReviewerForRevisionEdgeType.php',
437437
'DifferentialReviewerStatus' => 'applications/differential/constants/DifferentialReviewerStatus.php',
438+
'DifferentialReviewersAddBlockingReviewersHeraldAction' => 'applications/differential/herald/DifferentialReviewersAddBlockingReviewersHeraldAction.php',
439+
'DifferentialReviewersAddBlockingSelfHeraldAction' => 'applications/differential/herald/DifferentialReviewersAddBlockingSelfHeraldAction.php',
440+
'DifferentialReviewersAddReviewersHeraldAction' => 'applications/differential/herald/DifferentialReviewersAddReviewersHeraldAction.php',
441+
'DifferentialReviewersAddSelfHeraldAction' => 'applications/differential/herald/DifferentialReviewersAddSelfHeraldAction.php',
438442
'DifferentialReviewersField' => 'applications/differential/customfield/DifferentialReviewersField.php',
443+
'DifferentialReviewersHeraldAction' => 'applications/differential/herald/DifferentialReviewersHeraldAction.php',
439444
'DifferentialReviewersView' => 'applications/differential/view/DifferentialReviewersView.php',
440445
'DifferentialRevision' => 'applications/differential/storage/DifferentialRevision.php',
441446
'DifferentialRevisionAffectedFilesHeraldField' => 'applications/differential/herald/DifferentialRevisionAffectedFilesHeraldField.php',
@@ -4044,7 +4049,12 @@
40444049
'DifferentialReviewer' => 'Phobject',
40454050
'DifferentialReviewerForRevisionEdgeType' => 'PhabricatorEdgeType',
40464051
'DifferentialReviewerStatus' => 'Phobject',
4052+
'DifferentialReviewersAddBlockingReviewersHeraldAction' => 'DifferentialReviewersHeraldAction',
4053+
'DifferentialReviewersAddBlockingSelfHeraldAction' => 'DifferentialReviewersHeraldAction',
4054+
'DifferentialReviewersAddReviewersHeraldAction' => 'DifferentialReviewersHeraldAction',
4055+
'DifferentialReviewersAddSelfHeraldAction' => 'DifferentialReviewersHeraldAction',
40474056
'DifferentialReviewersField' => 'DifferentialCoreCustomField',
4057+
'DifferentialReviewersHeraldAction' => 'HeraldAction',
40484058
'DifferentialReviewersView' => 'AphrontView',
40494059
'DifferentialRevision' => array(
40504060
'DifferentialDAO',

src/applications/differential/editor/DifferentialTransactionEditor.php

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1588,11 +1588,6 @@ protected function buildHeraldAdapter(
15881588
$revision,
15891589
$revision->getActiveDiff());
15901590

1591-
$reviewers = $revision->getReviewerStatus();
1592-
$reviewer_phids = mpull($reviewers, 'getReviewerPHID');
1593-
1594-
$adapter->setExplicitReviewers($reviewer_phids);
1595-
15961591
return $adapter;
15971592
}
15981593

@@ -1603,60 +1598,6 @@ protected function didApplyHeraldRules(
16031598

16041599
$xactions = array();
16051600

1606-
// Build a transaction to adjust reviewers.
1607-
$reviewers = array(
1608-
DifferentialReviewerStatus::STATUS_ADDED =>
1609-
array_keys($adapter->getReviewersAddedByHerald()),
1610-
DifferentialReviewerStatus::STATUS_BLOCKING =>
1611-
array_keys($adapter->getBlockingReviewersAddedByHerald()),
1612-
);
1613-
1614-
$old_reviewers = $object->getReviewerStatus();
1615-
$old_reviewers = mpull($old_reviewers, null, 'getReviewerPHID');
1616-
1617-
$value = array();
1618-
foreach ($reviewers as $status => $phids) {
1619-
foreach ($phids as $phid) {
1620-
if ($phid == $object->getAuthorPHID()) {
1621-
// Don't try to add the revision's author as a reviewer, since this
1622-
// isn't valid and doesn't make sense.
1623-
continue;
1624-
}
1625-
1626-
// If the target is already a reviewer, don't try to change anything
1627-
// if their current status is at least as strong as the new status.
1628-
// For example, don't downgrade an "Accepted" to a "Blocking Reviewer".
1629-
$old_reviewer = idx($old_reviewers, $phid);
1630-
if ($old_reviewer) {
1631-
$old_status = $old_reviewer->getStatus();
1632-
1633-
$old_strength = DifferentialReviewerStatus::getStatusStrength(
1634-
$old_status);
1635-
$new_strength = DifferentialReviewerStatus::getStatusStrength(
1636-
$status);
1637-
1638-
if ($new_strength <= $old_strength) {
1639-
continue;
1640-
}
1641-
}
1642-
1643-
$value['+'][$phid] = array(
1644-
'data' => array(
1645-
'status' => $status,
1646-
),
1647-
);
1648-
}
1649-
}
1650-
1651-
if ($value) {
1652-
$edge_reviewer = DifferentialRevisionHasReviewerEdgeType::EDGECONST;
1653-
1654-
$xactions[] = id(new DifferentialTransaction())
1655-
->setTransactionType(PhabricatorTransactions::TYPE_EDGE)
1656-
->setMetadataValue('edge:type', $edge_reviewer)
1657-
->setNewValue($value);
1658-
}
1659-
16601601
// Require legalpad document signatures.
16611602
$legal_phids = $adapter->getRequiredSignatureDocumentPHIDs();
16621603
if ($legal_phids) {
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
final class DifferentialReviewersAddBlockingReviewersHeraldAction
4+
extends DifferentialReviewersHeraldAction {
5+
6+
const ACTIONCONST = 'differential.reviewers.blocking';
7+
8+
public function getHeraldActionName() {
9+
return pht('Add blocking reviewers');
10+
}
11+
12+
public function supportsRuleType($rule_type) {
13+
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
14+
}
15+
16+
public function applyEffect($object, HeraldEffect $effect) {
17+
return $this->applyReviewers($effect->getTarget(), $is_blocking = true);
18+
}
19+
20+
public function getHeraldActionStandardType() {
21+
return self::STANDARD_PHID_LIST;
22+
}
23+
24+
protected function getDatasource() {
25+
return new PhabricatorMetaMTAMailableDatasource();
26+
}
27+
28+
public function renderActionDescription($value) {
29+
return pht('Add blocking reviewers: %s.', $this->renderHandleList($value));
30+
}
31+
32+
}
33+
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<?php
2+
3+
final class DifferentialReviewersAddBlockingSelfHeraldAction
4+
extends DifferentialReviewersHeraldAction {
5+
6+
const ACTIONCONST = 'differential.reviewers.self.blocking';
7+
8+
public function getHeraldActionName() {
9+
return pht('Add me as a blocking reviewer');
10+
}
11+
12+
public function supportsRuleType($rule_type) {
13+
return ($rule_type == HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
14+
}
15+
16+
public function applyEffect($object, HeraldEffect $effect) {
17+
$phid = $effect->getRule()->getAuthorPHID();
18+
return $this->applyReviewers(array($phid), $is_blocking = true);
19+
}
20+
21+
public function getHeraldActionStandardType() {
22+
return self::STANDARD_NONE;
23+
}
24+
25+
public function renderActionDescription($value) {
26+
return pht('Add rule author as blocking reviewer.');
27+
}
28+
29+
}
30+
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
final class DifferentialReviewersAddReviewersHeraldAction
4+
extends DifferentialReviewersHeraldAction {
5+
6+
const ACTIONCONST = 'differential.reviewers.add';
7+
8+
public function getHeraldActionName() {
9+
return pht('Add reviewers');
10+
}
11+
12+
public function supportsRuleType($rule_type) {
13+
return ($rule_type != HeraldRuleTypeConfig::RULE_TYPE_PERSONAL);
14+
}
15+
16+
public function applyEffect($object, HeraldEffect $effect) {
17+
return $this->applyReviewers($effect->getTarget(), $is_blocking = false);
18+
}
19+
20+
public function getHeraldActionStandardType() {
21+
return self::STANDARD_PHID_LIST;
22+
}
23+
24+
protected function getDatasource() {
25+
return new PhabricatorMetaMTAMailableDatasource();
26+
}
27+
28+
public function renderActionDescription($value) {
29+
return pht('Add reviewers: %s.', $this->renderHandleList($value));
30+
}
31+
32+
}
33+

0 commit comments

Comments
 (0)