From 83206242c9dd3327305d3ddc8c5910a4df0e7465 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 3 Mar 2014 08:36:40 -0800 Subject: [PATCH] Clean up some Differential behaviors Summary: Ref T2222. - Restore mail tags for ApplicationTransactions mail. - Restore subject line verbs. - Denormalize line count and repository PHID. - Fix an issue with the mailgun adapter where headers weren't attached properly. Test Plan: Sent some mail, verified it had correct subjects and tags. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2222 Differential Revision: https://secure.phabricator.com/D8378 --- .../editor/DifferentialTransactionEditor.php | 4 ++ .../storage/DifferentialTransaction.php | 63 +++++++++++++++++++ ...icatorMailImplementationMailgunAdapter.php | 5 ++ 3 files changed, 72 insertions(+) diff --git a/src/applications/differential/editor/DifferentialTransactionEditor.php b/src/applications/differential/editor/DifferentialTransactionEditor.php index c0208603c0..a21bbf9794 100644 --- a/src/applications/differential/editor/DifferentialTransactionEditor.php +++ b/src/applications/differential/editor/DifferentialTransactionEditor.php @@ -364,6 +364,10 @@ final class DifferentialTransactionEditor $diff->setRevisionID($object->getID()); $diff->save(); + + $object->setLineCount($diff->getLineCount()); + $object->setRepositoryPHID($diff->getRepositoryPHID()); + return; } diff --git a/src/applications/differential/storage/DifferentialTransaction.php b/src/applications/differential/storage/DifferentialTransaction.php index 61269ccff4..38f5e626ca 100644 --- a/src/applications/differential/storage/DifferentialTransaction.php +++ b/src/applications/differential/storage/DifferentialTransaction.php @@ -87,6 +87,69 @@ final class DifferentialTransaction extends PhabricatorApplicationTransaction { return $phids; } + public function getActionName() { + switch ($this->getTransactionType()) { + case self::TYPE_INLINE: + return pht('Commented On'); + case self::TYPE_UPDATE: + return pht('Updated'); + case self::TYPE_ACTION: + $map = array( + DifferentialAction::ACTION_ACCEPT => pht('Accepted'), + DifferentialAction::ACTION_REJECT => pht('Requested Changes To'), + DifferentialAction::ACTION_RETHINK => pht('Planned Changes To'), + DifferentialAction::ACTION_ABANDON => pht('Abandoned'), + DifferentialAction::ACTION_CLOSE => pht('Closed'), + DifferentialAction::ACTION_REQUEST => pht('Requested A Review Of'), + DifferentialAction::ACTION_RESIGN => pht('Resigned From'), + DifferentialAction::ACTION_ADDREVIEWERS => pht('Added Reviewers'), + DifferentialAction::ACTION_CLAIM => pht('Commandeered'), + DifferentialAction::ACTION_REOPEN => pht('Reopened'), + ); + $name = idx($map, $this->getNewValue()); + if ($name !== null) { + return $name; + } + break; + } + + return parent::getActionName(); + } + + public function getMailTags() { + $tags = array(); + + switch ($this->getTransactionType()) { + case PhabricatorTransactions::TYPE_SUBSCRIBERS; + $tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_CC; + break; + case self::TYPE_ACTION: + switch ($this->getNewValue()) { + case DifferentialAction::ACTION_CLOSE: + $tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_CLOSED; + break; + } + break; + case PhabricatorTransactions::TYPE_EDGE: + switch ($this->getMetadataValue('edge:type')) { + case PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER: + $tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_REVIEWERS; + break; + } + break; + case PhabricatorTransactions::TYPE_COMMENT: + case self::TYPE_INLINE: + $tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_COMMENT; + break; + } + + if (!$tags) { + $tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_OTHER; + } + + return $tags; + } + public function getTitle() { $author_phid = $this->getAuthorPHID(); $author_handle = $this->renderHandleLink($author_phid); diff --git a/src/applications/metamta/adapter/PhabricatorMailImplementationMailgunAdapter.php b/src/applications/metamta/adapter/PhabricatorMailImplementationMailgunAdapter.php index 030963e150..35d5e57e72 100644 --- a/src/applications/metamta/adapter/PhabricatorMailImplementationMailgunAdapter.php +++ b/src/applications/metamta/adapter/PhabricatorMailImplementationMailgunAdapter.php @@ -99,6 +99,11 @@ final class PhabricatorMailImplementationMailgunAdapter $params['cc'] = $this->params['ccs']; } + foreach (idx($this->params, 'headers', array()) as $header) { + list($name, $value) = $header; + $params['h:'.$name] = $value; + } + $future = new HTTPSFuture( "https://api:{$key}@api.mailgun.net/v2/{$domain}/messages", $params);