From 97a97f5376edd2aa8be0171d2ae9a9950f5b95b6 Mon Sep 17 00:00:00 2001 From: vrana Date: Mon, 19 Nov 2012 15:51:46 -0800 Subject: [PATCH] Attach mentioned Maniphest task also to revision Summary: Also disable this feature without 'maniphest.enabled'. Test Plan: Wrote "fixes T..." in `arc diff`, verified that the task is attached. Add another "fixes T..." in edit revision on web, verified that it was added. Deleted "fixes T..." in edit revision, verified that the attached task wasn't deleted. Reviewers: 20after4, epriestley Reviewed By: 20after4 CC: aran, Korvin Maniphest Tasks: T945 Differential Revision: https://secure.phabricator.com/D3986 --- ...DifferentialFreeformFieldSpecification.php | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php index 1424592381..cf79450b72 100644 --- a/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php +++ b/src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php @@ -4,6 +4,10 @@ abstract class DifferentialFreeformFieldSpecification extends DifferentialFieldSpecification { private function findMentionedTasks($message) { + if (!PhabricatorEnv::getEnvConfig('maniphest.enabled')) { + return array(); + } + $prefixes = array( 'resolves' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, 'fixes' => ManiphestTaskStatus::STATUS_CLOSED_RESOLVED, @@ -67,6 +71,34 @@ abstract class DifferentialFreeformFieldSpecification return $tasks_statuses; } + public function didWriteRevision(DifferentialRevisionEditor $editor) { + $message = $this->renderValueForCommitMessage(false); + $tasks = $this->findMentionedTasks($message); + if (!$tasks) { + return; + } + + $revision_phid = $editor->getRevision()->getPHID(); + $edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK; + + $add_phids = id(new ManiphestTask()) + ->loadAllWhere('id IN (%Ld)', array_keys($tasks)); + $add_phids = mpull($add_phids, 'getPHID'); + + $old_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( + $revision_phid, + $edge_type); + + $add_phids = array_diff($add_phids, $old_phids); + + $edge_editor = id(new PhabricatorEdgeEditor())->setActor($this->getUser()); + foreach ($add_phids as $phid) { + $edge_editor->addEdge($revision_phid, $edge_type, $phid); + } + // NOTE: Deletes only through Maniphest Tasks field. + $edge_editor->save(); + } + public function didParseCommit( PhabricatorRepository $repository, PhabricatorRepositoryCommit $commit,