]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow anyone to mark Differential revisions as commited.
authorMarek Sapota <mareksapota@fb.com>
Tue, 25 Oct 2011 23:34:15 +0000 (16:34 -0700)
committerMarek Sapota <mareksapota@fb.com>
Wed, 26 Oct 2011 00:24:57 +0000 (17:24 -0700)
Test Plan:
Run `arc mark-committed` on a revision that you don't own, you should see a
prompt asking you if you really want to do that and if you answer `Y` it should
mark the revision as committed.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, epriestley, mareksapota
Differential Revision: 1052

src/workflow/mark-committed/ArcanistMarkCommittedWorkflow.php
src/workflow/mark-committed/__init__.php

index 74c0eee444c19f648002565d3bf5d33afd6d123c..bcfaa9b74abaf01e1adab0d9b028450e156db6cd 100644 (file)
@@ -79,32 +79,41 @@ EOTEXT
       throw new ArcanistUsageException(
         "mark-committed requires exactly one revision.");
     }
-
-    $revision_data = $conduit->callMethodSynchronous(
-      'differential.find',
-      array(
-        'query' => 'committable',
-        'guids' => array(
-          $this->getUserPHID(),
-        ),
-      ));
+    $revision_id = reset($revision_list);
+    $revision_id = $this->normalizeRevisionID($revision_id);
 
     $revision = null;
     try {
-      $revision_id = reset($revision_list);
-      $revision_id = $this->normalizeRevisionID($revision_id);
-      $revision = $this->chooseRevision(
-        $revision_data,
-        $revision_id);
-    } catch (ArcanistChooseInvalidRevisionException $ex) {
+      $revision = $conduit->callMethodSynchronous(
+        'differential.getrevision',
+        array(
+          'revision_id' => $revision_id,
+        )
+      );
+    } catch (Exception $ex) {
       if (!$is_finalize) {
         throw new ArcanistUsageException(
-          "Revision D{$revision_id} is not committable. You can only mark ".
-          "revisions which have been 'accepted' as committed.");
+          "Revision D{$revision_id} does not exist."
+        );
       }
     }
 
+    if (!$is_finalize && $revision['statusName'] != 'Accepted') {
+      throw new ArcanistUsageException(
+        "Revision D{$revision_id} is not committable. You can only mark ".
+        "revisions which have been 'accepted' as committed."
+      );
+    }
+
     if ($revision) {
+      if ($revision['authorPHID'] != $this->getUserPHID()) {
+        $prompt = "You are not the author of revision D{$revision_id}, ".
+          'are you sure you want to mark it committed?';
+        if (!phutil_console_confirm($prompt)) {
+          throw new ArcanistUserAbortException();
+        }
+      }
+
       $actually_mark = true;
       if ($is_finalize) {
         $project_info = $conduit->callMethodSynchronous(
@@ -117,8 +126,7 @@ EOTEXT
         }
       }
       if ($actually_mark) {
-        $revision_id = $revision->getID();
-        $revision_name = $revision->getName();
+        $revision_name = $revision['title'];
 
         echo "Marking revision D{$revision_id} '{$revision_name}' ".
              "committed...\n";
@@ -131,17 +139,12 @@ EOTEXT
       }
     }
 
-    $revision_info = $conduit->callMethodSynchronous(
-      'differential.getrevision',
-      array(
-        'revision_id' => $revision_id,
-      ));
-    $status = $revision_info['statusName'];
+    $status = $revision['statusName'];
     if ($status == 'Accepted' || $status == 'Committed') {
       // If this has already been attached to commits, don't show the
       // "you can push this commit" message since we know it's been committed
       // already.
-      $is_finalized = empty($revision_info['commits']);
+      $is_finalized = empty($revision['commits']);
     } else {
       $is_finalized = false;
     }
index 83bdcd8d87354bbfa0c18ce1f2e682416baf08f8..cfeea0919eda842a41bd91a0147d34e73d5dac94 100644 (file)
@@ -7,6 +7,7 @@
 
 
 phutil_require_module('arcanist', 'exception/usage');
+phutil_require_module('arcanist', 'exception/usage/userabort');
 phutil_require_module('arcanist', 'workflow/base');
 
 phutil_require_module('phutil', 'console');