Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/herald/DifferentialReviewersHeraldAction.php
12256 views
1
<?php
2
3
abstract class DifferentialReviewersHeraldAction
4
extends HeraldAction {
5
6
const DO_AUTHORS = 'do.authors';
7
const DO_ADD_REVIEWERS = 'do.add-reviewers';
8
const DO_ADD_BLOCKING_REVIEWERS = 'do.add-blocking-reviewers';
9
10
public function getActionGroupKey() {
11
return HeraldApplicationActionGroup::ACTIONGROUPKEY;
12
}
13
14
public function supportsObject($object) {
15
return ($object instanceof DifferentialRevision);
16
}
17
18
protected function applyReviewers(array $phids, $is_blocking) {
19
$adapter = $this->getAdapter();
20
$object = $adapter->getObject();
21
22
$phids = array_fuse($phids);
23
24
// Don't try to add revision authors as reviewers.
25
$authors = array();
26
foreach ($phids as $phid) {
27
if ($phid == $object->getAuthorPHID()) {
28
$authors[] = $phid;
29
unset($phids[$phid]);
30
}
31
}
32
33
if ($authors) {
34
$this->logEffect(self::DO_AUTHORS, $authors);
35
if (!$phids) {
36
return;
37
}
38
}
39
40
$reviewers = $object->getReviewers();
41
42
if ($is_blocking) {
43
$new_status = DifferentialReviewerStatus::STATUS_BLOCKING;
44
} else {
45
$new_status = DifferentialReviewerStatus::STATUS_ADDED;
46
}
47
48
$new_strength = DifferentialReviewerStatus::getStatusStrength(
49
$new_status);
50
51
$current = array();
52
foreach ($phids as $phid) {
53
if (!isset($reviewers[$phid])) {
54
continue;
55
}
56
57
// If we're applying a stronger status (usually, upgrading a reviewer
58
// into a blocking reviewer), skip this check so we apply the change.
59
$old_strength = DifferentialReviewerStatus::getStatusStrength(
60
$reviewers[$phid]->getReviewerStatus());
61
if ($old_strength <= $new_strength) {
62
continue;
63
}
64
65
$current[] = $phid;
66
}
67
68
$allowed_types = array(
69
PhabricatorPeopleUserPHIDType::TYPECONST,
70
PhabricatorProjectProjectPHIDType::TYPECONST,
71
PhabricatorOwnersPackagePHIDType::TYPECONST,
72
);
73
74
$targets = $this->loadStandardTargets($phids, $allowed_types, $current);
75
if (!$targets) {
76
return;
77
}
78
79
$phids = array_fuse(array_keys($targets));
80
81
$value = array();
82
foreach ($phids as $phid) {
83
if ($is_blocking) {
84
$value[] = 'blocking('.$phid.')';
85
} else {
86
$value[] = $phid;
87
}
88
}
89
90
$reviewers_type = DifferentialRevisionReviewersTransaction::TRANSACTIONTYPE;
91
92
$xaction = $adapter->newTransaction()
93
->setTransactionType($reviewers_type)
94
->setNewValue(
95
array(
96
'+' => $value,
97
));
98
99
$adapter->queueTransaction($xaction);
100
101
if ($is_blocking) {
102
$this->logEffect(self::DO_ADD_BLOCKING_REVIEWERS, $phids);
103
} else {
104
$this->logEffect(self::DO_ADD_REVIEWERS, $phids);
105
}
106
}
107
108
protected function getActionEffectMap() {
109
return array(
110
self::DO_AUTHORS => array(
111
'icon' => 'fa-user',
112
'color' => 'grey',
113
'name' => pht('Revision Author'),
114
),
115
self::DO_ADD_REVIEWERS => array(
116
'icon' => 'fa-user',
117
'color' => 'green',
118
'name' => pht('Added Reviewers'),
119
),
120
self::DO_ADD_BLOCKING_REVIEWERS => array(
121
'icon' => 'fa-user',
122
'color' => 'green',
123
'name' => pht('Added Blocking Reviewers'),
124
),
125
);
126
}
127
128
protected function renderActionEffectDescription($type, $data) {
129
switch ($type) {
130
case self::DO_AUTHORS:
131
return pht(
132
'Declined to add revision author as reviewer: %s.',
133
$this->renderHandleList($data));
134
case self::DO_ADD_REVIEWERS:
135
return pht(
136
'Added %s reviewer(s): %s.',
137
phutil_count($data),
138
$this->renderHandleList($data));
139
case self::DO_ADD_BLOCKING_REVIEWERS:
140
return pht(
141
'Added %s blocking reviewer(s): %s.',
142
phutil_count($data),
143
$this->renderHandleList($data));
144
}
145
}
146
147
148
}
149
150