]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Always include 'workflow' on Arcanist events
authorepriestley <git@epriestley.com>
Tue, 4 Sep 2012 19:08:04 +0000 (12:08 -0700)
committerepriestley <git@epriestley.com>
Tue, 4 Sep 2012 19:08:04 +0000 (12:08 -0700)
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
src/workflow/ArcanistCommitWorkflow.php
src/workflow/ArcanistDiffWorkflow.php

index 52512855abad7484e4e96eaaf2e0e1887a174a7a..a5afc1014ff52dbe0bdd23995274ecedc5126ed6 100644 (file)
@@ -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;
+  }
+
 }
index eb4a18c955131355f0550e6168c272bdfd3e3bb0..8fce0a972a6c02ef937328671826afa86ccf84eb 100644 (file)
@@ -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');
 
index 40dba22c307844f80fabe0bd355303e2d013bd3f..6d78f4c938c087eee5bbd8dfb1230f00ee7c8adb 100644 (file)
@@ -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');
   }