2011-01-26 02:17:19 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2011-01-30 21:08:40 +01:00
|
|
|
class DifferentialCommentMail extends DifferentialMail {
|
2011-01-26 02:17:19 +01:00
|
|
|
|
|
|
|
protected $changedByCommit;
|
|
|
|
|
|
|
|
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) {
|
|
|
|
|
|
|
|
$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);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderSubject() {
|
2011-05-08 09:35:29 +02:00
|
|
|
$verb = ucwords($this->getVerb());
|
2011-01-26 02:17:19 +01:00
|
|
|
$revision = $this->getRevision();
|
2011-05-08 09:35:29 +02:00
|
|
|
$title = $revision->getTitle();
|
|
|
|
$id = $revision->getID();
|
|
|
|
$subject = "[{$verb}] D{$id}: {$title}";
|
|
|
|
return $subject;
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function renderBody() {
|
|
|
|
|
2011-01-30 21:08:40 +01:00
|
|
|
$comment = $this->getComment();
|
2011-01-26 02:17:19 +01:00
|
|
|
|
|
|
|
$actor = $this->getActorName();
|
2011-01-30 21:08:40 +01:00
|
|
|
$name = $this->getRevision()->getTitle();
|
2011-01-26 02:17:19 +01:00
|
|
|
$verb = $this->getVerb();
|
|
|
|
|
|
|
|
$body = array();
|
|
|
|
|
|
|
|
$body[] = "{$actor} has {$verb} the revision \"{$name}\".";
|
2011-06-30 21:32:30 +02:00
|
|
|
|
|
|
|
// If the commented added reviewers or CCs, list them explicitly.
|
|
|
|
$meta = $comment->getMetadata();
|
|
|
|
$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) {
|
|
|
|
$body[] = 'Added Reviewers: '.$this->renderHandleList(
|
|
|
|
$handles,
|
|
|
|
$m_reviewers);
|
|
|
|
}
|
|
|
|
if ($m_cc) {
|
|
|
|
$body[] = 'Added CCs: '.$this->renderHandleList(
|
|
|
|
$handles,
|
|
|
|
$m_cc);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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';
|
|
|
|
$body[] = ' This revision was updated prior to commit.';
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
$body[] = $this->renderRevisionDetailLink();
|
2011-04-10 18:08:11 +02:00
|
|
|
$body[] = null;
|
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
$revision = $this->getRevision();
|
|
|
|
if ($revision->getStatus() == DifferentialRevisionStatus::COMMITTED) {
|
2011-04-10 17:31:18 +02:00
|
|
|
$phids = $revision->loadCommitPHIDs();
|
2011-04-10 23:36:04 +02:00
|
|
|
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";
|
|
|
|
}
|
2011-02-09 21:57:38 +01:00
|
|
|
|
2011-04-10 23:36:04 +02:00
|
|
|
foreach ($handles as $handle) {
|
|
|
|
$body[] = ' '.PhabricatorEnv::getProductionURI($handle->getURI());
|
|
|
|
}
|
|
|
|
$body[] = null;
|
2011-01-26 02:17:19 +01:00
|
|
|
}
|
|
|
|
}
|
2011-04-10 17:31:18 +02:00
|
|
|
|
2011-01-26 02:17:19 +01:00
|
|
|
return implode("\n", $body);
|
|
|
|
}
|
|
|
|
}
|