From f4615cd86b9607472ee22d72a4efa4b9ad93589a Mon Sep 17 00:00:00 2001 From: Joshua Spence Date: Thu, 10 Jul 2014 21:48:49 +1000 Subject: [PATCH] Allow the `todo` workflow to add project tags. 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.connect() >>> [1] http://phabricator.joshuaspence.com/api/conduit.connect <<< [1] 1,050,487 us <<< [0] 1,051,585 us >>> [2] project.query() >>> [3] http://phabricator.joshuaspence.com/api/project.query <<< [3] 294,584 us <<< [2] 294,986 us >>> [4] maniphest.createtask() >>> [5] http://phabricator.joshuaspence.com/api/maniphest.createtask <<< [5] 637,693 us <<< [4] 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 | 41 +++++++++++++++++++++------ 1 file changed, 32 insertions(+), 9 deletions(-) diff --git a/src/workflow/ArcanistTodoWorkflow.php b/src/workflow/ArcanistTodoWorkflow.php index b9f99022..934e3e90 100644 --- a/src/workflow/ArcanistTodoWorkflow.php +++ b/src/workflow/ArcanistTodoWorkflow.php @@ -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' => 'Other users to CC on the new task.', + 'help' => pht('Other users to CC on the new task.'), + ), + 'project' => array( + 'param' => 'project', + 'repeat' => true, + '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: '**%s**' at **%s**\n", $result['id'],