From e1ccd270faeab7d870e864c560f1d433d797103e Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 19 Mar 2012 19:56:37 -0700 Subject: [PATCH] Add inline comments to diffusion/audit emails Summary: Depends on D1929. In emails, notify recipients that inlines are attached. Vaguely copy/pastey from Differential but they only share like six lines and this seems like a random piece of code to pull out. Test Plan: Added inline comments, got email mentioning them Reviewers: davidreuss, nh, btrahan Reviewed By: davidreuss CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1930 --- .../comment/PhabricatorAuditCommentEditor.php | 40 +++++++++++++++++-- .../audit/editor/comment/__init__.php | 1 + 2 files changed, 37 insertions(+), 4 deletions(-) diff --git a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php index 1a8347ccc8..9360a76574 100644 --- a/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php +++ b/src/applications/audit/editor/comment/PhabricatorAuditCommentEditor.php @@ -120,7 +120,7 @@ final class PhabricatorAuditCommentEditor { $this->publishFeedStory($comment, array_keys($audit_phids)); PhabricatorSearchCommitIndexer::indexCommit($commit); - $this->sendMail($comment, $other_comments); + $this->sendMail($comment, $other_comments, $inline_comments); } @@ -189,7 +189,8 @@ final class PhabricatorAuditCommentEditor { private function sendMail( PhabricatorAuditComment $comment, - array $other_comments) { + array $other_comments, + array $inline_comments) { $commit = $this->commit; $data = $commit->loadCommitData(); @@ -221,7 +222,8 @@ final class PhabricatorAuditCommentEditor { $comment, "{$name}: {$summary}", $handle, - $reply_handler); + $reply_handler, + $inline_comments); $email_to = array(); @@ -276,7 +278,8 @@ final class PhabricatorAuditCommentEditor { PhabricatorAuditComment $comment, $cname, PhabricatorObjectHandle $handle, - PhabricatorMailReplyHandler $reply_handler) { + PhabricatorMailReplyHandler $reply_handler, + array $inline_comments) { $commit = $this->commit; $user = $this->user; @@ -292,8 +295,37 @@ final class PhabricatorAuditCommentEditor { $body[] = $comment->getContent(); } + if ($inline_comments) { + $block = array(); + + $path_map = id(new DiffusionPathQuery()) + ->withPathIDs(mpull($inline_comments, 'getPathID')) + ->execute(); + $path_map = ipull($path_map, 'path', 'id'); + + foreach ($inline_comments as $inline) { + $path = idx($path_map, $inline->getPathID()); + if ($path === null) { + continue; + } + + $start = $inline->getLineNumber(); + $len = $inline->getLineLength(); + if ($len) { + $range = $start.'-'.($start + $len); + } else { + $range = $start; + } + + $content = $inline->getContent(); + $block[] = "{$path}:{$range} {$content}"; + } + $body[] = "INLINE COMMENTS\n ".implode("\n ", $block); + } + $body[] = "COMMIT\n ".PhabricatorEnv::getProductionURI($handle->getURI()); + $reply_instructions = $reply_handler->getReplyHandlerInstructions(); if ($reply_instructions) { $body[] = "REPLY HANDLER ACTIONS\n ".$reply_instructions; diff --git a/src/applications/audit/editor/comment/__init__.php b/src/applications/audit/editor/comment/__init__.php index 2959e1378a..2610bb9286 100644 --- a/src/applications/audit/editor/comment/__init__.php +++ b/src/applications/audit/editor/comment/__init__.php @@ -10,6 +10,7 @@ phutil_require_module('phabricator', 'applications/audit/constants/action'); phutil_require_module('phabricator', 'applications/audit/constants/status'); phutil_require_module('phabricator', 'applications/audit/storage/auditcomment'); phutil_require_module('phabricator', 'applications/audit/storage/inlinecommment'); +phutil_require_module('phabricator', 'applications/diffusion/query/path'); phutil_require_module('phabricator', 'applications/feed/constants/story'); phutil_require_module('phabricator', 'applications/feed/publisher'); phutil_require_module('phabricator', 'applications/metamta/storage/mail');