]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Show build results in `arc land`
authorepriestley <git@epriestley.com>
Thu, 17 Apr 2014 22:59:54 +0000 (15:59 -0700)
committerepriestley <git@epriestley.com>
Thu, 17 Apr 2014 22:59:54 +0000 (15:59 -0700)
Summary:
Fixes T4809. When landing a revision, check for a (non-manual) buildable of the current diff. If we find one, check its status:

  - If it passed, print out a message to inform the user that we checked.
  - If it failed or is still building, print out details about the issue and require a confirmation to continue.
  - Just ignore other cases.

Test Plan:
  - Ran `arc land` on a revision with no buildable, a passing buildable, a failed buildable, and a building buildable for the current diff.
  - Got sensible output / prompts.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4809

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

src/workflow/ArcanistLandWorkflow.php

index 17c3f4ad137491c9296c196be552a5d0d5b2d8e8..1f20652e76f145947703a61af9f977ff2544669e 100644 (file)
@@ -533,6 +533,11 @@ EOTEXT
 
     echo pht("Landing revision '%s'...",
              "D{$rev_id}: {$rev_title}"), "\n";
+
+    $diff_phid = idx($this->revision, 'activeDiffPHID');
+    if ($diff_phid) {
+      $this->checkForBuildables($diff_phid);
+    }
   }
 
   private function pullFromRemote() {
@@ -1162,4 +1167,95 @@ EOTEXT
       $this->oldBranch);
   }
 
+
+  /**
+   * Check if a diff has a running or failed buildable, and prompt the user
+   * before landing if it does.
+   */
+  private function checkForBuildables($diff_phid) {
+    // NOTE: Since Harbormaster is still beta and this stuff all got added
+    // recently, just bail if we can't find a buildable. This is just an
+    // advisory check intended to prevent human error.
+
+    try {
+      $buildables = $this->getConduit()->callMethodSynchronous(
+        'harbormaster.querybuildables',
+        array(
+          'buildablePHIDs' => array($diff_phid),
+          'manualBuildables' => false,
+        ));
+    } catch (ConduitClientException $ex) {
+      return;
+    }
+
+    if (!$buildables['data']) {
+      // If there's no corresponding buildable, we're done.
+      return;
+    }
+
+    $console = PhutilConsole::getConsole();
+
+    $buildable = head($buildables['data']);
+
+    if ($buildable['buildableStatus'] == 'passed') {
+      $console->writeOut(
+        "**<bg:green> %s </bg>** %s\n",
+        pht('BUILDS PASSED'),
+        pht(
+          'Harbormaster builds for the active diff completed successfully.'));
+      return;
+    }
+
+    switch ($buildable['buildableStatus']) {
+      case 'building':
+        $message = pht(
+          'Harbormaster is still building the active diff for this revision:');
+        $prompt = pht('Land revision anyway, despite ongoing build?');
+        break;
+      case 'failed':
+        $message = pht(
+          'Harbormaster failed to build the active diff for this revision. '.
+          'Build failures:');
+        $prompt = pht('Land revision anyway, despite build failures?');
+        break;
+      default:
+        // If we don't recognize the status, just bail.
+        return;
+    }
+
+    $builds = $this->getConduit()->callMethodSynchronous(
+      'harbormaster.querybuilds',
+      array(
+        'buildablePHIDs' => array($buildable['phid']),
+      ));
+
+    $console->writeOut($message."\n\n");
+    foreach ($builds['data'] as $build) {
+      switch ($build['buildStatus']) {
+        case 'failed':
+          $color = 'red';
+          break;
+        default:
+          $color = 'yellow';
+          break;
+      }
+
+      $console->writeOut(
+        "    **<bg:".$color."> %s </bg>** %s: %s\n",
+        phutil_utf8_strtoupper($build['buildStatusName']),
+        pht('Build %d', $build['id']),
+        $build['name']);
+    }
+
+    $console->writeOut(
+      "\n%s\n\n    **%s**: __%s__",
+      pht('You can review build details here:'),
+      pht('Harbormaster URI'),
+      $buildable['uri']);
+
+    if (!$console->confirm($prompt)) {
+      throw new ArcanistUserAbortException();
+    }
+  }
+
 }