mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-20 13:52:40 +01:00
Make Diffusion Herald emails thread with Audit emails
Summary: - Users may elect to receive an initial notification about a commit; allow it to be replied to in order to interact with the object. - Share thread headers between emails. - Add the "REPLY HANDLER ACTIONS" section to both emails. Test Plan: - Used "reparse.php --herald" to trigger herald emails, verified reply-to and email body. - Made audit comments, verified body. Reviewers: btrahan Reviewed By: btrahan CC: aran, epriestley Maniphest Tasks: T904 Differential Revision: https://secure.phabricator.com/D1762
This commit is contained in:
parent
dd7eb969b3
commit
5590515007
3 changed files with 58 additions and 16 deletions
|
@ -185,14 +185,20 @@ final class PhabricatorAuditCommentEditor {
|
|||
);
|
||||
$verb = idx($map, $comment->getAction(), 'Commented On');
|
||||
|
||||
$reply_handler = self::newReplyHandlerForCommit($commit);
|
||||
|
||||
$prefix = PhabricatorEnv::getEnvConfig('metamta.diffusion.subject-prefix');
|
||||
$subject = "{$prefix} [{$verb}] {$name}: {$summary}";
|
||||
$thread_id = '<diffusion-audit-'.$commit->getPHID().'>';
|
||||
|
||||
$threading = self::getMailThreading($commit->getPHID());
|
||||
list($thread_id, $thread_topic) = $threading;
|
||||
|
||||
$is_new = !count($other_comments);
|
||||
$body = $this->renderMailBody(
|
||||
$comment,
|
||||
"{$name}: {$summary}",
|
||||
$handle);
|
||||
$handle,
|
||||
$reply_handler);
|
||||
|
||||
$email_to = array();
|
||||
|
||||
|
@ -212,14 +218,12 @@ final class PhabricatorAuditCommentEditor {
|
|||
$template = id(new PhabricatorMetaMTAMail())
|
||||
->setSubject($subject)
|
||||
->setFrom($comment->getActorPHID())
|
||||
->addHeader('Thread-Topic', 'Diffusion Audit '.$commit->getPHID())
|
||||
->setThreadID($thread_id, $is_new)
|
||||
->addHeader('Thread-Topic', $thread_topic)
|
||||
->setRelatedPHID($commit->getPHID())
|
||||
->setIsBulk(true)
|
||||
->setBody($body);
|
||||
|
||||
$reply_handler = self::newReplyHandlerForCommit($commit);
|
||||
|
||||
$mails = $reply_handler->multiplexMail(
|
||||
$template,
|
||||
array_select_keys($handles, $email_to),
|
||||
|
@ -230,6 +234,13 @@ final class PhabricatorAuditCommentEditor {
|
|||
}
|
||||
}
|
||||
|
||||
public static function getMailThreading($phid) {
|
||||
return array(
|
||||
'<diffusion-audit-'.$phid.'>',
|
||||
'Diffusion Audit '.$phid,
|
||||
);
|
||||
}
|
||||
|
||||
public static function newReplyHandlerForCommit($commit) {
|
||||
$handler_class = PhabricatorEnv::getEnvConfig(
|
||||
'metamta.diffusion.reply-handler');
|
||||
|
@ -241,7 +252,8 @@ final class PhabricatorAuditCommentEditor {
|
|||
private function renderMailBody(
|
||||
PhabricatorAuditComment $comment,
|
||||
$cname,
|
||||
PhabricatorObjectHandle $handle) {
|
||||
PhabricatorObjectHandle $handle,
|
||||
PhabricatorMailReplyHandler $reply_handler) {
|
||||
|
||||
$commit = $this->commit;
|
||||
$user = $this->user;
|
||||
|
@ -259,6 +271,11 @@ final class PhabricatorAuditCommentEditor {
|
|||
|
||||
$body[] = "COMMIT\n ".PhabricatorEnv::getProductionURI($handle->getURI());
|
||||
|
||||
$reply_instructions = $reply_handler->getReplyHandlerInstructions();
|
||||
if ($reply_instructions) {
|
||||
$body[] = "REPLY HANDLER ACTIONS\n ".$reply_instructions;
|
||||
}
|
||||
|
||||
return implode("\n\n", $body)."\n";
|
||||
}
|
||||
|
||||
|
|
|
@ -106,6 +106,18 @@ class PhabricatorRepositoryCommitHeraldWorker
|
|||
$why_uri = PhabricatorEnv::getProductionURI(
|
||||
'/herald/transcript/'.$xscript_id.'/');
|
||||
|
||||
$reply_handler = PhabricatorAuditCommentEditor::newReplyHandlerForCommit(
|
||||
$commit);
|
||||
|
||||
$reply_instructions = $reply_handler->getReplyHandlerInstructions();
|
||||
if ($reply_instructions) {
|
||||
$reply_instructions =
|
||||
"\n".
|
||||
"REPLY HANDLER ACTIONS\n".
|
||||
" ".$reply_instructions."\n";
|
||||
}
|
||||
|
||||
|
||||
$body = <<<EOBODY
|
||||
DESCRIPTION
|
||||
{$description}
|
||||
|
@ -118,7 +130,7 @@ DIFFERENTIAL REVISION
|
|||
|
||||
AFFECTED FILES
|
||||
{$files}
|
||||
|
||||
{$reply_instructions}
|
||||
MANAGE HERALD COMMIT RULES
|
||||
{$manage_uri}
|
||||
|
||||
|
@ -129,19 +141,31 @@ EOBODY;
|
|||
|
||||
$subject = "[Herald/Commit] {$commit_name} ({$who}){$name}";
|
||||
|
||||
$mailer = new PhabricatorMetaMTAMail();
|
||||
$mailer->setRelatedPHID($commit->getPHID());
|
||||
$mailer->addTos($email_phids);
|
||||
$mailer->setSubject($subject);
|
||||
$mailer->setBody($body);
|
||||
$mailer->setIsBulk(true);
|
||||
$threading = PhabricatorAuditCommentEditor::getMailThreading(
|
||||
$commit->getPHID());
|
||||
list($thread_id, $thread_topic) = $threading;
|
||||
|
||||
$mailer->addHeader('X-Herald-Rules', $xscript->getXHeraldRulesHeader());
|
||||
$template = new PhabricatorMetaMTAMail();
|
||||
$template->setRelatedPHID($commit->getPHID());
|
||||
$template->setSubject($subject);
|
||||
$template->setBody($body);
|
||||
$template->setThreadID($thread_id, $is_new = true);
|
||||
$template->addHeader('Thread-Topic', $thread_topic);
|
||||
$template->setIsBulk(true);
|
||||
|
||||
$template->addHeader('X-Herald-Rules', $xscript->getXHeraldRulesHeader());
|
||||
if ($author_phid) {
|
||||
$mailer->setFrom($author_phid);
|
||||
$template->setFrom($author_phid);
|
||||
}
|
||||
|
||||
$mailer->saveAndSend();
|
||||
$mails = $reply_handler->multiplexMail(
|
||||
$template,
|
||||
id(new PhabricatorObjectHandleData($email_phids))->loadHandles(),
|
||||
array());
|
||||
|
||||
foreach ($mails as $mail) {
|
||||
$mail->saveAndSend();
|
||||
}
|
||||
}
|
||||
|
||||
private function createAudits(
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
|
||||
phutil_require_module('phabricator', 'applications/audit/constants/status');
|
||||
phutil_require_module('phabricator', 'applications/audit/editor/comment');
|
||||
phutil_require_module('phabricator', 'applications/herald/adapter/commit');
|
||||
phutil_require_module('phabricator', 'applications/herald/config/contenttype');
|
||||
phutil_require_module('phabricator', 'applications/herald/engine/engine');
|
||||
|
|
Loading…
Reference in a new issue