1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Drive Differential e-mail message by field specification

Summary: Refactoring before the actual change.

Test Plan: None yet.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Koolvin

Differential Revision: https://secure.phabricator.com/D2661
This commit is contained in:
vrana 2012-06-06 00:45:29 -07:00
parent 259638e900
commit 1406d6cdd0
7 changed files with 104 additions and 34 deletions

View file

@ -88,5 +88,26 @@ final class DifferentialDefaultFieldSelector
return array_values($map);
}
public function sortFieldsForMail(array $fields) {
assert_instances_of($fields, 'DifferentialFieldSpecification');
$map = array();
foreach ($fields as $field) {
$map[get_class($field)] = $field;
}
$map = array_select_keys(
$map,
array(
'DifferentialSummaryFieldSpecification',
'DifferentialTestPlanFieldSpecification',
'DifferentialRevisionIDFieldSpecification',
'DifferentialBranchFieldSpecification',
'DifferentialCommitsFieldSpecification',
)) + $map;
return array_values($map);
}
}

View file

@ -33,4 +33,9 @@ abstract class DifferentialFieldSelector {
return $fields;
}
public function sortFieldsForMail(array $fields) {
assert_instances_of($fields, 'DifferentialFieldSpecification');
return $fields;
}
}

View file

@ -38,4 +38,21 @@ final class DifferentialBranchFieldSpecification
return phutil_escape_html($branch);
}
public function renderValueForMail() {
$status = $this->getRevision()->getStatus();
if ($status != ArcanistDifferentialRevisionStatus::NEEDS_REVISION &&
$status != ArcanistDifferentialRevisionStatus::ACCEPTED) {
return null;
}
$diff = $this->getRevision()->loadActiveDiff();
if ($diff) {
$branch = $diff->getBranch();
if ($branch) {
return "BRANCH\n $branch";
}
}
}
}

View file

@ -1,7 +1,7 @@
<?php
/*
* Copyright 2011 Facebook, Inc.
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -50,4 +50,34 @@ final class DifferentialCommitsFieldSpecification
return $revision->getCommitPHIDs();
}
public function renderValueForMail() {
$revision = $this->getRevision();
if ($revision->getStatus() != ArcanistDifferentialRevisionStatus::CLOSED) {
return null;
}
$phids = $revision->loadCommitPHIDs();
if (!$phids) {
return null;
}
$body = array();
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
if (count($handles) == 1) {
$body[] = "COMMIT";
} else {
// This is unlikely to ever happen since we'll send this mail the
// first time we discover a commit, but it's not impossible if data
// was migrated, etc.
$body[] = "COMMITS";
}
foreach ($handles as $handle) {
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
}
return implode("\n", $body);
}
}

View file

@ -28,6 +28,7 @@
* @task edit Extending the Revision Edit Interface
* @task view Extending the Revision View Interface
* @task list Extending the Revision List Interface
* @task mail Extending the E-mail Interface
* @task conduit Extending the Conduit View Interface
* @task commit Extending Commit Messages
* @task load Loading Additional Data
@ -367,6 +368,22 @@ abstract class DifferentialFieldSpecification {
}
/* -( Extending the E-mail Interface )------------------------------------- */
/**
* Return plain text to render in e-mail messages. The text may span
* multiple lines.
*
* @return string|null Plain text, or null for no message.
*
* @task mail
*/
public function renderValueForMail() {
return null;
}
/* -( Extending the Conduit Interface )------------------------------------ */

View file

@ -104,4 +104,9 @@ final class DifferentialRevisionIDFieldSpecification
return 'D'.$revision->getID();
}
public function renderValueForMail() {
$uri = PhabricatorEnv::getProductionURI('/D'.$this->id);
return "REVISION DETAIL\n {$uri}";
}
}

View file

@ -161,40 +161,15 @@ final class DifferentialCommentMail extends DifferentialMail {
$body[] = null;
}
$body[] = $this->renderRevisionDetailLink();
$body[] = null;
$selector = DifferentialFieldSelector::newSelector();
$aux_fields = $selector->sortFieldsForMail(
$selector->getFieldSpecifications());
$revision = $this->getRevision();
$status = $revision->getStatus();
if ($status == ArcanistDifferentialRevisionStatus::NEEDS_REVISION ||
$status == ArcanistDifferentialRevisionStatus::ACCEPTED) {
$diff = $revision->loadActiveDiff();
if ($diff) {
$branch = $diff->getBranch();
if ($branch) {
$body[] = "BRANCH\n $branch";
$body[] = null;
}
}
}
if ($status == ArcanistDifferentialRevisionStatus::CLOSED) {
$phids = $revision->loadCommitPHIDs();
if ($phids) {
$handles = id(new PhabricatorObjectHandleData($phids))->loadHandles();
if (count($handles) == 1) {
$body[] = "COMMIT";
} else {
// This is unlikely to ever happen since we'll send this mail the
// first time we discover a commit, but it's not impossible if data
// was migrated, etc.
$body[] = "COMMITS";
}
foreach ($handles as $handle) {
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
}
foreach ($aux_fields as $field) {
$field->setRevision($this->getRevision());
$text = $field->renderValueForMail();
if ($text !== null) {
$body[] = $text;
$body[] = null;
}
}