@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DiffusionCommitRequiredActionResultBucket
4 extends DiffusionCommitResultBucket {
5
6 const BUCKETKEY = 'action';
7
8 private $objects;
9
10 public function getResultBucketName() {
11 return pht('Bucket by Required Action');
12 }
13
14 protected function buildResultGroups(
15 PhabricatorSavedQuery $query,
16 array $objects) {
17
18 $this->objects = $objects;
19
20 $phids = $query->getEvaluatedParameter('responsiblePHIDs');
21 if (!$phids) {
22 throw new Exception(
23 pht(
24 'You can not bucket results by required action without '.
25 'specifying "Responsible Users".'));
26 }
27 $phids = array_fuse($phids);
28
29 $groups = array();
30
31 $groups[] = $this->newGroup()
32 ->setName(pht('Needs Attention'))
33 ->setNoDataString(pht('None of your commits have active concerns.'))
34 ->setObjects($this->filterConcernRaised($phids));
35
36 $groups[] = $this->newGroup()
37 ->setName(pht('Needs Verification'))
38 ->setNoDataString(pht('No commits are awaiting your verification.'))
39 ->setObjects($this->filterNeedsVerification($phids));
40
41 $groups[] = $this->newGroup()
42 ->setName(pht('Ready to Audit'))
43 ->setNoDataString(pht('No commits are waiting for you to audit them.'))
44 ->setObjects($this->filterShouldAudit($phids));
45
46 $groups[] = $this->newGroup()
47 ->setName(pht('Waiting on Authors'))
48 ->setNoDataString(pht('None of your audits are waiting on authors.'))
49 ->setObjects($this->filterWaitingOnAuthors($phids));
50
51 $groups[] = $this->newGroup()
52 ->setName(pht('Waiting on Auditors'))
53 ->setNoDataString(pht('None of your commits are waiting on audit.'))
54 ->setObjects($this->filterWaitingOnAuditors($phids));
55
56 // Because you can apply these buckets to queries which include revisions
57 // that have been closed, add an "Other" bucket if we still have stuff
58 // that didn't get filtered into any of the previous buckets.
59 if ($this->objects) {
60 $groups[] = $this->newGroup()
61 ->setName(pht('Other Commits'))
62 ->setObjects($this->objects);
63 }
64
65 return $groups;
66 }
67
68 private function filterConcernRaised(array $phids) {
69 $results = array();
70 $objects = $this->objects;
71
72 foreach ($objects as $key => $object) {
73 if (empty($phids[$object->getAuthorPHID()])) {
74 continue;
75 }
76
77 if (!$object->isAuditStatusConcernRaised()) {
78 continue;
79 }
80
81 $results[$key] = $object;
82 unset($this->objects[$key]);
83 }
84
85 return $results;
86 }
87
88 private function filterNeedsVerification(array $phids) {
89 $results = array();
90 $objects = $this->objects;
91
92 $has_concern = array(
93 PhabricatorAuditRequestStatus::CONCERNED,
94 );
95 $has_concern = array_fuse($has_concern);
96
97 foreach ($objects as $key => $object) {
98 if (isset($phids[$object->getAuthorPHID()])) {
99 continue;
100 }
101
102 if (!$object->isAuditStatusNeedsVerification()) {
103 continue;
104 }
105
106 if (!$this->hasAuditorsWithStatus($object, $phids, $has_concern)) {
107 continue;
108 }
109
110 $results[$key] = $object;
111 unset($this->objects[$key]);
112 }
113
114 return $results;
115 }
116
117 private function filterShouldAudit(array $phids) {
118 $results = array();
119 $objects = $this->objects;
120
121 $should_audit = array(
122 PhabricatorAuditRequestStatus::AUDIT_REQUIRED,
123 PhabricatorAuditRequestStatus::AUDIT_REQUESTED,
124 );
125 $should_audit = array_fuse($should_audit);
126
127 foreach ($objects as $key => $object) {
128 if (isset($phids[$object->getAuthorPHID()])) {
129 continue;
130 }
131
132 if (!$this->hasAuditorsWithStatus($object, $phids, $should_audit)) {
133 continue;
134 }
135
136 $results[$key] = $object;
137 unset($this->objects[$key]);
138 }
139
140 return $results;
141 }
142
143 private function filterWaitingOnAuthors(array $phids) {
144 $results = array();
145 $objects = $this->objects;
146
147 foreach ($objects as $key => $object) {
148 if (!$object->isAuditStatusConcernRaised()) {
149 continue;
150 }
151
152 if (isset($phids[$object->getAuthorPHID()])) {
153 continue;
154 }
155
156 $results[$key] = $object;
157 unset($this->objects[$key]);
158 }
159
160 return $results;
161 }
162
163 private function filterWaitingOnAuditors(array $phids) {
164 $results = array();
165 $objects = $this->objects;
166
167 foreach ($objects as $key => $object) {
168 $any_waiting =
169 $object->isAuditStatusNeedsAudit() ||
170 $object->isAuditStatusNeedsVerification() ||
171 $object->isAuditStatusPartiallyAudited();
172
173 if (!$any_waiting) {
174 continue;
175 }
176
177 $results[$key] = $object;
178 unset($this->objects[$key]);
179 }
180
181 return $results;
182 }
183
184}