]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Create an arc todo workflow for quickly creating a task.
authorAlan Huang <alanh@devrs314.snc6.facebook.com>
Wed, 11 Jul 2012 00:32:36 +0000 (17:32 -0700)
committerAlan Huang <alanh@devrs314.snc6.facebook.com>
Wed, 11 Jul 2012 00:32:36 +0000 (17:32 -0700)
Summary:
Run `arc todo o rly?` to create a Maniphest task
titled 'o rly?'. Pass --cc to add CCs besides yourself.

Test Plan: Ran `arc todo o rly?`. Behaved as expected.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran, Korvin
Maniphest Tasks: T749, T1325

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

src/__phutil_library_map__.php
src/workflow/ArcanistTodoWorkflow.php [new file with mode: 0644]

index fdfda1a80bb4b73c0de3143f99f2f87792d89f38..7af9c2e060882a44f4b292ead6c46f7fd83daf10 100644 (file)
@@ -112,6 +112,7 @@ phutil_register_library_map(array(
     'ArcanistTasksWorkflow' => 'workflow/ArcanistTasksWorkflow.php',
     'ArcanistTextLinter' => 'lint/linter/ArcanistTextLinter.php',
     'ArcanistTextLinterTestCase' => 'lint/linter/__tests__/ArcanistTextLinterTestCase.php',
+    'ArcanistTodoWorkflow' => 'workflow/ArcanistTodoWorkflow.php',
     'ArcanistUncommittedChangesException' => 'exception/usage/ArcanistUncommittedChangesException.php',
     'ArcanistUnitTestResult' => 'unit/ArcanistUnitTestResult.php',
     'ArcanistUnitWorkflow' => 'workflow/ArcanistUnitWorkflow.php',
@@ -213,6 +214,7 @@ phutil_register_library_map(array(
     'ArcanistTasksWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistTextLinter' => 'ArcanistLinter',
     'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase',
+    'ArcanistTodoWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistUncommittedChangesException' => 'ArcanistUsageException',
     'ArcanistUnitWorkflow' => 'ArcanistBaseWorkflow',
     'ArcanistUpgradeWorkflow' => 'ArcanistBaseWorkflow',
diff --git a/src/workflow/ArcanistTodoWorkflow.php b/src/workflow/ArcanistTodoWorkflow.php
new file mode 100644 (file)
index 0000000..a600c37
--- /dev/null
@@ -0,0 +1,98 @@
+<?php
+
+/*
+ * Copyright 2012 Facebook, Inc.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * Quickly create a task
+ *
+ * @group workflow
+ */
+final class ArcanistTodoWorkflow extends ArcanistBaseWorkflow {
+
+  public function getCommandSynopses() {
+    return phutil_console_format(<<<EOTEXT
+      **todo** __summary__ [__options__]
+EOTEXT
+      );
+  }
+
+  public function getCommandHelp() {
+    return phutil_console_format(<<<EOTEXT
+        Quickly create a task for yourself.
+EOTEXT
+      );
+  }
+
+  public function requiresConduit() {
+    return true;
+  }
+
+  public function desiresWorkingCopy() {
+    return true;
+  }
+
+  public function requiresAuthentication() {
+    return true;
+  }
+
+
+  public function getArguments() {
+    return array(
+      '*' => 'summary',
+      'cc' => array(
+        'param' => 'cc',
+        'short' => 'C',
+        'repeat' => true,
+        'help'  => 'Other users to CC on the new task.',
+      ),
+    );
+  }
+
+  public function run() {
+    $summary = implode(' ', $this->getArgument('summary'));
+    $ccs = $this->getArgument('cc');
+    $conduit = $this->getConduit();
+
+    if (trim($summary) == '') {
+      echo "Please provide a summary.\n";
+      return;
+    }
+
+    $args = array(
+      'title' => $summary,
+      'ownerPHID' => $this->getUserPHID()
+    );
+
+    if ($ccs) {
+      $phids = array();
+      $users = $conduit->callMethodSynchronous(
+        'user.query',
+        array(
+          'usernames' => $ccs
+        ));
+      foreach ($users as $user => $info) {
+        $phids[] = $info['phid'];
+      }
+      $args['ccPHIDs'] = $phids;
+    }
+
+    $conduit->callMethodSynchronous(
+      'maniphest.createtask',
+      $args);
+  }
+
+}