@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

Simplify Differential "Reviewers" field

Summary: Ref T11114. Keep rendering and mail, toss the rest.

Test Plan: Edited and viewed reviewers.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T11114

Differential Revision: https://secure.phabricator.com/D17086

+15 -242
-239
src/applications/differential/customfield/DifferentialReviewersField.php
··· 7 7 return 'differential:reviewers'; 8 8 } 9 9 10 - public function getFieldKeyForConduit() { 11 - return 'reviewerPHIDs'; 12 - } 13 - 14 10 public function getFieldName() { 15 11 return pht('Reviewers'); 16 12 } ··· 24 20 return $revision->getReviewerStatus(); 25 21 } 26 22 27 - public function getNewValueForApplicationTransactions() { 28 - $specs = array(); 29 - foreach ($this->getValue() as $reviewer) { 30 - $specs[$reviewer->getReviewerPHID()] = array( 31 - 'data' => $reviewer->getEdgeData(), 32 - ); 33 - } 34 - 35 - return array('=' => $specs); 36 - } 37 - 38 - public function readValueFromRequest(AphrontRequest $request) { 39 - $datasource = id(new DifferentialBlockingReviewerDatasource()) 40 - ->setViewer($request->getViewer()); 41 - 42 - $new_phids = $request->getArr($this->getFieldKey()); 43 - $new_phids = $datasource->evaluateTokens($new_phids); 44 - 45 - $reviewers = array(); 46 - foreach ($new_phids as $spec) { 47 - if (!is_array($spec)) { 48 - $reviewers[$spec] = DifferentialReviewerStatus::STATUS_ADDED; 49 - } else { 50 - $reviewers[$spec['phid']] = $spec['type']; 51 - } 52 - } 53 - 54 - $this->updateReviewers($this->getValue(), $reviewers); 55 - } 56 - 57 - private function updateReviewers(array $old_reviewers, array $new_map) { 58 - // Compute a new set of reviewer objects. We're going to respect the new 59 - // reviewer order, add or remove any new or missing reviewers, and respect 60 - // any blocking or unblocking changes. For reviewers who were there before 61 - // and are still there, we're going to keep the old value because it 62 - // may be something like "Accept", "Reject", etc. 63 - 64 - $old_map = mpull($old_reviewers, 'getStatus', 'getReviewerPHID'); 65 - $status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING; 66 - 67 - $new_reviewers = array(); 68 - foreach ($new_map as $phid => $new) { 69 - $old = idx($old_map, $phid); 70 - 71 - // If we have an old status and this didn't make the reviewer blocking 72 - // or nonblocking, just retain the old status. This makes sure we don't 73 - // throw away rejects, accepts, etc. 74 - if ($old) { 75 - $is_block = ($old !== $status_blocking && $new === $status_blocking); 76 - $is_unblock = ($old === $status_blocking && $new !== $status_blocking); 77 - if (!$is_block && !$is_unblock) { 78 - $new_reviewers[$phid] = $old; 79 - continue; 80 - } 81 - } 82 - 83 - $new_reviewers[$phid] = $new; 84 - } 85 - 86 - foreach ($new_reviewers as $phid => $status) { 87 - $new_reviewers[$phid] = new DifferentialReviewerProxy( 88 - $phid, 89 - array( 90 - 'status' => $status, 91 - )); 92 - } 93 - 94 - $this->setValue($new_reviewers); 95 - } 96 - 97 - public function renderEditControl(array $handles) { 98 - $status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING; 99 - 100 - $value = array(); 101 - foreach ($this->getValue() as $reviewer) { 102 - $phid = $reviewer->getReviewerPHID(); 103 - if ($reviewer->getStatus() == $status_blocking) { 104 - $value[] = 'blocking('.$phid.')'; 105 - } else { 106 - $value[] = $phid; 107 - } 108 - } 109 - 110 - return id(new AphrontFormTokenizerControl()) 111 - ->setUser($this->getViewer()) 112 - ->setName($this->getFieldKey()) 113 - ->setDatasource(new DifferentialReviewerDatasource()) 114 - ->setValue($value) 115 - ->setError($this->getFieldError()) 116 - ->setLabel($this->getFieldName()); 117 - } 118 - 119 - public function getApplicationTransactionType() { 120 - return PhabricatorTransactions::TYPE_EDGE; 121 - } 122 - 123 - public function getApplicationTransactionMetadata() { 124 - return array( 125 - 'edge:type' => DifferentialRevisionHasReviewerEdgeType::EDGECONST, 126 - ); 127 - } 128 - 129 23 public function shouldAppearInPropertyView() { 130 24 return true; 131 25 } ··· 164 58 return $reviewers; 165 59 } 166 60 167 - public function shouldAppearInCommitMessage() { 168 - return true; 169 - } 170 - 171 - public function shouldAppearInCommitMessageTemplate() { 172 - return true; 173 - } 174 - 175 - public function getCommitMessageLabels() { 176 - return array( 177 - 'Reviewer', 178 - 'Reviewers', 179 - ); 180 - } 181 - 182 - public function parseValueFromCommitMessage($value) { 183 - $results = $this->parseObjectList( 184 - $value, 185 - array( 186 - PhabricatorPeopleUserPHIDType::TYPECONST, 187 - PhabricatorProjectProjectPHIDType::TYPECONST, 188 - PhabricatorOwnersPackagePHIDType::TYPECONST, 189 - ), 190 - false, 191 - array('!')); 192 - 193 - return $this->flattenReviewers($results); 194 - } 195 - 196 - public function getRequiredHandlePHIDsForCommitMessage() { 197 - return mpull($this->getValue(), 'getReviewerPHID'); 198 - } 199 - 200 - public function readValueFromCommitMessage($value) { 201 - $value = $this->inflateReviewers($value); 202 - 203 - $reviewers = array(); 204 - foreach ($value as $spec) { 205 - $phid = $spec['phid']; 206 - 207 - $is_blocking = isset($spec['suffixes']['!']); 208 - if ($is_blocking) { 209 - $status = DifferentialReviewerStatus::STATUS_BLOCKING; 210 - } else { 211 - $status = DifferentialReviewerStatus::STATUS_ADDED; 212 - } 213 - 214 - $reviewers[$phid] = $status; 215 - } 216 - 217 - $this->updateReviewers( 218 - $this->getObject()->getReviewerStatus(), 219 - $reviewers); 220 - 221 - return $this; 222 - } 223 - 224 - public function renderCommitMessageValue(array $handles) { 225 - $suffixes = array(); 226 - 227 - $status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING; 228 - 229 - foreach ($this->getValue() as $reviewer) { 230 - if ($reviewer->getStatus() == $status_blocking) { 231 - $phid = $reviewer->getReviewerPHID(); 232 - $suffixes[$phid] = '!'; 233 - } 234 - } 235 - 236 - return $this->renderObjectList($handles, $suffixes); 237 - } 238 - 239 - public function validateCommitMessageValue($value) { 240 - if (!$value) { 241 - return; 242 - } 243 - 244 - $author_phid = $this->getObject()->getAuthorPHID(); 245 - 246 - $config_self_accept_key = 'differential.allow-self-accept'; 247 - $allow_self_accept = PhabricatorEnv::getEnvConfig($config_self_accept_key); 248 - 249 - $value = $this->inflateReviewers($value); 250 - foreach ($value as $spec) { 251 - $phid = $spec['phid']; 252 - 253 - if (($phid == $author_phid) && !$allow_self_accept) { 254 - throw new DifferentialFieldValidationException( 255 - pht('The author of a revision can not be a reviewer.')); 256 - } 257 - } 258 - } 259 - 260 61 public function getRequiredHandlePHIDsForRevisionHeaderWarnings() { 261 62 return mpull($this->getValue(), 'getReviewerPHID'); 262 63 } ··· 286 87 } 287 88 288 89 return $warnings; 289 - } 290 - 291 - public function getProTips() { 292 - return array( 293 - pht( 294 - 'You can mark a reviewer as blocking by adding an exclamation '. 295 - 'mark ("!") after their name.'), 296 - ); 297 - } 298 - 299 - private function flattenReviewers(array $values) { 300 - // NOTE: For now, `arc` relies on this field returning only scalars, so we 301 - // need to reduce the results into scalars. See T10981. 302 - $result = array(); 303 - 304 - foreach ($values as $value) { 305 - $result[] = $value['phid'].implode('', array_keys($value['suffixes'])); 306 - } 307 - 308 - return $result; 309 - } 310 - 311 - private function inflateReviewers(array $values) { 312 - $result = array(); 313 - 314 - foreach ($values as $value) { 315 - if (substr($value, -1) == '!') { 316 - $value = substr($value, 0, -1); 317 - $suffixes = array('!' => '!'); 318 - } else { 319 - $suffixes = array(); 320 - } 321 - 322 - $result[] = array( 323 - 'phid' => $value, 324 - 'suffixes' => $suffixes, 325 - ); 326 - } 327 - 328 - return $result; 329 90 } 330 91 331 92 }
+3
src/applications/differential/storage/DifferentialTransaction.php
··· 27 27 // without doing a migration. At some point, we should do a migration and 28 28 // throw this away. 29 29 30 + // NOTE: Old reviewer edits are raw edge transactions. They could be 31 + // migrated to modular transactions when the rest of this migrates. 32 + 30 33 $xaction_type = $this->getTransactionType(); 31 34 if ($xaction_type == PhabricatorTransactions::TYPE_CUSTOMFIELD) { 32 35 switch ($this->getMetadataValue('customfield:key')) {
+12 -3
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
··· 960 960 if ($field) { 961 961 return $field->getApplicationTransactionTitle($this); 962 962 } else { 963 - return pht( 964 - '%s edited a custom field.', 965 - $this->renderHandleLink($author_phid)); 963 + $developer_mode = 'phabricator.developer-mode'; 964 + $is_developer = PhabricatorEnv::getEnvConfig($developer_mode); 965 + if ($is_developer) { 966 + return pht( 967 + '%s edited a custom field (with key "%s").', 968 + $this->renderHandleLink($author_phid), 969 + $this->getMetadata('customfield:key')); 970 + } else { 971 + return pht( 972 + '%s edited a custom field.', 973 + $this->renderHandleLink($author_phid)); 974 + } 966 975 } 967 976 968 977 case PhabricatorTransactions::TYPE_TOKEN: