2012-04-08 02:40:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-07-09 01:12:13 +02:00
|
|
|
* Displays User Tasks.
|
2012-04-08 02:40:25 +02:00
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistTasksWorkflow extends ArcanistWorkflow {
|
2012-04-08 02:40:25 +02:00
|
|
|
|
|
|
|
private $tasks;
|
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'tasks';
|
|
|
|
}
|
|
|
|
|
2012-04-08 02:40:25 +02:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**tasks** [__options__]
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
View all assigned tasks.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'status' => array(
|
|
|
|
'param' => 'task_status',
|
2015-05-13 10:05:15 +02:00
|
|
|
'help' => pht('Show tasks that or open or closed, default is open.'),
|
2012-04-08 02:40:25 +02:00
|
|
|
),
|
|
|
|
'owner' => array(
|
|
|
|
'param' => 'username',
|
|
|
|
'paramtype' => 'username',
|
2015-05-13 10:05:15 +02:00
|
|
|
'help' => pht(
|
2014-05-23 22:53:05 +02:00
|
|
|
'Only show tasks assigned to the given username, '.
|
2015-05-13 10:05:15 +02:00
|
|
|
'also accepts %s to show all, default is you.',
|
|
|
|
'@all'),
|
2013-05-23 19:32:41 +02:00
|
|
|
'conflict' => array(
|
2015-05-13 10:05:15 +02:00
|
|
|
'unassigned' => pht('%s suppresses unassigned', '--owner'),
|
2013-05-23 19:32:41 +02:00
|
|
|
),
|
2012-04-08 02:40:25 +02:00
|
|
|
),
|
|
|
|
'order' => array(
|
|
|
|
'param' => 'task_order',
|
2015-05-13 10:05:15 +02:00
|
|
|
'help' => pht(
|
2014-05-23 22:53:05 +02:00
|
|
|
'Arrange tasks based on priority, created, or modified, '.
|
2015-05-13 10:05:15 +02:00
|
|
|
'default is priority.'),
|
2012-04-08 02:40:25 +02:00
|
|
|
),
|
|
|
|
'limit' => array(
|
|
|
|
'param' => 'n',
|
|
|
|
'paramtype' => 'int',
|
2015-05-13 10:05:15 +02:00
|
|
|
'help' => pht('Limit the amount of tasks outputted, default is all.'),
|
2013-05-23 19:32:41 +02:00
|
|
|
),
|
|
|
|
'unassigned' => array(
|
2015-05-13 10:05:15 +02:00
|
|
|
'help' => pht('Only show tasks that are not assigned (upforgrabs).'),
|
2014-06-17 19:01:39 +02:00
|
|
|
),
|
2012-04-08 02:40:25 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$output = array();
|
|
|
|
|
2013-05-23 19:32:41 +02:00
|
|
|
$status = $this->getArgument('status');
|
|
|
|
$owner = $this->getArgument('owner');
|
|
|
|
$order = $this->getArgument('order');
|
|
|
|
$limit = $this->getArgument('limit');
|
|
|
|
$unassigned = $this->getArgument('unassigned');
|
|
|
|
|
|
|
|
if ($owner) {
|
2013-06-05 00:29:39 +02:00
|
|
|
$owner_phid = $this->findOwnerPhid($owner);
|
2014-05-23 22:53:05 +02:00
|
|
|
} else if ($unassigned) {
|
2013-06-05 00:29:39 +02:00
|
|
|
$owner_phid = null;
|
2013-05-23 19:32:41 +02:00
|
|
|
} else {
|
2013-06-05 00:29:39 +02:00
|
|
|
$owner_phid = $this->getUserPHID();
|
2013-05-23 19:32:41 +02:00
|
|
|
}
|
|
|
|
|
2012-04-08 02:40:25 +02:00
|
|
|
$this->tasks = $this->loadManiphestTasks(
|
2012-10-01 04:40:54 +02:00
|
|
|
($status == 'all' ? 'any' : $status),
|
2013-06-05 00:29:39 +02:00
|
|
|
$owner_phid,
|
2012-04-08 02:40:25 +02:00
|
|
|
$order,
|
2012-10-01 04:40:54 +02:00
|
|
|
$limit);
|
2012-04-08 02:40:25 +02:00
|
|
|
|
2012-10-11 21:39:35 +02:00
|
|
|
if (!$this->tasks) {
|
2015-05-13 10:05:15 +02:00
|
|
|
echo pht('No tasks found.')."\n";
|
2012-10-11 21:39:35 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-06-17 19:01:39 +02:00
|
|
|
$table = id(new PhutilConsoleTable())
|
|
|
|
->setShowHeader(false)
|
2015-05-13 10:05:15 +02:00
|
|
|
->addColumn('id', array('title' => pht('ID')))
|
|
|
|
->addColumn('title', array('title' => pht('Title')))
|
|
|
|
->addColumn('priority', array('title' => pht('Priority')))
|
|
|
|
->addColumn('status', array('title' => pht('Status')));
|
2014-06-17 19:01:39 +02:00
|
|
|
|
2012-04-08 02:40:25 +02:00
|
|
|
foreach ($this->tasks as $task) {
|
2012-10-01 04:40:54 +02:00
|
|
|
$output = array();
|
|
|
|
|
|
|
|
// Render the "T123" column.
|
2014-05-23 22:53:05 +02:00
|
|
|
$task_id = 'T'.$task['id'];
|
2014-06-17 19:01:39 +02:00
|
|
|
$formatted_task_id = phutil_console_format('**%s**', $task_id);
|
|
|
|
$output['id'] = $formatted_task_id;
|
2012-10-01 04:40:54 +02:00
|
|
|
|
|
|
|
// Render the "Title" column.
|
|
|
|
$formatted_title = rtrim($task['title']);
|
2014-06-17 19:01:39 +02:00
|
|
|
$output['title'] = $formatted_title;
|
2014-04-09 21:13:34 +02:00
|
|
|
|
2012-10-01 04:40:54 +02:00
|
|
|
// Render the "Priority" column.
|
2014-04-09 21:13:34 +02:00
|
|
|
$web_to_terminal_colors = array(
|
|
|
|
'violet' => 'magenta',
|
|
|
|
'indigo' => 'magenta',
|
|
|
|
'orange' => 'red',
|
|
|
|
'sky' => 'cyan',
|
|
|
|
'red' => 'red',
|
|
|
|
'yellow' => 'yellow',
|
|
|
|
'green' => 'green',
|
|
|
|
'blue' => 'blue',
|
|
|
|
'cyan' => 'cyan',
|
|
|
|
'magenta' => 'magenta',
|
|
|
|
'lightred' => 'red',
|
|
|
|
'lightorange' => 'red',
|
|
|
|
'lightyellow' => 'yellow',
|
|
|
|
'lightgreen' => 'green',
|
|
|
|
'lightblue' => 'blue',
|
|
|
|
'lightsky' => 'blue',
|
|
|
|
'lightindigo' => 'magenta',
|
2014-06-17 19:01:39 +02:00
|
|
|
'lightviolet' => 'magenta',
|
2014-04-09 21:13:34 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
if (isset($task['priorityColor'])) {
|
|
|
|
$color = idx($web_to_terminal_colors, $task['priorityColor'], 'white');
|
|
|
|
} else {
|
|
|
|
$color = 'white';
|
2012-04-08 02:40:25 +02:00
|
|
|
}
|
2012-10-01 04:40:54 +02:00
|
|
|
$formatted_priority = phutil_console_format(
|
|
|
|
"<bg:{$color}> </bg> %s",
|
|
|
|
$task['priority']);
|
2014-06-17 19:01:39 +02:00
|
|
|
$output['priority'] = $formatted_priority;
|
2012-10-01 04:40:54 +02:00
|
|
|
|
|
|
|
// Render the "Status" column.
|
2014-04-09 16:48:24 +02:00
|
|
|
if (isset($task['isClosed'])) {
|
|
|
|
if ($task['isClosed']) {
|
|
|
|
$status_text = $task['statusName'];
|
|
|
|
$status_color = 'red';
|
|
|
|
} else {
|
|
|
|
$status_text = $task['statusName'];
|
|
|
|
$status_color = 'green';
|
|
|
|
}
|
|
|
|
$formatted_status = phutil_console_format(
|
|
|
|
"<bg:{$status_color}> </bg> %s",
|
|
|
|
$status_text);
|
2014-06-17 19:01:39 +02:00
|
|
|
$output['status'] = $formatted_status;
|
2012-10-01 04:40:54 +02:00
|
|
|
} else {
|
2014-06-17 19:01:39 +02:00
|
|
|
$output['status'] = '';
|
2012-04-08 02:40:25 +02:00
|
|
|
}
|
2012-10-01 04:40:54 +02:00
|
|
|
|
2014-06-17 19:01:39 +02:00
|
|
|
$table->addRow($output);
|
2012-10-01 04:40:54 +02:00
|
|
|
}
|
|
|
|
|
2014-06-17 19:01:39 +02:00
|
|
|
$table->draw();
|
2012-04-08 02:40:25 +02:00
|
|
|
}
|
|
|
|
|
2013-06-05 00:29:39 +02:00
|
|
|
private function findOwnerPHID($owner) {
|
2012-04-08 02:40:25 +02:00
|
|
|
$conduit = $this->getConduit();
|
2013-06-05 00:29:39 +02:00
|
|
|
|
2014-01-25 23:23:23 +01:00
|
|
|
$users = $conduit->callMethodSynchronous(
|
|
|
|
'user.query',
|
2012-04-08 02:40:25 +02:00
|
|
|
array(
|
2014-01-25 23:23:23 +01:00
|
|
|
'usernames' => array($owner),
|
2012-04-08 02:40:25 +02:00
|
|
|
));
|
2013-06-05 00:29:39 +02:00
|
|
|
|
2014-01-25 23:23:23 +01:00
|
|
|
if (!$users) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
$user = head($users);
|
|
|
|
return idx($user, 'phid');
|
2012-04-08 02:40:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
private function loadManiphestTasks($status, $owner_phid, $order, $limit) {
|
|
|
|
$conduit = $this->getConduit();
|
|
|
|
|
|
|
|
$find_params = array();
|
2013-06-05 00:29:39 +02:00
|
|
|
if ($owner_phid !== null) {
|
2012-04-08 02:40:25 +02:00
|
|
|
$find_params['ownerPHIDs'] = array($owner_phid);
|
|
|
|
}
|
2013-06-05 00:29:39 +02:00
|
|
|
|
2012-04-08 02:40:25 +02:00
|
|
|
if ($limit !== false) {
|
|
|
|
$find_params['limit'] = $limit;
|
|
|
|
}
|
2013-06-05 00:29:39 +02:00
|
|
|
|
2014-05-23 22:53:05 +02:00
|
|
|
$find_params['order'] = ($order ? 'order-'.$order : 'order-priority');
|
|
|
|
$find_params['status'] = ($status ? 'status-'.$status : 'status-open');
|
2012-04-08 02:40:25 +02:00
|
|
|
|
2014-06-17 19:01:39 +02:00
|
|
|
return $conduit->callMethodSynchronous('maniphest.query', $find_params);
|
2012-04-08 02:40:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|