From 2427d317b2f0957b0c4917c5c321e07d94c7e2b9 Mon Sep 17 00:00:00 2001 From: Jakub Vrana Date: Thu, 30 May 2013 17:33:17 -0700 Subject: [PATCH] Reference task based on branch name in `arc diff` Summary: This was mentioned in T2928 and nobody objected. It just references the task instead of fixing it as that would be too aggressive. It also doesn't check assignee of the task (by purpose). Test Plan: Created diff from a branch named T2928. Reviewers: epriestley, edward Reviewed By: epriestley CC: aran, Korvin Maniphest Tasks: T2928 Differential Revision: https://secure.phabricator.com/D5640 --- ...API_differential_updaterevision_Method.php | 2 +- .../editor/DifferentialRevisionEditor.php | 17 +++++++------ .../DifferentialBranchFieldSpecification.php | 24 +++++++++++++++++++ 3 files changed, 33 insertions(+), 10 deletions(-) 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.', + ); + } + }