@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 e-mail message by field specification

Summary: Refactoring before the actual change.

Test Plan: None yet.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

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

vrana 1406d6cd 259638e9

+104 -34
+21
src/applications/differential/field/selector/DifferentialDefaultFieldSelector.php
··· 88 88 return array_values($map); 89 89 } 90 90 91 + public function sortFieldsForMail(array $fields) { 92 + assert_instances_of($fields, 'DifferentialFieldSpecification'); 93 + 94 + $map = array(); 95 + foreach ($fields as $field) { 96 + $map[get_class($field)] = $field; 97 + } 98 + 99 + $map = array_select_keys( 100 + $map, 101 + array( 102 + 'DifferentialSummaryFieldSpecification', 103 + 'DifferentialTestPlanFieldSpecification', 104 + 'DifferentialRevisionIDFieldSpecification', 105 + 'DifferentialBranchFieldSpecification', 106 + 'DifferentialCommitsFieldSpecification', 107 + )) + $map; 108 + 109 + return array_values($map); 110 + } 111 + 91 112 } 92 113
+5
src/applications/differential/field/selector/DifferentialFieldSelector.php
··· 33 33 return $fields; 34 34 } 35 35 36 + public function sortFieldsForMail(array $fields) { 37 + assert_instances_of($fields, 'DifferentialFieldSpecification'); 38 + return $fields; 39 + } 40 + 36 41 }
+17
src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php
··· 38 38 return phutil_escape_html($branch); 39 39 } 40 40 41 + public function renderValueForMail() { 42 + $status = $this->getRevision()->getStatus(); 43 + 44 + if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION && 45 + $status != ArcanistDifferentialRevisionStatus::ACCEPTED) { 46 + return null; 47 + } 48 + 49 + $diff = $this->getRevision()->loadActiveDiff(); 50 + if ($diff) { 51 + $branch = $diff->getBranch(); 52 + if ($branch) { 53 + return "BRANCH\n $branch"; 54 + } 55 + } 56 + } 57 + 41 58 }
+31 -1
src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php
··· 1 1 <?php 2 2 3 3 /* 4 - * Copyright 2011 Facebook, Inc. 4 + * Copyright 2012 Facebook, Inc. 5 5 * 6 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 7 * you may not use this file except in compliance with the License. ··· 48 48 private function getCommitPHIDs() { 49 49 $revision = $this->getRevision(); 50 50 return $revision->getCommitPHIDs(); 51 + } 52 + 53 + public function renderValueForMail() { 54 + $revision = $this->getRevision(); 55 + 56 + if ($revision->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED) { 57 + return null; 58 + } 59 + 60 + $phids = $revision->loadCommitPHIDs(); 61 + if (!$phids) { 62 + return null; 63 + } 64 + 65 + $body = array(); 66 + $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); 67 + if (count($handles) == 1) { 68 + $body[] = "COMMIT"; 69 + } else { 70 + // This is unlikely to ever happen since we'll send this mail the 71 + // first time we discover a commit, but it's not impossible if data 72 + // was migrated, etc. 73 + $body[] = "COMMITS"; 74 + } 75 + 76 + foreach ($handles as $handle) { 77 + $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); 78 + } 79 + 80 + return implode("\n", $body); 51 81 } 52 82 53 83 }
+17
src/applications/differential/field/specification/DifferentialFieldSpecification.php
··· 28 28 * @task edit Extending the Revision Edit Interface 29 29 * @task view Extending the Revision View Interface 30 30 * @task list Extending the Revision List Interface 31 + * @task mail Extending the E-mail Interface 31 32 * @task conduit Extending the Conduit View Interface 32 33 * @task commit Extending Commit Messages 33 34 * @task load Loading Additional Data ··· 364 365 */ 365 366 public function renderValueForRevisionList(DifferentialRevision $revision) { 366 367 throw new DifferentialFieldSpecificationIncompleteException($this); 368 + } 369 + 370 + 371 + /* -( Extending the E-mail Interface )------------------------------------- */ 372 + 373 + 374 + /** 375 + * Return plain text to render in e-mail messages. The text may span 376 + * multiple lines. 377 + * 378 + * @return string|null Plain text, or null for no message. 379 + * 380 + * @task mail 381 + */ 382 + public function renderValueForMail() { 383 + return null; 367 384 } 368 385 369 386
+5
src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php
··· 104 104 return 'D'.$revision->getID(); 105 105 } 106 106 107 + public function renderValueForMail() { 108 + $uri = PhabricatorEnv::getProductionURI('/D'.$this->id); 109 + return "REVISION DETAIL\n {$uri}"; 110 + } 111 + 107 112 }
+8 -33
src/applications/differential/mail/DifferentialCommentMail.php
··· 161 161 $body[] = null; 162 162 } 163 163 164 - $body[] = $this->renderRevisionDetailLink(); 165 - $body[] = null; 164 + $selector = DifferentialFieldSelector::newSelector(); 165 + $aux_fields = $selector->sortFieldsForMail( 166 + $selector->getFieldSpecifications()); 166 167 167 - $revision = $this->getRevision(); 168 - $status = $revision->getStatus(); 169 - 170 - if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVISION || 171 - $status == ArcanistDifferentialRevisionStatus::ACCEPTED) { 172 - $diff = $revision->loadActiveDiff(); 173 - if ($diff) { 174 - $branch = $diff->getBranch(); 175 - if ($branch) { 176 - $body[] = "BRANCH\n $branch"; 177 - $body[] = null; 178 - } 179 - } 180 - } 181 - 182 - if ($status == ArcanistDifferentialRevisionStatus::CLOSED) { 183 - $phids = $revision->loadCommitPHIDs(); 184 - if ($phids) { 185 - $handles = id(new PhabricatorObjectHandleData($phids))->loadHandles(); 186 - if (count($handles) == 1) { 187 - $body[] = "COMMIT"; 188 - } else { 189 - // This is unlikely to ever happen since we'll send this mail the 190 - // first time we discover a commit, but it's not impossible if data 191 - // was migrated, etc. 192 - $body[] = "COMMITS"; 193 - } 194 - 195 - foreach ($handles as $handle) { 196 - $body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI()); 197 - } 168 + foreach ($aux_fields as $field) { 169 + $field->setRevision($this->getRevision()); 170 + $text = $field->renderValueForMail(); 171 + if ($text !== null) { 172 + $body[] = $text; 198 173 $body[] = null; 199 174 } 200 175 }