mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-10 08:52:39 +01:00
Add Differential and Herald mail stamps and some refinements
Summary: Ref T13053. Adds revision stamps (status, reviewers, etc). Adds Herald rule stamps, like the existing X-Herald-Rules header. Removes the "self" stamps, since you can just write a rule against `whatever(@epriestley)` equivalently. If there's routing logic around this, it can live in the routing layer. This avoids tons of self-actor, self-mention, self-reviewer, self-blocking-reviewer, self-resigned-reviewer, etc., stamps. Use `natcasesort()` instead of `sort()` so that numeric values (like monograms) sort `9, 80, 700` instead of `700, 80, 9`. Remove the commas from rendering since they don't really add anything. Test Plan: Edited tasks and revisions, looked at mail stamps, saw stamps that looked pretty reasonable (with no more self stuff, no more commas, sorting numbers, and Herald stamps). Reviewers: amckinley Reviewed By: amckinley Maniphest Tasks: T13053 Differential Revision: https://secure.phabricator.com/D18997
This commit is contained in:
parent
7d475eb09a
commit
1bf64e5cbc
9 changed files with 131 additions and 57 deletions
|
@ -487,6 +487,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialLintField' => 'applications/differential/customfield/DifferentialLintField.php',
|
||||
'DifferentialLintStatus' => 'applications/differential/constants/DifferentialLintStatus.php',
|
||||
'DifferentialLocalCommitsView' => 'applications/differential/view/DifferentialLocalCommitsView.php',
|
||||
'DifferentialMailEngineExtension' => 'applications/differential/engineextension/DifferentialMailEngineExtension.php',
|
||||
'DifferentialMailView' => 'applications/differential/mail/DifferentialMailView.php',
|
||||
'DifferentialManiphestTasksField' => 'applications/differential/customfield/DifferentialManiphestTasksField.php',
|
||||
'DifferentialModernHunk' => 'applications/differential/storage/DifferentialModernHunk.php',
|
||||
|
@ -4402,7 +4403,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorVersionedDraft' => 'applications/draft/storage/PhabricatorVersionedDraft.php',
|
||||
'PhabricatorVeryWowEnglishTranslation' => 'infrastructure/internationalization/translation/PhabricatorVeryWowEnglishTranslation.php',
|
||||
'PhabricatorViewerDatasource' => 'applications/people/typeahead/PhabricatorViewerDatasource.php',
|
||||
'PhabricatorViewerMailStamp' => 'applications/metamta/stamp/PhabricatorViewerMailStamp.php',
|
||||
'PhabricatorWatcherHasObjectEdgeType' => 'applications/transactions/edges/PhabricatorWatcherHasObjectEdgeType.php',
|
||||
'PhabricatorWebContentSource' => 'infrastructure/contentsource/PhabricatorWebContentSource.php',
|
||||
'PhabricatorWebServerSetupCheck' => 'applications/config/check/PhabricatorWebServerSetupCheck.php',
|
||||
|
@ -5612,6 +5612,7 @@ phutil_register_library_map(array(
|
|||
'DifferentialLintField' => 'DifferentialHarbormasterField',
|
||||
'DifferentialLintStatus' => 'Phobject',
|
||||
'DifferentialLocalCommitsView' => 'AphrontView',
|
||||
'DifferentialMailEngineExtension' => 'PhabricatorMailEngineExtension',
|
||||
'DifferentialMailView' => 'Phobject',
|
||||
'DifferentialManiphestTasksField' => 'DifferentialCoreCustomField',
|
||||
'DifferentialModernHunk' => 'DifferentialHunk',
|
||||
|
@ -10152,7 +10153,6 @@ phutil_register_library_map(array(
|
|||
'PhabricatorVersionedDraft' => 'PhabricatorDraftDAO',
|
||||
'PhabricatorVeryWowEnglishTranslation' => 'PhutilTranslation',
|
||||
'PhabricatorViewerDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorViewerMailStamp' => 'PhabricatorMailStamp',
|
||||
'PhabricatorWatcherHasObjectEdgeType' => 'PhabricatorEdgeType',
|
||||
'PhabricatorWebContentSource' => 'PhabricatorContentSource',
|
||||
'PhabricatorWebServerSetupCheck' => 'PhabricatorSetupCheck',
|
||||
|
|
|
@ -0,0 +1,80 @@
|
|||
<?php
|
||||
|
||||
final class DifferentialMailEngineExtension
|
||||
extends PhabricatorMailEngineExtension {
|
||||
|
||||
const EXTENSIONKEY = 'differential';
|
||||
|
||||
public function supportsObject($object) {
|
||||
return ($object instanceof DifferentialRevision);
|
||||
}
|
||||
|
||||
public function newMailStampTemplates($object) {
|
||||
return array(
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('author')
|
||||
->setLabel(pht('Author')),
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('reviewer')
|
||||
->setLabel(pht('Reviewer')),
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('blocking-reviewer')
|
||||
->setLabel(pht('Reviewer')),
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('resigned-reviewer')
|
||||
->setLabel(pht('Reviewer')),
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('revision-repository')
|
||||
->setLabel(pht('Revision Repository')),
|
||||
id(new PhabricatorPHIDMailStamp())
|
||||
->setKey('revision-status')
|
||||
->setLabel(pht('Revision Status')),
|
||||
);
|
||||
}
|
||||
|
||||
public function newMailStamps($object, array $xactions) {
|
||||
$editor = $this->getEditor();
|
||||
$viewer = $this->getViewer();
|
||||
|
||||
$revision = id(new DifferentialRevisionQuery())
|
||||
->setViewer($viewer)
|
||||
->needReviewers(true)
|
||||
->withPHIDs(array($object->getPHID()))
|
||||
->executeOne();
|
||||
|
||||
$reviewers = array();
|
||||
$blocking = array();
|
||||
$resigned = array();
|
||||
foreach ($revision->getReviewers() as $reviewer) {
|
||||
$reviewer_phid = $reviewer->getReviewerPHID();
|
||||
|
||||
if ($reviewer->isResigned()) {
|
||||
$resigned[] = $reviewer_phid;
|
||||
} else {
|
||||
$reviewers[] = $reviewer_phid;
|
||||
if ($reviewer->isBlocking()) {
|
||||
$reviewers[] = $blocking;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$this->getMailStamp('author')
|
||||
->setValue($revision->getAuthorPHID());
|
||||
|
||||
$this->getMailStamp('reviewer')
|
||||
->setValue($reviewers);
|
||||
|
||||
$this->getMailStamp('blocking-reviewer')
|
||||
->setValue($blocking);
|
||||
|
||||
$this->getMailStamp('resigned-reviewer')
|
||||
->setValue($resigned);
|
||||
|
||||
$this->getMailStamp('revision-repository')
|
||||
->setValue($revision->getRepositoryPHID());
|
||||
|
||||
$this->getMailStamp('revision-status')
|
||||
->setValue($revision->getModernRevisionStatus());
|
||||
}
|
||||
|
||||
}
|
|
@ -69,6 +69,11 @@ final class DifferentialReviewer
|
|||
return ($this->getReviewerStatus() == $status_resigned);
|
||||
}
|
||||
|
||||
public function isBlocking() {
|
||||
$status_blocking = DifferentialReviewerStatus::STATUS_BLOCKING;
|
||||
return ($this->getReviewerStatus() == $status_blocking);
|
||||
}
|
||||
|
||||
public function isRejected($diff_phid) {
|
||||
$status_rejected = DifferentialReviewerStatus::STATUS_REJECTED;
|
||||
|
||||
|
|
|
@ -70,14 +70,14 @@ final class PhabricatorMailTarget extends Phobject {
|
|||
$body .= "\n";
|
||||
$body .= pht('STAMPS');
|
||||
$body .= "\n";
|
||||
$body .= implode(', ', $stamps);
|
||||
$body .= implode(' ', $stamps);
|
||||
$body .= "\n";
|
||||
|
||||
if ($has_html) {
|
||||
$html = array();
|
||||
$html[] = phutil_tag('strong', array(), pht('STAMPS'));
|
||||
$html[] = phutil_tag('br');
|
||||
$html[] = phutil_implode_html(', ', $stamps);
|
||||
$html[] = phutil_implode_html(' ', $stamps);
|
||||
$html[] = phutil_tag('br');
|
||||
$html = phutil_tag('div', array(), $html);
|
||||
$html_body .= hsprintf('%s', $html);
|
||||
|
|
|
@ -6,11 +6,21 @@ final class PhabricatorStringMailStamp
|
|||
const STAMPTYPE = 'string';
|
||||
|
||||
public function renderStamps($value) {
|
||||
if (!strlen($value)) {
|
||||
if ($value === null || $value === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->renderStamp($this->getKey(), $value);
|
||||
$value = (array)$value;
|
||||
if (!$value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$results = array();
|
||||
foreach ($value as $v) {
|
||||
$results[] = $this->renderStamp($this->getKey(), $v);
|
||||
}
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorViewerMailStamp
|
||||
extends PhabricatorMailStamp {
|
||||
|
||||
const STAMPTYPE = 'viewer';
|
||||
|
||||
public function renderStamps($value) {
|
||||
// If we're sending one mail to everyone, we never include viewer-based
|
||||
// stamps since they'll only be accurate for one recipient. Recipients
|
||||
// can still use the corresponding stamps with their usernames or PHIDs.
|
||||
if (!PhabricatorMetaMTAMail::shouldMailEachRecipient()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$viewer_phid = $this->getViewer()->getPHID();
|
||||
if (!$viewer_phid) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!$value) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$value = (array)$value;
|
||||
$value = array_fuse($value);
|
||||
|
||||
if (!isset($value[$viewer_phid])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->renderStamp($this->getKey());
|
||||
}
|
||||
|
||||
}
|
|
@ -41,9 +41,11 @@ final class PhabricatorRepositoryRepositoryPHIDType
|
|||
$name = $repository->getName();
|
||||
$uri = $repository->getURI();
|
||||
|
||||
$handle->setName($monogram);
|
||||
$handle->setFullName("{$monogram} {$name}");
|
||||
$handle->setURI($uri);
|
||||
$handle
|
||||
->setName($monogram)
|
||||
->setFullName("{$monogram} {$name}")
|
||||
->setURI($uri)
|
||||
->setMailStampName($monogram);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -205,6 +205,25 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
return $this->mustEncrypt;
|
||||
}
|
||||
|
||||
public function getHeraldRuleMonograms() {
|
||||
// Convert the stored "<123>, <456>" string into a list: "H123", "H456".
|
||||
$list = $this->heraldHeader;
|
||||
$list = preg_split('/[, ]+/', $list);
|
||||
|
||||
foreach ($list as $key => $item) {
|
||||
$item = trim($item, '<>');
|
||||
|
||||
if (!is_numeric($item)) {
|
||||
unset($list[$key]);
|
||||
continue;
|
||||
}
|
||||
|
||||
$list[$key] = 'H'.$item;
|
||||
}
|
||||
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function setIsInverseEdgeEditor($is_inverse_edge_editor) {
|
||||
$this->isInverseEdgeEditor = $is_inverse_edge_editor;
|
||||
return $this;
|
||||
|
@ -4109,7 +4128,7 @@ abstract class PhabricatorApplicationTransactionEditor
|
|||
}
|
||||
}
|
||||
|
||||
sort($results);
|
||||
natcasesort($results);
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
|
|
@ -36,13 +36,9 @@ final class PhabricatorEditorMailEngineExtension
|
|||
->setKey('mention')
|
||||
->setLabel(pht('Mentioned User'));
|
||||
|
||||
$templates[] = id(new PhabricatorViewerMailStamp())
|
||||
->setKey('self-actor')
|
||||
->setLabel(pht('You Acted'));
|
||||
|
||||
$templates[] = id(new PhabricatorViewerMailStamp())
|
||||
->setKey('self-mention')
|
||||
->setLabel(pht('You Were Mentioned'));
|
||||
$templates[] = id(new PhabricatorStringMailStamp())
|
||||
->setKey('herald')
|
||||
->setLabel(pht('Herald Rule'));
|
||||
|
||||
return $templates;
|
||||
}
|
||||
|
@ -71,11 +67,8 @@ final class PhabricatorEditorMailEngineExtension
|
|||
$this->getMailStamp('mention')
|
||||
->setValue($mentioned_phids);
|
||||
|
||||
$this->getMailStamp('self-actor')
|
||||
->setValue($editor->getActingAsPHID());
|
||||
|
||||
$this->getMailStamp('self-mention')
|
||||
->setValue($mentioned_phids);
|
||||
$this->getMailStamp('herald')
|
||||
->setValue($editor->getHeraldRuleMonograms());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue