From a802a901230cfffff9dea4826d57b433300f2d29 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 4 Sep 2012 12:08:04 -0700 Subject: [PATCH] Always include 'workflow' on Arcanist events Summary: This object is highly useful in many client event handlers (particularly for access to the CLI) and allows them to be implemented less intrusively. This also slightly reduces code duplication. Test Plan: Ran "arc diff". Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T1753 Differential Revision: https://secure.phabricator.com/D3421 --- src/workflow/ArcanistBaseWorkflow.php | 11 +++++++++++ src/workflow/ArcanistCommitWorkflow.php | 7 ++----- src/workflow/ArcanistDiffWorkflow.php | 16 ++++++---------- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/workflow/ArcanistBaseWorkflow.php b/src/workflow/ArcanistBaseWorkflow.php index 52512855..a5afc101 100644 --- a/src/workflow/ArcanistBaseWorkflow.php +++ b/src/workflow/ArcanistBaseWorkflow.php @@ -1315,4 +1315,15 @@ abstract class ArcanistBaseWorkflow { return $parser; } + protected function dispatchEvent($type, array $data) { + $data += array( + 'workflow' => $this, + ); + + $event = new PhutilEvent($type, $data); + PhutilEventEngine::dispatchEvent($event); + + return $event; + } + } diff --git a/src/workflow/ArcanistCommitWorkflow.php b/src/workflow/ArcanistCommitWorkflow.php index eb4a18c9..8fce0a97 100644 --- a/src/workflow/ArcanistCommitWorkflow.php +++ b/src/workflow/ArcanistCommitWorkflow.php @@ -135,14 +135,11 @@ EOTEXT 'edit' => false, )); - $event = new PhutilEvent( + $event = $this->dispatchEvent( ArcanistEventType::TYPE_COMMIT_WILLCOMMITSVN, array( 'message' => $message, - 'workflow' => $this, - ) - ); - PhutilEventEngine::dispatchEvent($event); + )); $message = $event->getValue('message'); diff --git a/src/workflow/ArcanistDiffWorkflow.php b/src/workflow/ArcanistDiffWorkflow.php index 40dba22c..6d78f4c9 100644 --- a/src/workflow/ArcanistDiffWorkflow.php +++ b/src/workflow/ArcanistDiffWorkflow.php @@ -383,8 +383,9 @@ EOTEXT $commit_message = $this->buildCommitMessage(); - PhutilEventEngine::dispatchEvent( - new PhutilEvent(ArcanistEventType::TYPE_DIFF_DIDBUILDMESSAGE)); + $this->dispatchEvent( + ArcanistEventType::TYPE_DIFF_DIDBUILDMESSAGE, + array()); if (!$this->shouldOnlyCreateDiff()) { $revision = $this->buildRevisionFromCommitMessage($commit_message); @@ -430,14 +431,13 @@ EOTEXT $this->diffID = $diff_info['diffid']; - $event = new PhutilEvent( + $event = $this->dispatchEvent( ArcanistEventType::TYPE_DIFF_WASCREATED, array( 'diffID' => $diff_info['diffid'], 'lintResult' => $lint_result, 'unitResult' => $unit_result, )); - PhutilEventEngine::dispatchEvent($event); $this->updateLintDiffProperty(); $this->updateUnitDiffProperty(); @@ -2273,26 +2273,22 @@ EOTEXT } private function dispatchWillCreateRevisionEvent(array $fields) { - $event = new PhutilEvent( + $event = $this->dispatchEvent( ArcanistEventType::TYPE_REVISION_WILLCREATEREVISION, array( 'specification' => $fields, )); - PhutilEventEngine::dispatchEvent($event); - return $event->getValue('specification'); } private function dispatchWillBuildEvent(array $fields) { - $event = new PhutilEvent( + $event = $this->dispatchEvent( ArcanistEventType::TYPE_DIFF_WILLBUILDMESSAGE, array( 'fields' => $fields, )); - PhutilEventEngine::dispatchEvent($event); - return $event->getValue('fields'); }