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

Drive Differential review request e-mail message by field specification

Summary:
This also changes some stuff:

- Reviewers used to be at top, now they are under comments.
- Primary reviewer is now rendered as first.

Test Plan: Added `renderValueForMail()` to a custom field, created diff, commented on it and verified e-mails.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin

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

vrana ee916859 1406d6cd

+118 -56
+1
src/__phutil_library_map__.php
··· 268 268 'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php', 269 269 'DifferentialLocalCommitsView' => 'applications/differential/view/DifferentialLocalCommitsView.php', 270 270 'DifferentialMail' => 'applications/differential/mail/DifferentialMail.php', 271 + 'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php', 271 272 'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php', 272 273 'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php', 273 274 'DifferentialPathFieldSpecification' => 'applications/differential/field/specification/DifferentialPathFieldSpecification.php',
+25
src/applications/differential/constants/DifferentialMailPhase.php
··· 1 + <?php 2 + 3 + /* 4 + * Copyright 2012 Facebook, Inc. 5 + * 6 + * Licensed under the Apache License, Version 2.0 (the "License"); 7 + * you may not use this file except in compliance with the License. 8 + * You may obtain a copy of the License at 9 + * 10 + * http://www.apache.org/licenses/LICENSE-2.0 11 + * 12 + * Unless required by applicable law or agreed to in writing, software 13 + * distributed under the License is distributed on an "AS IS" BASIS, 14 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 + * See the License for the specific language governing permissions and 16 + * limitations under the License. 17 + */ 18 + 19 + final class DifferentialMailPhase { 20 + 21 + const WELCOME = 1; 22 + const UPDATE = 2; 23 + const COMMENT = 3; 24 + 25 + }
+2
src/applications/differential/field/selector/DifferentialDefaultFieldSelector.php
··· 99 99 $map = array_select_keys( 100 100 $map, 101 101 array( 102 + 'DifferentialReviewersFieldSpecification', 102 103 'DifferentialSummaryFieldSpecification', 103 104 'DifferentialTestPlanFieldSpecification', 104 105 'DifferentialRevisionIDFieldSpecification', 106 + 'DifferentialManiphestTasksFieldSpecification', 105 107 'DifferentialBranchFieldSpecification', 106 108 'DifferentialCommitsFieldSpecification', 107 109 )) + $map;
+1 -1
src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php
··· 38 38 return phutil_escape_html($branch); 39 39 } 40 40 41 - public function renderValueForMail() { 41 + public function renderValueForMail($phase) { 42 42 $status = $this->getRevision()->getStatus(); 43 43 44 44 if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION &&
+1 -1
src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php
··· 50 50 return $revision->getCommitPHIDs(); 51 51 } 52 52 53 - public function renderValueForMail() { 53 + public function renderValueForMail($phase) { 54 54 $revision = $this->getRevision(); 55 55 56 56 if ($revision->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED) {
+2 -1
src/applications/differential/field/specification/DifferentialFieldSpecification.php
··· 375 375 * Return plain text to render in e-mail messages. The text may span 376 376 * multiple lines. 377 377 * 378 + * @return int One of DifferentialMailPhase constants. 378 379 * @return string|null Plain text, or null for no message. 379 380 * 380 381 * @task mail 381 382 */ 382 - public function renderValueForMail() { 383 + public function renderValueForMail($phase) { 383 384 return null; 384 385 } 385 386
+19
src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php
··· 156 156 return $task_phids; 157 157 } 158 158 159 + public function renderValueForMail($phase) { 160 + if ($phase == DifferentialMailPhase::COMMENT) { 161 + return null; 162 + } 163 + 164 + if (!$this->maniphestTasks) { 165 + return null; 166 + } 167 + 168 + $handles = id(new PhabricatorObjectHandleData($this->maniphestTasks)) 169 + ->loadHandles(); 170 + $body = array(); 171 + $body[] = 'MANIPHEST TASKS'; 172 + foreach ($handles as $handle) { 173 + $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); 174 + } 175 + return implode("\n", $body); 176 + } 177 + 159 178 }
+18
src/applications/differential/field/specification/DifferentialReviewersFieldSpecification.php
··· 164 164 return array(); 165 165 } 166 166 167 + public function renderValueForMail($phase) { 168 + if ($phase == DifferentialMailPhase::COMMENT) { 169 + return null; 170 + } 171 + 172 + if (!$this->reviewers) { 173 + return null; 174 + } 175 + 176 + $handles = id(new PhabricatorObjectHandleData($this->reviewers)) 177 + ->loadHandles(); 178 + $handles = array_select_keys( 179 + $handles, 180 + array($this->getRevision()->getPrimaryReviewer())) + $handles; 181 + $names = mpull($handles, 'getName'); 182 + return 'Reviewers: '.implode(', ', $names); 183 + } 184 + 167 185 }
+1 -1
src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php
··· 104 104 return 'D'.$revision->getID(); 105 105 } 106 106 107 - public function renderValueForMail() { 107 + public function renderValueForMail($phase) { 108 108 $uri = PhabricatorEnv::getProductionURI('/D'.$this->id); 109 109 return "REVISION DETAIL\n {$uri}"; 110 110 }
+12
src/applications/differential/field/specification/DifferentialSummaryFieldSpecification.php
··· 74 74 return (string)$value; 75 75 } 76 76 77 + public function renderValueForMail($phase) { 78 + if ($phase != DifferentialMailPhase::WELCOME) { 79 + return null; 80 + } 81 + 82 + if ($this->summary == '') { 83 + return null; 84 + } 85 + 86 + return $this->summary; 87 + } 88 + 77 89 }
+12
src/applications/differential/field/specification/DifferentialTestPlanFieldSpecification.php
··· 107 107 return $value; 108 108 } 109 109 110 + public function renderValueForMail($phase) { 111 + if ($phase != DifferentialMailPhase::WELCOME) { 112 + return null; 113 + } 114 + 115 + if ($this->plan == '') { 116 + return null; 117 + } 118 + 119 + return "TEST PLAN\n".preg_replace('/^/m', ' ', $this->plan); 120 + } 121 + 110 122 private function isRequired() { 111 123 return PhabricatorEnv::getEnvConfig('differential.require-test-plan-field'); 112 124 }
-2
src/applications/differential/mail/DifferentialCCWelcomeMail.php
··· 29 29 $body = array(); 30 30 31 31 $body[] = "{$actor} added you to the CC list for the revision \"{$name}\"."; 32 - $body[] = $this->renderReviewersLine(); 33 - $body[] = null; 34 32 35 33 $body[] = $this->renderReviewRequestBody(); 36 34
+1 -12
src/applications/differential/mail/DifferentialCommentMail.php
··· 161 161 $body[] = null; 162 162 } 163 163 164 - $selector = DifferentialFieldSelector::newSelector(); 165 - $aux_fields = $selector->sortFieldsForMail( 166 - $selector->getFieldSpecifications()); 167 - 168 - foreach ($aux_fields as $field) { 169 - $field->setRevision($this->getRevision()); 170 - $text = $field->renderValueForMail(); 171 - if ($text !== null) { 172 - $body[] = $text; 173 - $body[] = null; 174 - } 175 - } 164 + $body[] = $this->renderAuxFields(DifferentialMailPhase::COMMENT); 176 165 177 166 return implode("\n", $body); 178 167 }
+18 -5
src/applications/differential/mail/DifferentialMail.php
··· 354 354 return $this->changesets; 355 355 } 356 356 357 - protected function getManiphestTaskPHIDs() { 358 - return $this->getRevision()->getAttachedPHIDs( 359 - PhabricatorPHIDConstants::PHID_TYPE_TASK); 360 - } 361 - 362 357 public function setInlineComments(array $inline_comments) { 363 358 assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface'); 364 359 $this->inlineComments = $inline_comments; ··· 367 362 368 363 public function getInlineComments() { 369 364 return $this->inlineComments; 365 + } 366 + 367 + protected function renderAuxFields($phase) { 368 + $selector = DifferentialFieldSelector::newSelector(); 369 + $aux_fields = $selector->sortFieldsForMail( 370 + $selector->getFieldSpecifications()); 371 + 372 + $body = array(); 373 + foreach ($aux_fields as $field) { 374 + $field->setRevision($this->getRevision()); 375 + $text = $field->renderValueForMail($phase); 376 + if ($text !== null) { 377 + $body[] = $text; 378 + $body[] = null; 379 + } 380 + } 381 + 382 + return implode("\n", $body); 370 383 } 371 384 372 385 public function renderRevisionDetailLink() {
-2
src/applications/differential/mail/DifferentialNewDiffMail.php
··· 44 44 } else { 45 45 $body[] = "{$actor} updated the revision \"{$name}\"."; 46 46 } 47 - $body[] = $this->renderReviewersLine(); 48 - $body[] = null; 49 47 50 48 $body[] = $this->renderReviewRequestBody(); 51 49
+5 -31
src/applications/differential/mail/DifferentialReviewRequestMail.php
··· 40 40 $this->setChangesets($changesets); 41 41 } 42 42 43 - protected function renderReviewersLine() { 44 - $reviewers = $this->getRevision()->getReviewers(); 45 - $handles = id(new PhabricatorObjectHandleData($reviewers))->loadHandles(); 46 - return 'Reviewers: '.$this->renderHandleList($handles, $reviewers); 47 - } 48 - 49 43 protected function renderReviewRequestBody() { 50 44 $revision = $this->getRevision(); 51 45 52 46 $body = array(); 53 - if ($this->isFirstMailToRecipients()) { 54 - if ($revision->getSummary() != '') { 55 - $body[] = $this->formatText($revision->getSummary()); 56 - $body[] = null; 57 - } 58 - 59 - if ($revision->getTestPlan() != '') { 60 - $body[] = 'TEST PLAN'; 61 - $body[] = $this->formatText($revision->getTestPlan()); 62 - $body[] = null; 63 - } 64 - } else { 47 + if (!$this->isFirstMailToRecipients()) { 65 48 if (strlen($this->getComments())) { 66 49 $body[] = $this->formatText($this->getComments()); 67 50 $body[] = null; 68 51 } 69 52 } 70 53 71 - $body[] = $this->renderRevisionDetailLink(); 72 - $body[] = null; 73 - 74 - $task_phids = $this->getManiphestTaskPHIDs(); 75 - if ($task_phids) { 76 - $handles = id(new PhabricatorObjectHandleData($task_phids)) 77 - ->loadHandles(); 78 - $body[] = 'MANIPHEST TASKS'; 79 - foreach ($handles as $handle) { 80 - $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); 81 - } 82 - $body[] = null; 83 - } 54 + $phase = ($this->isFirstMailToRecipients() ? 55 + DifferentialMailPhase::WELCOME : 56 + DifferentialMailPhase::UPDATE); 57 + $body[] = $this->renderAuxFields($phase); 84 58 85 59 $changesets = $this->getChangesets(); 86 60 if ($changesets) {