Page MenuHomestyx hydra

No OneTemporary

diff --git a/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php b/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php
index 0d5f877c1f..ccf09be6ab 100644
--- a/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php
+++ b/src/applications/conduit/method/differential/creatediff/ConduitAPI_differential_creatediff_Method.php
@@ -1,134 +1,137 @@
<?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.
*/
class ConduitAPI_differential_creatediff_Method extends ConduitAPIMethod {
public function getMethodDescription() {
return "Create a new Differential diff.";
}
public function defineParamTypes() {
return array(
'changes' => 'required list<dict>',
'sourceMachine' => 'required string',
'sourcePath' => 'required string',
'branch' => 'required string',
'sourceControlSystem' => 'required enum<svn, git>',
'sourceControlPath' => 'required string',
'sourceControlBaseRevision' => 'required string',
'parentRevisionID' => 'optional revisionid',
'creationMethod' => 'optional string',
'authorPHID' => 'optional phid',
'arcanistProject' => 'optional string',
'lintStatus' =>
'required enum<none, skip, okay, warn, fail>',
'unitStatus' =>
'required enum<none, skip, okay, warn, fail>',
);
}
public function defineReturnType() {
return 'nonempty dict';
}
public function defineErrorTypes() {
return array(
);
}
protected function execute(ConduitAPIRequest $request) {
$change_data = $request->getValue('changes');
$changes = array();
foreach ($change_data as $dict) {
$changes[] = ArcanistDiffChange::newFromDictionary($dict);
}
$diff = DifferentialDiff::newFromRawChanges($changes);
$diff->setSourcePath($request->getValue('sourcePath'));
$diff->setSourceMachine($request->getValue('sourceMachine'));
$diff->setBranch($request->getValue('branch'));
$diff->setCreationMethod($request->getValue('creationMethod'));
$diff->setAuthorPHID($request->getValue('authorPHID'));
$parent_id = $request->getValue('parentRevisionID');
if ($parent_id) {
$parent_rev = id(new DifferentialRevision())->load($parent_id);
if ($parent_rev) {
if ($parent_rev->getStatus() != DifferentialRevisionStatus::COMMITTED) {
$diff->setParentRevisionID($parent_id);
}
}
}
$system = $request->getValue('sourceControlSystem');
$diff->setSourceControlSystem($system);
$diff->setSourceControlPath($request->getValue('sourceControlPath'));
$diff->setSourceControlBaseRevision(
$request->getValue('sourceControlBaseRevision'));
$diff->setArcanistProject($request->getValue('arcanistProject'));
switch ($request->getValue('lintStatus')) {
case 'skip':
$diff->setLintStatus(DifferentialLintStatus::LINT_SKIP);
break;
case 'okay':
$diff->setLintStatus(DifferentialLintStatus::LINT_OKAY);
break;
case 'warn':
$diff->setLintStatus(DifferentialLintStatus::LINT_WARN);
break;
case 'fail':
$diff->setLintStatus(DifferentialLintStatus::LINT_FAIL);
break;
case 'none':
default:
$diff->setLintStatus(DifferentialLintStatus::LINT_NONE);
break;
}
switch ($request->getValue('unitStatus')) {
case 'skip':
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_SKIP);
break;
case 'okay':
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_OKAY);
break;
case 'warn':
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_WARN);
break;
case 'fail':
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_FAIL);
break;
case 'none':
default:
$diff->setUnitStatus(DifferentialUnitStatus::UNIT_NONE);
break;
}
$diff->save();
+ $path = '/differential/diff/'.$diff->getID().'/';
+ $uri = PhabricatorEnv::getURI($path);
+
return array(
'diffid' => $diff->getID(),
- 'uri' => 'http://local.aphront.com/differential/diff/'.$diff->getID().'/',
+ 'uri' => $uri,
);
}
}
diff --git a/src/applications/differential/mail/base/DifferentialMail.php b/src/applications/differential/mail/base/DifferentialMail.php
index 322049845e..e80ae7aebe 100755
--- a/src/applications/differential/mail/base/DifferentialMail.php
+++ b/src/applications/differential/mail/base/DifferentialMail.php
@@ -1,311 +1,310 @@
<?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.
*/
abstract class DifferentialMail {
const SUBJECT_PREFIX = '[Differential]';
protected $to = array();
protected $cc = array();
protected $actorName;
protected $actorID;
protected $revision;
protected $comment;
protected $changesets;
protected $inlineComments;
protected $isFirstMailAboutRevision;
protected $isFirstMailToRecipients;
protected $heraldTranscriptURI;
protected $heraldRulesHeader;
public function getActorName() {
return $this->actorName;
}
public function setActorName($actor_name) {
$this->actorName = $actor_name;
return $this;
}
abstract protected function renderSubject();
abstract protected function renderBody();
public function setXHeraldRulesHeader($header) {
$this->heraldRulesHeader = $header;
return $this;
}
public function send() {
$to_phids = $this->getToPHIDs();
if (!$to_phids) {
throw new Exception('No "To:" users provided!');
}
$message_id = $this->getMessageID();
$cc_phids = $this->getCCPHIDs();
$subject = $this->buildSubject();
$body = $this->buildBody();
$mail = new PhabricatorMetaMTAMail();
if ($this->getActorID()) {
$mail->setFrom($this->getActorID());
$mail->setReplyTo($this->getReplyHandlerEmailAddress());
} else {
$mail->setFrom($this->getReplyHandlerEmailAddress());
}
$mail
->addTos($to_phids)
->addCCs($cc_phids)
->setSubject($subject)
->setBody($body)
->setIsHTML($this->shouldMarkMailAsHTML())
->addHeader('Thread-Topic', $this->getRevision()->getTitle())
->addHeader('Thread-Index', $this->generateThreadIndex());
if ($this->isFirstMailAboutRevision()) {
$mail->addHeader('Message-ID', $message_id);
} else {
$mail->addHeader('In-Reply-To', $message_id);
$mail->addHeader('References', $message_id);
}
if ($this->heraldRulesHeader) {
$mail->addHeader('X-Herald-Rules', $this->heraldRulesHeader);
}
$mail->setRelatedPHID($this->getRevision()->getPHID());
// Save this to the MetaMTA queue for later delivery to the MTA.
$mail->save();
}
protected function buildSubject() {
return self::SUBJECT_PREFIX.' '.$this->renderSubject();
}
protected function shouldMarkMailAsHTML() {
return false;
}
protected function buildBody() {
$actions = array();
$body = $this->renderBody();
$body .= <<<EOTEXT
ACTIONS
Reply to comment, or !accept, !reject, !abandon, !resign, or !showdiff.
EOTEXT;
if ($this->getHeraldTranscriptURI() && $this->isFirstMailToRecipients()) {
$xscript_uri = $this->getHeraldTranscriptURI();
$body .= <<<EOTEXT
MANAGE HERALD RULES
http://todo.com/herald/
WHY DID I GET THIS EMAIL?
{$xscript_uri}
Tip: use the X-Herald-Rules header to filter Herald messages in your client.
EOTEXT;
}
return $body;
}
protected function getReplyHandlerEmailAddress() {
// TODO
$phid = $this->getRevision()->getPHID();
$server = 'todo.example.com';
return "differential+{$phid}@{$server}";
}
protected function formatText($text) {
$text = explode("\n", $text);
foreach ($text as &$line) {
$line = rtrim(' '.$line);
}
unset($line);
return implode("\n", $text);
}
public function setToPHIDs(array $to) {
$this->to = $this->filterContactPHIDs($to);
return $this;
}
public function setCCPHIDs(array $cc) {
$this->cc = $this->filterContactPHIDs($cc);
return $this;
}
protected function filterContactPHIDs(array $phids) {
return $phids;
// TODO: actually do this?
// Differential revisions use Subscriptions for CCs, so any arbitrary
// PHID can end up CC'd to them. Only try to actually send email PHIDs
// which have ToolsHandle types that are marked emailable. If we don't
// filter here, sending the email will fail.
/*
$handles = array();
prep(new ToolsHandleData($phids, $handles));
foreach ($handles as $phid => $handle) {
if (!$handle->isEmailable()) {
unset($handles[$phid]);
}
}
return array_keys($handles);
*/
}
protected function getToPHIDs() {
return $this->to;
}
protected function getCCPHIDs() {
return $this->cc;
}
public function setActorID($actor_id) {
$this->actorID = $actor_id;
return $this;
}
public function getActorID() {
return $this->actorID;
}
public function setRevision($revision) {
$this->revision = $revision;
return $this;
}
public function getRevision() {
return $this->revision;
}
protected function getMessageID() {
$phid = $this->getRevision()->getPHID();
// TODO
return "<differential-rev-{$phid}-req@TODO.com>";
}
public function setComment($comment) {
$this->comment = $comment;
return $this;
}
public function getComment() {
return $this->comment;
}
public function setChangesets($changesets) {
$this->changesets = $changesets;
return $this;
}
public function getChangesets() {
return $this->changesets;
}
public function setInlineComments(array $inline_comments) {
$this->inlineComments = $inline_comments;
return $this;
}
public function getInlineComments() {
return $this->inlineComments;
}
public function renderRevisionDetailLink() {
$uri = $this->getRevisionURI();
return "REVISION DETAIL\n {$uri}";
}
public function getRevisionURI() {
- // TODO
- return 'http://local.aphront.com/D'.$this->getRevision()->getID();
+ return PhabricatorEnv::getURI('/D'.$this->getRevision()->getID());
}
public function setIsFirstMailToRecipients($first) {
$this->isFirstMailToRecipients = $first;
return $this;
}
public function isFirstMailToRecipients() {
return $this->isFirstMailToRecipients;
}
public function setIsFirstMailAboutRevision($first) {
$this->isFirstMailAboutRevision = $first;
return $this;
}
public function isFirstMailAboutRevision() {
return $this->isFirstMailAboutRevision;
}
protected function generateThreadIndex() {
// When threading, Outlook ignores the 'References' and 'In-Reply-To'
// headers that most clients use. Instead, it uses a custom 'Thread-Index'
// header. The format of this header is something like this (from
// camel-exchange-folder.c in Evolution Exchange):
/* A new post to a folder gets a 27-byte-long thread index. (The value
* is apparently unique but meaningless.) Each reply to a post gets a
* 32-byte-long thread index whose first 27 bytes are the same as the
* parent's thread index. Each reply to any of those gets a
* 37-byte-long thread index, etc. The Thread-Index header contains a
* base64 representation of this value.
*/
// The specific implementation uses a 27-byte header for the first email
// a recipient receives, and a random 5-byte suffix (32 bytes total)
// thereafter. This means that all the replies are (incorrectly) siblings,
// but it would be very difficult to keep track of the entire tree and this
// gets us reasonable client behavior.
$base = substr(md5($this->getRevision()->getPHID()), 0, 27);
if (!$this->isFirstMailAboutRevision()) {
// not totally sure, but it seems like outlook orders replies by
// thread-index rather than timestamp, so to get these to show up in the
// right order we use the time as the last 4 bytes.
$base .= ' ' . pack("N", time());
}
return base64_encode($base);
}
public function setHeraldTranscriptURI($herald_transcript_uri) {
$this->heraldTranscriptURI = $herald_transcript_uri;
return $this;
}
public function getHeraldTranscriptURI() {
return $this->heraldTranscriptURI;
}
}

File Metadata

Mime Type
text/x-diff
Expires
Sat, Nov 15, 8:15 AM (19 h, 14 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
337709
Default Alt Text
(13 KB)

Event Timeline