]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Allow the `todo` workflow to add project tags.
authorJoshua Spence <josh@joshuaspence.com>
Thu, 10 Jul 2014 11:48:49 +0000 (21:48 +1000)
committerJoshua Spence <josh@joshuaspence.com>
Thu, 10 Jul 2014 11:48:49 +0000 (21:48 +1000)
Summary: Fixes T4418. Allows Maniphests created through the `arc todo` workflow to have projects assigned.

Test Plan:
```
> ./bin/arc --trace --conduit-uri='http://phabricator.joshuaspence.com' todo "Test project" --project foo --project bar
libphutil loaded from '/home/joshua/workspace/github.com/phacility/libphutil/src'.
arcanist loaded from '/home/joshua/workspace/github.com/phacility/arcanist/src'.
Config: Reading user configuration file "/home/joshua/.arcrc"...
Config: Did not find system configuration at "/etc/arcconfig".
Working Copy: Reading .arcconfig from "/home/joshua/workspace/github.com/phacility/arcanist/.arcconfig".
Working Copy: Path "/home/joshua/workspace/github.com/phacility/arcanist" is part of `git` working copy "/home/joshua/workspace/github.com/phacility/arcanist".
Working Copy: Project root is at "/home/joshua/workspace/github.com/phacility/arcanist".
Config: Did not find local configuration at "/home/joshua/workspace/github.com/phacility/arcanist/.git/arc/config".
Loading phutil library from '/home/joshua/workspace/github.com/phacility/arcanist/src'...
>>> [0] <conduit> conduit.connect() <bytes = 618>
>>> [1] <http> http://phabricator.joshuaspence.com/api/conduit.connect
<<< [1] <http> 1,050,487 us
<<< [0] <conduit> 1,051,585 us
>>> [2] <conduit> project.query() <bytes = 199>
>>> [3] <http> http://phabricator.joshuaspence.com/api/project.query
<<< [3] <http> 294,584 us
<<< [2] <conduit> 294,986 us
>>> [4] <conduit> maniphest.createtask() <bytes = 313>
>>> [5] <http> http://phabricator.joshuaspence.com/api/maniphest.createtask
<<< [5] <http> 637,693 us
<<< [4] <conduit> 638,098 us
Created task T6: 'Test project' at http://phabricator.joshuaspence.com/T6
```

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: epriestley, Korvin

Maniphest Tasks: T4418

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

src/workflow/ArcanistTodoWorkflow.php

index b9f990228b01044e9f942972d998927682f6f45a..934e3e906549a39787493bf650703faee0c1d31a 100644 (file)
@@ -35,15 +35,19 @@ EOTEXT
     return true;
   }
 
-
   public function getArguments() {
     return array(
       '*' => 'summary',
       'cc' => array(
-        'param' => 'cc',
-        'short' => 'C',
+        'param'  => 'cc',
+        'short'  => 'C',
+        'repeat' => true,
+        'help'   => pht('Other users to CC on the new task.'),
+      ),
+      'project' => array(
+        'param'  => 'project',
         'repeat' => true,
-        'help'  => 'Other users to CC on the new task.',
+        'help'   => pht('Projects to assign to the task.'),
       ),
     );
   }
@@ -51,6 +55,8 @@ EOTEXT
   public function run() {
     $summary = implode(' ', $this->getArgument('summary'));
     $ccs = $this->getArgument('cc');
+    $slugs = $this->getArgument('project');
+
     $conduit = $this->getConduit();
 
     if (trim($summary) == '') {
@@ -60,7 +66,7 @@ EOTEXT
 
     $args = array(
       'title' => $summary,
-      'ownerPHID' => $this->getUserPHID()
+      'ownerPHID' => $this->getUserPHID(),
     );
 
     if ($ccs) {
@@ -68,7 +74,7 @@ EOTEXT
       $users = $conduit->callMethodSynchronous(
         'user.query',
         array(
-          'usernames' => $ccs
+          'usernames' => $ccs,
         ));
       foreach ($users as $user => $info) {
         $phids[] = $info['phid'];
@@ -76,10 +82,27 @@ EOTEXT
       $args['ccPHIDs'] = $phids;
     }
 
-    $result = $conduit->callMethodSynchronous(
-      'maniphest.createtask',
-      $args);
+    if ($slugs) {
+      $phids = array();
+      $projects = $conduit->callMethodSynchronous(
+        'project.query',
+        array(
+          'slugs' => $slugs,
+        ));
+
+      foreach ($slugs as $slug) {
+        $project = idx($projects['slugMap'], $slug);
+
+        if (!$project) {
+          throw new ArcanistUsageException('No such project: "'.$slug.'"');
+        }
+        $phids[] = $project;
+      }
+
+      $args['projectPHIDs'] = $phids;
+    }
 
+    $result = $conduit->callMethodSynchronous('maniphest.createtask', $args);
     echo phutil_console_format(
       "Created task T%s: '<fg:green>**%s**</fg>' at <fg:blue>**%s**</fg>\n",
       $result['id'],