Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistTasksWorkflow.php
| Show All 38 Lines | public function requiresAuthentication() { | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function getArguments() { | public function getArguments() { | ||||
| return array( | return array( | ||||
| 'status' => array( | 'status' => array( | ||||
| 'param' => 'task_status', | 'param' => 'task_status', | ||||
| 'help' => "Show tasks that or open or closed, default is open.", | 'help' => 'Show tasks that or open or closed, default is open.', | ||||
| ), | ), | ||||
| 'owner' => array( | 'owner' => array( | ||||
| 'param' => 'username', | 'param' => 'username', | ||||
| 'paramtype' => 'username', | 'paramtype' => 'username', | ||||
| 'help' => | 'help' => | ||||
| "Only show tasks assigned to the given username, ". | 'Only show tasks assigned to the given username, '. | ||||
| "also accepts @all to show all, default is you.", | 'also accepts @all to show all, default is you.', | ||||
| 'conflict' => array( | 'conflict' => array( | ||||
| "unassigned" => "--owner suppresses unassigned", | 'unassigned' => '--owner suppresses unassigned', | ||||
| ), | ), | ||||
| ), | ), | ||||
| 'order' => array( | 'order' => array( | ||||
| 'param' => 'task_order', | 'param' => 'task_order', | ||||
| 'help' => | 'help' => | ||||
| "Arrange tasks based on priority, created, or modified, ". | 'Arrange tasks based on priority, created, or modified, '. | ||||
| "default is priority.", | 'default is priority.', | ||||
| ), | ), | ||||
| 'limit' => array( | 'limit' => array( | ||||
| 'param' => 'n', | 'param' => 'n', | ||||
| 'paramtype' => 'int', | 'paramtype' => 'int', | ||||
| 'help' => "Limit the amount of tasks outputted, default is all.", | 'help' => 'Limit the amount of tasks outputted, default is all.', | ||||
| ), | ), | ||||
| 'unassigned' => array( | 'unassigned' => array( | ||||
| 'help' => "Only show tasks that are not assigned (upforgrabs).", | 'help' => 'Only show tasks that are not assigned (upforgrabs).', | ||||
| ) | ) | ||||
| ); | ); | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
| $output = array(); | $output = array(); | ||||
| $status = $this->getArgument('status'); | $status = $this->getArgument('status'); | ||||
| $owner = $this->getArgument('owner'); | $owner = $this->getArgument('owner'); | ||||
| $order = $this->getArgument('order'); | $order = $this->getArgument('order'); | ||||
| $limit = $this->getArgument('limit'); | $limit = $this->getArgument('limit'); | ||||
| $unassigned = $this->getArgument('unassigned'); | $unassigned = $this->getArgument('unassigned'); | ||||
| if ($owner) { | if ($owner) { | ||||
| $owner_phid = $this->findOwnerPhid($owner); | $owner_phid = $this->findOwnerPhid($owner); | ||||
| } elseif ($unassigned) { | } else if ($unassigned) { | ||||
| $owner_phid = null; | $owner_phid = null; | ||||
| } else { | } else { | ||||
| $owner_phid = $this->getUserPHID(); | $owner_phid = $this->getUserPHID(); | ||||
| } | } | ||||
| $this->tasks = $this->loadManiphestTasks( | $this->tasks = $this->loadManiphestTasks( | ||||
| ($status == 'all' ? 'any' : $status), | ($status == 'all' ? 'any' : $status), | ||||
| $owner_phid, | $owner_phid, | ||||
| $order, | $order, | ||||
| $limit); | $limit); | ||||
| if (!$this->tasks) { | if (!$this->tasks) { | ||||
| echo "No tasks found.\n"; | echo "No tasks found.\n"; | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| $task_rows = array(); | $task_rows = array(); | ||||
| foreach ($this->tasks as $task) { | foreach ($this->tasks as $task) { | ||||
| $output = array(); | $output = array(); | ||||
| // Render the "T123" column. | // Render the "T123" column. | ||||
| $task_id = "T".$task['id']; | $task_id = 'T'.$task['id']; | ||||
| $formatted_task_id = phutil_console_format( | $formatted_task_id = phutil_console_format( | ||||
| '**%s**', | '**%s**', | ||||
| $task_id); | $task_id); | ||||
| $output['id'] = array( | $output['id'] = array( | ||||
| 'text' => $formatted_task_id, | 'text' => $formatted_task_id, | ||||
| 'len' => phutil_utf8_console_strlen($task_id), | 'len' => phutil_utf8_console_strlen($task_id), | ||||
| ); | ); | ||||
| ▲ Show 20 Lines • Show All 53 Lines • ▼ Show 20 Lines | foreach ($this->tasks as $task) { | ||||
| "<bg:{$status_color}> </bg> %s", | "<bg:{$status_color}> </bg> %s", | ||||
| $status_text); | $status_text); | ||||
| $output['status'] = array( | $output['status'] = array( | ||||
| 'text' => $formatted_status, | 'text' => $formatted_status, | ||||
| 'len' => phutil_utf8_console_strlen('status') + 2, | 'len' => phutil_utf8_console_strlen('status') + 2, | ||||
| ); | ); | ||||
| } else { | } else { | ||||
| $output['status'] = array( | $output['status'] = array( | ||||
| 'text' => "", | 'text' => '', | ||||
| 'len' => 0, | 'len' => 0, | ||||
| ); | ); | ||||
| } | } | ||||
| $task_rows[] = $output; | $task_rows[] = $output; | ||||
| } | } | ||||
| // Find the longest string in each column. | // Find the longest string in each column. | ||||
| ▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | private function loadManiphestTasks($status, $owner_phid, $order, $limit) { | ||||
| if ($owner_phid !== null) { | if ($owner_phid !== null) { | ||||
| $find_params['ownerPHIDs'] = array($owner_phid); | $find_params['ownerPHIDs'] = array($owner_phid); | ||||
| } | } | ||||
| if ($limit !== false) { | if ($limit !== false) { | ||||
| $find_params['limit'] = $limit; | $find_params['limit'] = $limit; | ||||
| } | } | ||||
| $find_params['order'] = ($order ? "order-".$order : "order-priority"); | $find_params['order'] = ($order ? 'order-'.$order : 'order-priority'); | ||||
| $find_params['status'] = ($status ? "status-".$status : "status-open"); | $find_params['status'] = ($status ? 'status-'.$status : 'status-open'); | ||||
| $tasks = $conduit->callMethodSynchronous( | $tasks = $conduit->callMethodSynchronous( | ||||
| 'maniphest.query', | 'maniphest.query', | ||||
| $find_params); | $find_params); | ||||
| return $tasks; | return $tasks; | ||||
| } | } | ||||
| } | } | ||||