2011-01-26 02:17:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
2012-01-10 20:39:11 +01:00
|
|
|
* Copyright 2012 Facebook, Inc.
|
2011-01-26 02:17:19 +01:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2012-03-13 19:18:11 +01:00
|
|
|
final class DifferentialCommentMail extends DifferentialMail {
|
2011-01-26 02:17:19 +01:00
|
|
|
|
|
|
|
protected $changedByCommit;
|
|
|
|
|
2012-06-16 08:21:25 +02:00
|
|
|
private $addedReviewers;
|
|
|
|
private $addedCCs;
|
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
public function setChangedByCommit($changed_by_commit) {
|
|
|
|
$this->changedByCommit = $changed_by_commit;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getChangedByCommit() {
|
|
|
|
return $this->changedByCommit;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
DifferentialRevision $revision,
|
2011-02-09 18:58:48 +01:00
|
|
|
PhabricatorObjectHandle $actor,
|
2011-01-30 21:08:40 +01:00
|
|
|
DifferentialComment $comment,
|
2011-01-26 02:17:19 +01:00
|
|
|
array $changesets,
|
|
|
|
array $inline_comments) {
|
2012-04-04 22:13:08 +02:00
|
|
|
assert_instances_of($changesets, 'DifferentialChangeset');
|
|
|
|
assert_instances_of($inline_comments, 'PhabricatorInlineCommentInterface');
|
2011-01-26 02:17:19 +01:00
|
|
|
|
|
|
|
$this->setRevision($revision);
|
2011-02-09 18:58:48 +01:00
|
|
|
$this->setActorHandle($actor);
|
2011-01-30 21:08:40 +01:00
|
|
|
$this->setComment($comment);
|
2011-01-26 02:17:19 +01:00
|
|
|
$this->setChangesets($changesets);
|
|
|
|
$this->setInlineComments($inline_comments);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
Add email preferences to receive fewer less-important notifications
Summary:
A few similar requests have come in across several tools and use cases that I
think this does a reasonable job of resolving.
We currently send one email for each update an object receives, but these aren't
always appreciated:
- Asana does post-commit review via Differential, so the "committed" mails are
useless.
- Quora wants to make project category edits to bugs without spamming people
attached to them.
- Some users in general are very sensitive to email volumes, and this gives us
a good way to reduce the volumes without incurring the complexity of
delayed-send-batching.
The technical mechanism is basically:
- Mail may optionally have "mail tags", which indicate content in the mail
(e.g., "maniphest-priority, maniphest-cc, maniphest-comment" for a mail which
contains a priority change, a CC change, and a comment).
- If a mail has tags, remove any recipients who have opted out of all the
tags.
- Some tags can't be opted out of via the UI, so this ensures that important
email is still delivered (e.g., cc + assign + comment is always delivered
because you can't opt out of "assign" or "comment").
Test Plan:
- Disabled all mail tags in the web UI.
- Used test console to send myself mail with an opt-outable tag, it was
immediately dropped.
- Used test console to send myself mail with an opt-outable tag and a custom
tag, it was delivered.
- Made Differential updates affecting CCs with and without comments, got
appropriate delivery.
- Made Maniphest updates affecting project, priority and CCs with and without
comments, got appropriate delivery.
- Verified mail headers in all cases.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley, moskov
Maniphest Tasks: T616, T855
Differential Revision: https://secure.phabricator.com/D1635
2012-02-18 07:57:07 +01:00
|
|
|
protected function getMailTags() {
|
|
|
|
$comment = $this->getComment();
|
|
|
|
$action = $comment->getAction();
|
|
|
|
|
|
|
|
$tags = array();
|
|
|
|
switch ($action) {
|
|
|
|
case DifferentialAction::ACTION_ADDCCS:
|
|
|
|
$tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_CC;
|
|
|
|
break;
|
2012-04-24 02:40:57 +02:00
|
|
|
case DifferentialAction::ACTION_CLOSE:
|
|
|
|
$tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_CLOSED;
|
Add email preferences to receive fewer less-important notifications
Summary:
A few similar requests have come in across several tools and use cases that I
think this does a reasonable job of resolving.
We currently send one email for each update an object receives, but these aren't
always appreciated:
- Asana does post-commit review via Differential, so the "committed" mails are
useless.
- Quora wants to make project category edits to bugs without spamming people
attached to them.
- Some users in general are very sensitive to email volumes, and this gives us
a good way to reduce the volumes without incurring the complexity of
delayed-send-batching.
The technical mechanism is basically:
- Mail may optionally have "mail tags", which indicate content in the mail
(e.g., "maniphest-priority, maniphest-cc, maniphest-comment" for a mail which
contains a priority change, a CC change, and a comment).
- If a mail has tags, remove any recipients who have opted out of all the
tags.
- Some tags can't be opted out of via the UI, so this ensures that important
email is still delivered (e.g., cc + assign + comment is always delivered
because you can't opt out of "assign" or "comment").
Test Plan:
- Disabled all mail tags in the web UI.
- Used test console to send myself mail with an opt-outable tag, it was
immediately dropped.
- Used test console to send myself mail with an opt-outable tag and a custom
tag, it was delivered.
- Made Differential updates affecting CCs with and without comments, got
appropriate delivery.
- Made Maniphest updates affecting project, priority and CCs with and without
comments, got appropriate delivery.
- Verified mail headers in all cases.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley, moskov
Maniphest Tasks: T616, T855
Differential Revision: https://secure.phabricator.com/D1635
2012-02-18 07:57:07 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strlen(trim($comment->getContent()))) {
|
|
|
|
switch ($action) {
|
2012-04-24 02:40:57 +02:00
|
|
|
case DifferentialAction::ACTION_CLOSE:
|
Add email preferences to receive fewer less-important notifications
Summary:
A few similar requests have come in across several tools and use cases that I
think this does a reasonable job of resolving.
We currently send one email for each update an object receives, but these aren't
always appreciated:
- Asana does post-commit review via Differential, so the "committed" mails are
useless.
- Quora wants to make project category edits to bugs without spamming people
attached to them.
- Some users in general are very sensitive to email volumes, and this gives us
a good way to reduce the volumes without incurring the complexity of
delayed-send-batching.
The technical mechanism is basically:
- Mail may optionally have "mail tags", which indicate content in the mail
(e.g., "maniphest-priority, maniphest-cc, maniphest-comment" for a mail which
contains a priority change, a CC change, and a comment).
- If a mail has tags, remove any recipients who have opted out of all the
tags.
- Some tags can't be opted out of via the UI, so this ensures that important
email is still delivered (e.g., cc + assign + comment is always delivered
because you can't opt out of "assign" or "comment").
Test Plan:
- Disabled all mail tags in the web UI.
- Used test console to send myself mail with an opt-outable tag, it was
immediately dropped.
- Used test console to send myself mail with an opt-outable tag and a custom
tag, it was delivered.
- Made Differential updates affecting CCs with and without comments, got
appropriate delivery.
- Made Maniphest updates affecting project, priority and CCs with and without
comments, got appropriate delivery.
- Verified mail headers in all cases.
Reviewers: btrahan
Reviewed By: btrahan
CC: aran, epriestley, moskov
Maniphest Tasks: T616, T855
Differential Revision: https://secure.phabricator.com/D1635
2012-02-18 07:57:07 +01:00
|
|
|
// Commit comments are auto-generated and not especially interesting,
|
|
|
|
// so don't tag them as having a comment.
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
$tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_COMMENT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $tags;
|
|
|
|
}
|
|
|
|
|
2012-06-11 21:21:37 +02:00
|
|
|
protected function renderVaryPrefix() {
|
2011-05-08 09:35:29 +02:00
|
|
|
$verb = ucwords($this->getVerb());
|
2012-06-11 21:21:37 +02:00
|
|
|
return "[{$verb}]";
|
2011-01-26 02:17:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function getVerb() {
|
2011-01-30 21:08:40 +01:00
|
|
|
$comment = $this->getComment();
|
|
|
|
$action = $comment->getAction();
|
|
|
|
$verb = DifferentialAction::getActionPastTenseVerb($action);
|
2011-01-26 02:17:19 +01:00
|
|
|
return $verb;
|
|
|
|
}
|
|
|
|
|
2012-06-16 08:21:25 +02:00
|
|
|
protected function prepareBody() {
|
|
|
|
parent::prepareBody();
|
2011-06-30 21:32:30 +02:00
|
|
|
|
|
|
|
// If the commented added reviewers or CCs, list them explicitly.
|
2012-06-16 08:21:25 +02:00
|
|
|
$meta = $this->getComment()->getMetadata();
|
2011-06-30 21:32:30 +02:00
|
|
|
$m_reviewers = idx(
|
|
|
|
$meta,
|
|
|
|
DifferentialComment::METADATA_ADDED_REVIEWERS,
|
|
|
|
array());
|
|
|
|
$m_cc = idx(
|
|
|
|
$meta,
|
|
|
|
DifferentialComment::METADATA_ADDED_CCS,
|
|
|
|
array());
|
|
|
|
$load = array_merge($m_reviewers, $m_cc);
|
|
|
|
if ($load) {
|
|
|
|
$handles = id(new PhabricatorObjectHandleData($load))->loadHandles();
|
|
|
|
if ($m_reviewers) {
|
2012-06-16 08:21:25 +02:00
|
|
|
$this->addedReviewers = $this->renderHandleList($handles, $m_reviewers);
|
2011-06-30 21:32:30 +02:00
|
|
|
}
|
|
|
|
if ($m_cc) {
|
2012-06-16 08:21:25 +02:00
|
|
|
$this->addedCCs = $this->renderHandleList($handles, $m_cc);
|
2011-06-30 21:32:30 +02:00
|
|
|
}
|
|
|
|
}
|
2012-06-16 08:21:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderBody() {
|
|
|
|
|
|
|
|
$comment = $this->getComment();
|
|
|
|
|
|
|
|
$actor = $this->getActorName();
|
|
|
|
$name = $this->getRevision()->getTitle();
|
|
|
|
$verb = $this->getVerb();
|
|
|
|
|
|
|
|
$body = array();
|
|
|
|
|
|
|
|
$body[] = "{$actor} has {$verb} the revision \"{$name}\".";
|
|
|
|
|
|
|
|
if ($this->addedReviewers) {
|
|
|
|
$body[] = 'Added Reviewers: '.$this->addedReviewers;
|
|
|
|
}
|
|
|
|
if ($this->addedCCs) {
|
|
|
|
$body[] = 'Added CCs: '.$this->addedCCs;
|
|
|
|
}
|
2011-06-30 21:32:30 +02:00
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
$body[] = null;
|
|
|
|
|
2011-01-30 21:08:40 +01:00
|
|
|
$content = $comment->getContent();
|
2011-01-26 02:17:19 +01:00
|
|
|
if (strlen($content)) {
|
|
|
|
$body[] = $this->formatText($content);
|
|
|
|
$body[] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->getChangedByCommit()) {
|
|
|
|
$body[] = 'CHANGED PRIOR TO COMMIT';
|
2012-05-23 01:09:49 +02:00
|
|
|
$body[] = ' '.$this->getChangedByCommit();
|
2011-01-26 02:17:19 +01:00
|
|
|
$body[] = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$inlines = $this->getInlineComments();
|
|
|
|
if ($inlines) {
|
|
|
|
$body[] = 'INLINE COMMENTS';
|
|
|
|
$changesets = $this->getChangesets();
|
|
|
|
foreach ($inlines as $inline) {
|
|
|
|
$changeset = $changesets[$inline->getChangesetID()];
|
|
|
|
if (!$changeset) {
|
|
|
|
throw new Exception('Changeset missing!');
|
|
|
|
}
|
|
|
|
$file = $changeset->getFilename();
|
2011-02-20 00:06:22 +01:00
|
|
|
$start = $inline->getLineNumber();
|
|
|
|
$len = $inline->getLineLength();
|
|
|
|
if ($len) {
|
|
|
|
$range = $start.'-'.($start + $len);
|
|
|
|
} else {
|
|
|
|
$range = $start;
|
|
|
|
}
|
2011-01-26 02:17:19 +01:00
|
|
|
$content = $inline->getContent();
|
2011-02-20 00:06:22 +01:00
|
|
|
$body[] = $this->formatText("{$file}:{$range} {$content}");
|
2011-01-26 02:17:19 +01:00
|
|
|
}
|
|
|
|
$body[] = null;
|
|
|
|
}
|
|
|
|
|
2012-06-06 19:52:17 +02:00
|
|
|
$body[] = $this->renderAuxFields(DifferentialMailPhase::COMMENT);
|
2011-04-10 17:31:18 +02:00
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
return implode("\n", $body);
|
|
|
|
}
|
|
|
|
}
|