Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistTasksWorkflow.php
Show First 20 Lines • Show All 47 Lines • ▼ Show 20 Lines | return array( | ||||
'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', | ||||
), | ), | ||||
), | ), | ||||
'project' => array( | |||||
'param' => 'project', | |||||
'help' => 'Only show tasks associated with the given project,'. | |||||
'also accepts project hastags.', | |||||
), | |||||
'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'); | ||||
$project = $this->getArgument('project'); | |||||
$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); | ||||
} else if ($unassigned) { | } else if ($unassigned) { | ||||
$owner_phid = null; | $owner_phid = null; | ||||
} else { | } else { | ||||
$owner_phid = $this->getUserPHID(); | $owner_phid = $this->getUserPHID(); | ||||
} | } | ||||
if ($project) { | |||||
$project_phid = $this->findProjectPHID($project); | |||||
} else { | |||||
$project_phid = null; | |||||
} | |||||
$this->tasks = $this->loadManiphestTasks( | $this->tasks = $this->loadManiphestTasks( | ||||
($status == 'all' ? 'any' : $status), | ($status == 'all' ? 'any' : $status), | ||||
$owner_phid, | $owner_phid, | ||||
$project_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; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 83 Lines • ▼ Show 20 Lines | private function findOwnerPHID($owner) { | ||||
if (!$users) { | if (!$users) { | ||||
return null; | return null; | ||||
} | } | ||||
$user = head($users); | $user = head($users); | ||||
return idx($user, 'phid'); | return idx($user, 'phid'); | ||||
} | } | ||||
private function loadManiphestTasks($status, $owner_phid, $order, $limit) { | private function findProjectPHID($project_name) { | ||||
$conduit = $this->getConduit(); | |||||
// Converts "My Project" to slug-equivalent "my_project". | |||||
$project_slug = str_replace(' ', '_', $project_name); | |||||
$project_slug = phutil_utf8_strtolower($project_slug); | |||||
$projects = $conduit->callMethodSynchronous( | |||||
'project.query', | |||||
array( | |||||
'slugs' => array($project_slug), | |||||
)); | |||||
$project = head(head($projects)); | |||||
if (!$project) { | |||||
$error = "Couldn't find project with name or hashtag \"$project_name\"."; | |||||
throw new ArcanistUsageException($error); | |||||
} | |||||
return idx($project, 'phid'); | |||||
} | |||||
private function loadManiphestTasks( | |||||
$status, | |||||
$owner_phid, | |||||
$project_phid, | |||||
$order, | |||||
$limit) { | |||||
$conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
$find_params = array(); | $find_params = array(); | ||||
if ($owner_phid !== null) { | if ($owner_phid !== null) { | ||||
$find_params['ownerPHIDs'] = array($owner_phid); | $find_params['ownerPHIDs'] = array($owner_phid); | ||||
} | } | ||||
if ($project_phid != null) { | |||||
$find_params['projectPHIDs'] = array($project_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'); | ||||
return $conduit->callMethodSynchronous('maniphest.query', $find_params); | return $conduit->callMethodSynchronous('maniphest.query', $find_params); | ||||
} | } | ||||
} | } |