diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 5d37794b..513df7fd 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -90,6 +90,7 @@ phutil_register_library_map(array( 'ArcanistSubversionAPI' => 'repository/api/subversion', 'ArcanistSubversionHookAPI' => 'repository/hookapi/subversion', 'ArcanistSvnHookPreCommitWorkflow' => 'workflow/svn-hook-pre-commit', + 'ArcanistTasksWorkflow' => 'workflow/tasks', 'ArcanistTextLinter' => 'lint/linter/text', 'ArcanistTextLinterTestCase' => 'lint/linter/text/__tests__', 'ArcanistUncommittedChangesException' => 'exception/usage/uncommittedchanges', @@ -168,6 +169,7 @@ phutil_register_library_map(array( 'ArcanistSubversionAPI' => 'ArcanistRepositoryAPI', 'ArcanistSubversionHookAPI' => 'ArcanistHookAPI', 'ArcanistSvnHookPreCommitWorkflow' => 'ArcanistBaseWorkflow', + 'ArcanistTasksWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistTextLinter' => 'ArcanistLinter', 'ArcanistTextLinterTestCase' => 'ArcanistLinterTestCase', 'ArcanistUncommittedChangesException' => 'ArcanistUsageException', diff --git a/src/workflow/tasks/ArcanistTasksWorkflow.php b/src/workflow/tasks/ArcanistTasksWorkflow.php new file mode 100644 index 00000000..bdf3d5ab --- /dev/null +++ b/src/workflow/tasks/ArcanistTasksWorkflow.php @@ -0,0 +1,182 @@ + array( + 'param' => 'task_status', + 'help' => "Show tasks that or open or closed, default is all.", + ), + 'owner' => array( + 'param' => 'username', + 'paramtype' => 'username', + 'help' => + "Only show tasks assigned to the given username, ". + "also accepts @all to show all, default is you.", + ), + 'order' => array( + 'param' => 'task_order', + 'help' => + "Arrange tasks based on priority, created, or modified, ". + "default is priority.", + ), + 'limit' => array( + 'param' => 'n', + 'paramtype' => 'int', + 'help' => "Limit the amount of tasks outputted, default is all.", + ) + ); + } + + public function run() { + $output = array(); + + $status = $this->getArgument('status'); + $owner = $this->getArgument('owner'); + $order = $this->getArgument('order'); + $limit = $this->getArgument('limit'); + $this->tasks = $this->loadManiphestTasks( + ($status == 'all'?'any':$status), + ($owner?$this->findOwnerPhid($owner):$this->getUserPHID()), + $order, + $limit + ); + + foreach ($this->tasks as $task) { + $tid = "T{$task['id']}"; + switch ($task['priority']) { + case 'Needs Triage': + $color = 'magenta'; + break; + case 'Unbreak Now!': + $color = 'red'; + break; + case 'High': + $color = 'yellow'; + break; + case 'Normal': + $color = 'green'; + break; + case 'Low': + $color = 'blue'; + break; + case 'Wishlist': + $color = 'cyan'; + break; + default: + $color = 'white'; + break; + } + $task_priority = $task['priority']; + $priority = phutil_console_format(" {$task_priority}"); + $output[] = array(phutil_console_format("**{$tid}**"), + $task['title'], + $priority, + ($task['status']? + phutil_console_format(" Closed"): + phutil_console_format(' Open')) + ); + } + $this->render($output); + } + + private function render($table) { + $column_length = array(); + foreach ($table as $row) { + foreach ($row as $col => $cell) { + if (!isset($column_length[$col])) + $column_length[$col] = 0; + if (strlen($cell) > $column_length[$col]) + $column_length[$col] = strlen($cell); + } + } + foreach ($table as $row) { + foreach ($row as $col => $cell) { + echo $cell.str_repeat(' ', $column_length[$col] - strlen($cell) + 4); + } + echo "\n"; + } + } + + private function findOwnerPhid($owner) { + $conduit = $this->getConduit(); + $owner_phid = $conduit->callMethodSynchronous( + 'user.find', + array( + 'aliases' => array($owner), + )); + return (isset($owner_phid[$owner])?$owner_phid[$owner]:false); + } + + private function loadManiphestTasks($status, $owner_phid, $order, $limit) { + $conduit = $this->getConduit(); + + $find_params = array(); + if ($owner_phid !== false) { + $find_params['ownerPHIDs'] = array($owner_phid); + } + if ($limit !== false) { + $find_params['limit'] = $limit; + } + $find_params['order'] = ($order?"order-".$order:"order-priority"); + $find_params['status'] = ($status?"status-".$status:"status-open"); + + $tasks = $conduit->callMethodSynchronous( + 'maniphest.find', + $find_params + ); + return $tasks; + } + +} diff --git a/src/workflow/tasks/__init__.php b/src/workflow/tasks/__init__.php new file mode 100644 index 00000000..49517604 --- /dev/null +++ b/src/workflow/tasks/__init__.php @@ -0,0 +1,14 @@ +