diff --git a/src/applications/differential/conduit/ConduitAPI_differential_updaterevision_Method.php b/src/applications/differential/conduit/ConduitAPI_differential_updaterevision_Method.php index a18a60bb64..532c56c384 100644 --- a/src/applications/differential/conduit/ConduitAPI_differential_updaterevision_Method.php +++ b/src/applications/differential/conduit/ConduitAPI_differential_updaterevision_Method.php @@ -60,9 +60,9 @@ final class ConduitAPI_differential_updaterevision_Method $editor->setActor($request->getUser()); $editor->setContentSource($content_source); $fields = $request->getValue('fields'); + $editor->addDiff($diff, $request->getValue('message')); $editor->copyFieldsFromConduit($fields); - $editor->addDiff($diff, $request->getValue('message')); $editor->save(); return array( diff --git a/src/applications/differential/editor/DifferentialRevisionEditor.php b/src/applications/differential/editor/DifferentialRevisionEditor.php index c334cdffd8..5b6d90beab 100644 --- a/src/applications/differential/editor/DifferentialRevisionEditor.php +++ b/src/applications/differential/editor/DifferentialRevisionEditor.php @@ -34,9 +34,9 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { $editor = new DifferentialRevisionEditor($revision); $editor->setActor($actor); + $editor->addDiff($diff, null); $editor->copyFieldsFromConduit($fields); - $editor->addDiff($diff, null); $editor->save(); return $revision; @@ -48,19 +48,19 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { $revision = $this->revision; $revision->loadRelationships(); - $aux_fields = DifferentialFieldSelector::newSelector() + $all_fields = DifferentialFieldSelector::newSelector() ->getFieldSpecifications(); - foreach ($aux_fields as $key => $aux_field) { + $aux_fields = array(); + foreach ($all_fields as $aux_field) { $aux_field->setRevision($revision); + $aux_field->setDiff($this->diff); $aux_field->setUser($actor); - if (!$aux_field->shouldAppearOnCommitMessage()) { - unset($aux_fields[$key]); + if ($aux_field->shouldAppearOnCommitMessage()) { + $aux_fields[$aux_field->getCommitMessageKey()] = $aux_field; } } - $aux_fields = mpull($aux_fields, null, 'getCommitMessageKey'); - foreach ($fields as $field => $value) { if (empty($aux_fields[$field])) { throw new Exception( @@ -73,8 +73,7 @@ final class DifferentialRevisionEditor extends PhabricatorEditor { $aux_field->validateField(); } - $aux_fields = array_values($aux_fields); - $this->setAuxiliaryFields($aux_fields); + $this->setAuxiliaryFields($all_fields); } public function setAuxiliaryFields(array $auxiliary_fields) { diff --git a/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php b/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php index 86b1399df8..c2563cb2c3 100644 --- a/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php @@ -46,4 +46,28 @@ final class DifferentialBranchFieldSpecification } } + public function didWriteRevision(DifferentialRevisionEditor $editor) { + $branch = $this->getDiff()->getBranch(); + $match = null; + if (preg_match('/^T(\d+)/i', $branch, $match)) { // No $ to allow T123_demo. + list(, $task_id) = $match; + $task = id(new ManiphestTask())->load($task_id); + if ($task) { + id(new PhabricatorEdgeEditor()) + ->setActor($this->getUser()) + ->addEdge( + $this->getRevision()->getPHID(), + PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK, + $task->getPHID()) + ->save(); + } + } + } + + public function getCommitMessageTips() { + return array( + 'Name branch "T123" to attach the diff to a task.', + ); + } + }