Skip to content

Commit 9e8bbdb

Browse files
author
epriestley
committedMar 11, 2014
Port Differential mail features forward to transactions
Summary: Ref T2222. Brings the major mail features (affected files, patches) forward. This drops some of the minor integrations which just show object state (like "Maniphest Tasks") since I think they're not very important. I'll put them back if users miss them. Test Plan: Sent mail with inline/attached patches. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8459
1 parent 5033101 commit 9e8bbdb

19 files changed

+104
-823
lines changed
 

‎src/__phutil_library_map__.php

-8
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,6 @@
335335
'DifferentialBlameRevisionFieldSpecification' => 'applications/differential/field/specification/DifferentialBlameRevisionFieldSpecification.php',
336336
'DifferentialBranchField' => 'applications/differential/customfield/DifferentialBranchField.php',
337337
'DifferentialBranchFieldSpecification' => 'applications/differential/field/specification/DifferentialBranchFieldSpecification.php',
338-
'DifferentialCCWelcomeMail' => 'applications/differential/mail/DifferentialCCWelcomeMail.php',
339338
'DifferentialCCsFieldSpecification' => 'applications/differential/field/specification/DifferentialCCsFieldSpecification.php',
340339
'DifferentialCapabilityDefaultView' => 'applications/differential/capability/DifferentialCapabilityDefaultView.php',
341340
'DifferentialChangeType' => 'applications/differential/constants/DifferentialChangeType.php',
@@ -382,7 +381,6 @@
382381
'DifferentialDependsOnField' => 'applications/differential/customfield/DifferentialDependsOnField.php',
383382
'DifferentialDependsOnFieldSpecification' => 'applications/differential/field/specification/DifferentialDependsOnFieldSpecification.php',
384383
'DifferentialDiff' => 'applications/differential/storage/DifferentialDiff.php',
385-
'DifferentialDiffContentMail' => 'applications/differential/mail/DifferentialDiffContentMail.php',
386384
'DifferentialDiffCreateController' => 'applications/differential/controller/DifferentialDiffCreateController.php',
387385
'DifferentialDiffProperty' => 'applications/differential/storage/DifferentialDiffProperty.php',
388386
'DifferentialDiffQuery' => 'applications/differential/query/DifferentialDiffQuery.php',
@@ -436,7 +434,6 @@
436434
'DifferentialMailPhase' => 'applications/differential/constants/DifferentialMailPhase.php',
437435
'DifferentialManiphestTasksField' => 'applications/differential/customfield/DifferentialManiphestTasksField.php',
438436
'DifferentialManiphestTasksFieldSpecification' => 'applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php',
439-
'DifferentialNewDiffMail' => 'applications/differential/mail/DifferentialNewDiffMail.php',
440437
'DifferentialPHIDTypeDiff' => 'applications/differential/phid/DifferentialPHIDTypeDiff.php',
441438
'DifferentialPHIDTypeRevision' => 'applications/differential/phid/DifferentialPHIDTypeRevision.php',
442439
'DifferentialParseCacheGarbageCollector' => 'applications/differential/garbagecollector/DifferentialParseCacheGarbageCollector.php',
@@ -456,7 +453,6 @@
456453
'DifferentialResultsTableView' => 'applications/differential/view/DifferentialResultsTableView.php',
457454
'DifferentialRevertPlanField' => 'applications/differential/customfield/DifferentialRevertPlanField.php',
458455
'DifferentialRevertPlanFieldSpecification' => 'applications/differential/field/specification/DifferentialRevertPlanFieldSpecification.php',
459-
'DifferentialReviewRequestMail' => 'applications/differential/mail/DifferentialReviewRequestMail.php',
460456
'DifferentialReviewedByField' => 'applications/differential/customfield/DifferentialReviewedByField.php',
461457
'DifferentialReviewedByFieldSpecification' => 'applications/differential/field/specification/DifferentialReviewedByFieldSpecification.php',
462458
'DifferentialReviewer' => 'applications/differential/storage/DifferentialReviewer.php',
@@ -2910,7 +2906,6 @@
29102906
'DifferentialBlameRevisionFieldSpecification' => 'DifferentialFieldSpecification',
29112907
'DifferentialBranchField' => 'DifferentialCustomField',
29122908
'DifferentialBranchFieldSpecification' => 'DifferentialFieldSpecification',
2913-
'DifferentialCCWelcomeMail' => 'DifferentialReviewRequestMail',
29142909
'DifferentialCCsFieldSpecification' => 'DifferentialFieldSpecification',
29152910
'DifferentialCapabilityDefaultView' => 'PhabricatorPolicyCapability',
29162911
'DifferentialChangeset' => 'DifferentialDAO',
@@ -2957,7 +2952,6 @@
29572952
1 => 'PhabricatorPolicyInterface',
29582953
2 => 'HarbormasterBuildableInterface',
29592954
),
2960-
'DifferentialDiffContentMail' => 'DifferentialMail',
29612955
'DifferentialDiffCreateController' => 'DifferentialController',
29622956
'DifferentialDiffProperty' => 'DifferentialDAO',
29632957
'DifferentialDiffQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
@@ -3004,7 +2998,6 @@
30042998
'DifferentialMail' => 'PhabricatorMail',
30052999
'DifferentialManiphestTasksField' => 'DifferentialCoreCustomField',
30063000
'DifferentialManiphestTasksFieldSpecification' => 'DifferentialFieldSpecification',
3007-
'DifferentialNewDiffMail' => 'DifferentialReviewRequestMail',
30083001
'DifferentialPHIDTypeDiff' => 'PhabricatorPHIDType',
30093002
'DifferentialPHIDTypeRevision' => 'PhabricatorPHIDType',
30103003
'DifferentialParseCacheGarbageCollector' => 'PhabricatorGarbageCollector',
@@ -3023,7 +3016,6 @@
30233016
'DifferentialResultsTableView' => 'AphrontView',
30243017
'DifferentialRevertPlanField' => 'DifferentialStoredCustomField',
30253018
'DifferentialRevertPlanFieldSpecification' => 'DifferentialFieldSpecification',
3026-
'DifferentialReviewRequestMail' => 'DifferentialMail',
30273019
'DifferentialReviewedByField' => 'DifferentialCoreCustomField',
30283020
'DifferentialReviewedByFieldSpecification' => 'DifferentialFieldSpecification',
30293021
'DifferentialReviewersField' => 'DifferentialCoreCustomField',

‎src/applications/differential/editor/DifferentialTransactionEditor.php

+66
Original file line numberDiff line numberDiff line change
@@ -1019,6 +1019,46 @@ protected function buildMailBody(
10191019
pht('REVISION DETAIL'),
10201020
PhabricatorEnv::getProductionURI('/D'.$object->getID()));
10211021

1022+
$update_xaction = null;
1023+
foreach ($xactions as $xaction) {
1024+
switch ($xaction->getTransactionType()) {
1025+
case DifferentialTransaction::TYPE_UPDATE:
1026+
$update_xaction = $xaction;
1027+
break;
1028+
}
1029+
}
1030+
1031+
if ($update_xaction) {
1032+
$diff = $this->loadDiff($update_xaction->getNewValue(), true);
1033+
1034+
$body->addTextSection(
1035+
pht('AFFECTED FILES'),
1036+
$this->renderAffectedFilesForMail($diff));
1037+
1038+
$config_key_inline = 'metamta.differential.inline-patches';
1039+
$config_inline = PhabricatorEnv::getEnvConfig($config_key_inline);
1040+
1041+
$config_key_attach = 'metamta.differential.attach-patches';
1042+
$config_attach = PhabricatorEnv::getEnvConfig($config_key_attach);
1043+
1044+
if ($config_inline || $config_attach) {
1045+
$patch = $this->renderPatchForMail($diff);
1046+
$lines = count(phutil_split_lines($patch));
1047+
1048+
if ($config_inline && ($lines <= $config_inline)) {
1049+
$body->addTextSection(
1050+
pht('CHANGE DETAILS'),
1051+
$patch);
1052+
}
1053+
1054+
if ($config_attach) {
1055+
$name = pht('D%s.%s.patch', $object->getID(), $diff->getID());
1056+
$mime_type = 'text/x-patch; charset=utf-8';
1057+
$body->addAttachment(
1058+
new PhabricatorMetaMTAAttachment($patch, $name, $mime_type));
1059+
}
1060+
}
1061+
}
10221062

10231063
return $body;
10241064
}
@@ -1491,4 +1531,30 @@ private function updateRevisionHashTable(
14911531
}
14921532
}
14931533

1534+
private function renderAffectedFilesForMail(DifferentialDiff $diff) {
1535+
$changesets = $diff->getChangesets();
1536+
1537+
$filenames = mpull($changesets, 'getDisplayFilename');
1538+
sort($filenames);
1539+
1540+
$count = count($filenames);
1541+
$max = 250;
1542+
if ($count > $max) {
1543+
$filenames = array_slice($filenames, 0, $max);
1544+
$filenames[] = pht('(%d more files...)', ($count - $max));
1545+
}
1546+
1547+
return implode("\n", $filenames);
1548+
}
1549+
1550+
private function renderPatchForMail(DifferentialDiff $diff) {
1551+
$format = PhabricatorEnv::getEnvConfig('metamta.differential.patch-format');
1552+
1553+
return id(new DifferentialRawDiffRenderer())
1554+
->setViewer($this->getActor())
1555+
->setFormat($format)
1556+
->setChangesets($diff->getChangesets())
1557+
->buildPatch();
1558+
}
1559+
14941560
}

‎src/applications/differential/field/specification/DifferentialArcanistProjectFieldSpecification.php

-14
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,4 @@ private function getArcanistProjectPHID() {
3535
return $diff->getArcanistProjectPHID();
3636
}
3737

38-
public function renderValueForMail($phase) {
39-
$diff = $this->getRevision()->loadActiveDiff();
40-
if ($diff) {
41-
$phid = $diff->getArcanistProjectPHID();
42-
if ($phid) {
43-
$handle = id(new PhabricatorHandleQuery())
44-
->setViewer($this->getUser())
45-
->withPHIDs(array($phid))
46-
->executeOne();
47-
return "ARCANIST PROJECT\n ".$handle->getName();
48-
}
49-
}
50-
}
51-
5238
}

‎src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php

-12
Original file line numberDiff line numberDiff line change
@@ -31,16 +31,4 @@ public function renderValueForRevisionView() {
3131
return $this->getBranchOrBookmarkDescription($diff);
3232
}
3333

34-
public function renderValueForMail($phase) {
35-
$diff = $this->getRevision()->loadActiveDiff();
36-
if ($diff) {
37-
$description = $this->getBranchOrBookmarkDescription($diff);
38-
if ($description) {
39-
return "BRANCH\n {$description}";
40-
}
41-
}
42-
43-
return null;
44-
}
45-
4634
}

‎src/applications/differential/field/specification/DifferentialCommitsFieldSpecification.php

-26
Original file line numberDiff line numberDiff line change
@@ -34,30 +34,4 @@ private function getCommitPHIDs() {
3434
return $revision->getCommitPHIDs();
3535
}
3636

37-
public function renderValueForMail($phase) {
38-
$revision = $this->getRevision();
39-
40-
if ($revision->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED) {
41-
return null;
42-
}
43-
44-
$phids = $revision->loadCommitPHIDs();
45-
if (!$phids) {
46-
return null;
47-
}
48-
49-
$body = array();
50-
$handles = id(new PhabricatorHandleQuery())
51-
->setViewer($this->getUser())
52-
->withPHIDs($phids)
53-
->execute();
54-
$body[] = pht('COMMIT(S)', count($handles));
55-
56-
foreach ($handles as $handle) {
57-
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
58-
}
59-
60-
return implode("\n", $body);
61-
}
62-
6337
}

‎src/applications/differential/field/specification/DifferentialFieldSpecification.php

-17
Original file line numberDiff line numberDiff line change
@@ -385,23 +385,6 @@ public function renderValueForDiffView() {
385385
}
386386

387387

388-
/* -( Extending the E-mail Interface )------------------------------------- */
389-
390-
391-
/**
392-
* Return plain text to render in e-mail messages. The text may span
393-
* multiple lines.
394-
*
395-
* @return int One of DifferentialMailPhase constants.
396-
* @return string|null Plain text, or null for no message.
397-
*
398-
* @task mail
399-
*/
400-
public function renderValueForMail($phase) {
401-
return null;
402-
}
403-
404-
405388
/* -( Extending the Conduit Interface )------------------------------------ */
406389

407390

‎src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php

-28
Original file line numberDiff line numberDiff line change
@@ -127,32 +127,4 @@ public function parseValueFromCommitMessage($value) {
127127
return $task_phids;
128128
}
129129

130-
public function renderValueForMail($phase) {
131-
if ($phase == DifferentialMailPhase::COMMENT) {
132-
return null;
133-
}
134-
135-
if (!$this->maniphestTasks) {
136-
return null;
137-
}
138-
139-
$handles = id(new PhabricatorHandleQuery())
140-
->setViewer($this->getUser())
141-
->withPHIDs($this->maniphestTasks)
142-
->execute();
143-
$body = array();
144-
$body[] = 'MANIPHEST TASKS';
145-
foreach ($handles as $handle) {
146-
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
147-
}
148-
return implode("\n", $body);
149-
}
150-
151-
public function getCommitMessageTips() {
152-
return array(
153-
'Use "Fixes T123" in your summary to mark that the current '.
154-
'revision completes a given task.'
155-
);
156-
}
157-
158130
}

‎src/applications/differential/field/specification/DifferentialReviewersFieldSpecification.php

-21
Original file line numberDiff line numberDiff line change
@@ -173,25 +173,4 @@ public function getRequiredHandlePHIDsForRevisionList(
173173
return $revision->getReviewers();
174174
}
175175

176-
public function renderValueForMail($phase) {
177-
if ($phase == DifferentialMailPhase::COMMENT) {
178-
return null;
179-
}
180-
181-
if (!$this->reviewers) {
182-
return null;
183-
}
184-
185-
$handles = id(new PhabricatorHandleQuery())
186-
->setViewer($this->getUser())
187-
->withPHIDs($this->reviewers)
188-
->execute();
189-
$handles = array_select_keys(
190-
$handles,
191-
array($this->getRevision()->getPrimaryReviewer())) + $handles;
192-
193-
$names = mpull($handles, 'getObjectName');
194-
return 'Reviewers: '.implode(', ', $names);
195-
}
196-
197176
}

‎src/applications/differential/field/specification/DifferentialRevisionIDFieldSpecification.php

-21
Original file line numberDiff line numberDiff line change
@@ -96,25 +96,4 @@ public function renderValueForRevisionList(DifferentialRevision $revision) {
9696
return 'D'.$revision->getID();
9797
}
9898

99-
public function renderValueForMail($phase) {
100-
$body = array();
101-
$body[] = 'REVISION DETAIL';
102-
$body[] = ' '.PhabricatorEnv::getProductionURI('/D'.$this->id);
103-
104-
if ($phase == DifferentialMailPhase::UPDATE) {
105-
$diffs = id(new DifferentialDiff())->loadAllWhere(
106-
'revisionID = %d ORDER BY id DESC LIMIT 2',
107-
$this->id);
108-
if (count($diffs) == 2) {
109-
list($new, $old) = array_values(mpull($diffs, 'getID'));
110-
$body[] = null;
111-
$body[] = 'CHANGE SINCE LAST DIFF';
112-
$body[] = ' '.PhabricatorEnv::getProductionURI(
113-
"/D{$this->id}?vs={$old}&id={$new}#toc");
114-
}
115-
}
116-
117-
return implode("\n", $body);
118-
}
119-
12099
}

‎src/applications/differential/field/specification/DifferentialSummaryFieldSpecification.php

-12
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ public function parseValueFromCommitMessage($value) {
6767
return (string)$value;
6868
}
6969

70-
public function renderValueForMail($phase) {
71-
if ($phase != DifferentialMailPhase::WELCOME) {
72-
return null;
73-
}
74-
75-
if ($this->summary == '') {
76-
return null;
77-
}
78-
79-
return $this->summary;
80-
}
81-
8270
public function shouldAddToSearchIndex() {
8371
return true;
8472
}

‎src/applications/differential/field/specification/DifferentialTestPlanFieldSpecification.php

-12
Original file line numberDiff line numberDiff line change
@@ -91,18 +91,6 @@ public function parseValueFromCommitMessage($value) {
9191
return $value;
9292
}
9393

94-
public function renderValueForMail($phase) {
95-
if ($phase != DifferentialMailPhase::WELCOME) {
96-
return null;
97-
}
98-
99-
if ($this->plan == '') {
100-
return null;
101-
}
102-
103-
return "TEST PLAN\n".preg_replace('/^/m', ' ', $this->plan);
104-
}
105-
10694
public function shouldAddToSearchIndex() {
10795
return true;
10896
}

‎src/applications/differential/mail/DifferentialCCWelcomeMail.php

-22
This file was deleted.

‎src/applications/differential/mail/DifferentialDiffContentMail.php

-19
This file was deleted.

0 commit comments

Comments
 (0)
Failed to load comments.