]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Add a --target flag to `arc unit` for uploading results
authorepriestley <git@epriestley.com>
Tue, 29 Sep 2015 16:51:51 +0000 (09:51 -0700)
committerepriestley <git@epriestley.com>
Tue, 29 Sep 2015 16:51:51 +0000 (09:51 -0700)
Summary: Ref T5821. Basic idea here is that Harbormaster can run `arc unit --everything --target ...` to get a build target updated.

Test Plan: Ran `arc unit --target ...`, saw web UI update with test results.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T5821

Differential Revision: https://secure.phabricator.com/D14190

src/workflow/ArcanistDiffWorkflow.php
src/workflow/ArcanistUnitWorkflow.php
src/workflow/ArcanistWorkflow.php

index 3074c16679c885f97ab53de30f9726e32cd2a4b6..eeabfdfba144593261239379abacd13276008d48 100644 (file)
@@ -2753,15 +2753,7 @@ EOTEXT
         $unit[$key] = $this->getModernUnitDictionary($message);
       }
 
-      switch ($unit_result) {
-        case ArcanistUnitWorkflow::RESULT_OKAY:
-        case ArcanistUnitWorkflow::RESULT_SKIP:
-          $type = 'pass';
-          break;
-        default:
-          $type = 'fail';
-          break;
-      }
+      $type = ArcanistUnitWorkflow::getHarbormasterTypeFromResult($unit_result);
 
       $futures[] = $this->getConduit()->callMethod(
         'harbormaster.sendmessage',
@@ -2785,23 +2777,4 @@ EOTEXT
     }
   }
 
-  private function getModernLintDictionary(array $map) {
-    $map = $this->getModernCommonDictionary($map);
-    return $map;
-  }
-
-  private function getModernUnitDictionary(array $map) {
-    $map = $this->getModernCommonDictionary($map);
-    return $map;
-  }
-
-  private function getModernCommonDictionary(array $map) {
-    foreach ($map as $key => $value) {
-      if ($value === null) {
-        unset($map[$key]);
-      }
-    }
-    return $map;
-  }
-
 }
index 1fcee32a0d910f5291e59ddfd0615d08c52f140b..04d8c8e01079fd99324048c350571ae87640222c 100644 (file)
@@ -84,6 +84,12 @@ EOTEXT
           'ugly' => pht('Only one output format allowed'),
         ),
       ),
+      'target' => array(
+        'param' => 'phid',
+        'help' => pht(
+          '(PROTOTYPE) Record a copy of the test results on the specified '.
+          'Harbormaster build target.'),
+      ),
       'everything' => array(
         'help' => pht('Run every test.'),
         'conflicts' => array(
@@ -107,6 +113,14 @@ EOTEXT
     return true;
   }
 
+  public function requiresConduit() {
+    return $this->shouldUploadResults();
+  }
+
+  public function requiresAuthentication() {
+    return $this->shouldUploadResults();
+  }
+
   public function getEngine() {
     return $this->engine;
   }
@@ -263,6 +277,12 @@ EOTEXT
         break;
     }
 
+
+    $target_phid = $this->getArgument('target');
+    if ($target_phid) {
+      $this->uploadTestResults($target_phid, $overall_result, $results);
+    }
+
     return $overall_result;
   }
 
@@ -370,4 +390,46 @@ EOTEXT
 
   }
 
+  public static function getHarbormasterTypeFromResult($unit_result) {
+    switch ($unit_result) {
+      case self::RESULT_OKAY:
+      case self::RESULT_SKIP:
+        $type = 'pass';
+        break;
+      default:
+        $type = 'fail';
+        break;
+    }
+
+    return $type;
+  }
+
+  private function shouldUploadResults() {
+    return ($this->getArgument('target') !== null);
+  }
+
+  private function uploadTestResults(
+    $target_phid,
+    $unit_result,
+    array $unit) {
+
+    // TODO: It would eventually be nice to stream test results up to the
+    // server as we go, but just get things working for now.
+
+    $message_type = self::getHarbormasterTypeFromResult($unit_result);
+
+    foreach ($unit as $key => $result) {
+      $dictionary = $result->toDictionary();
+      $unit[$key] = $this->getModernUnitDictionary($dictionary);
+    }
+
+    $this->getConduit()->callMethodSynchronous(
+      'harbormaster.sendmessage',
+      array(
+        'buildTargetPHID' => $target_phid,
+        'unit' => array_values($unit),
+        'type' => $message_type,
+      ));
+  }
+
 }
index 5464910327b09ee58fcfa92f4619bdcfe7776aff..c07279cc7786afade44ce005a1a373a8eab593a5 100644 (file)
@@ -2040,5 +2040,24 @@ abstract class ArcanistWorkflow extends Phobject {
     }
   }
 
+  protected function getModernLintDictionary(array $map) {
+    $map = $this->getModernCommonDictionary($map);
+    return $map;
+  }
+
+  protected function getModernUnitDictionary(array $map) {
+    $map = $this->getModernCommonDictionary($map);
+    return $map;
+  }
+
+  private function getModernCommonDictionary(array $map) {
+    foreach ($map as $key => $value) {
+      if ($value === null) {
+        unset($map[$key]);
+      }
+    }
+    return $map;
+  }
+
 
 }