1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-26 00:32:41 +01:00

Arcanst - add support for custom statuses to arc close workflow

Summary:
Fixes T4938. Now that we have customs statuses, this workflow needs to know about 'em.

One fun caveat is that Conduit isn't up and running to generate the help method, so I had to add a parameter to have the statuses list out. This could maybe be omitted since entering erroneous status options does indeed tell you the correct options.

Test Plan:
`arc close --list-status` -- got a list of statuses
`arc close T1` -- closed T1
`arc close T1` -- error T1 closed already
`arc close T1 -s foobar` -- T1 status set to foobar

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T1, T4938

Differential Revision: https://secure.phabricator.com/D8938
This commit is contained in:
Bob Trahan 2014-05-01 16:14:03 -07:00
parent c4ec22b140
commit 96d3416218

View file

@ -8,15 +8,28 @@
final class ArcanistCloseWorkflow extends ArcanistBaseWorkflow { final class ArcanistCloseWorkflow extends ArcanistBaseWorkflow {
private $tasks; private $tasks;
private $statusOptions = array( private $statusOptions;
"resolved" => 1, private $statusData;
"wontfix" => 2,
"invalid" => 3,
"duplicate" => 4,
"spite" => 5,
"open" => 0
);
private function loadStatusData() {
$this->statusData = $this->getConduit()->callMethodSynchronous(
'maniphest.querystatuses',
array());
return $this;
}
private function getStatusOptions() {
if ($this->statusData === null) {
throw new Exception('loadStatusData first!');
}
return idx($this->statusData, 'statusMap');
}
private function getDefaultClosedStatus() {
if ($this->statusData === null) {
throw new Exception('loadStatusData first!');
}
return idx($this->statusData, 'defaultClosedStatus');
}
public function getWorkflowName() { public function getWorkflowName() {
return 'close'; return 'close';
@ -31,7 +44,7 @@ EOTEXT
public function getCommandHelp() { public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT return phutil_console_format(<<<EOTEXT
Close a task. Close a task or otherwise update its status.
EOTEXT EOTEXT
); );
} }
@ -50,37 +63,45 @@ EOTEXT
public function getArguments() { public function getArguments() {
$options = array_keys($this->statusOptions);
$last = array_pop($options);
return array( return array(
'*' => 'task_id', '*' => 'task_id',
'message' => array( 'message' => array(
'short' => 'm', 'short' => 'm',
'param' => 'comment', 'param' => 'comment',
'help' => "Provide a comment with your status change.", 'help' => pht('Provide a comment with your status change.'),
), ),
'status' => array( 'status' => array(
'param' => 'status', 'param' => 'status',
'short' => 's', 'short' => 's',
'help' => "New status. Valid options are ". 'help' => pht('Specify a new status. Valid status options can be '.
implode(', ', $options).", or {$last}. Default is resolved.\n" 'seen with the `list-statuses` argument.'),
),
'list-statuses' => array(
'help' => 'Show available status options and exit.',
), ),
); );
} }
public function run() { public function run() {
$this->loadStatusData();
$list_statuses = $this->getArgument('list-statuses');
if ($list_statuses) {
echo phutil_console_format(pht(
"Valid status options are:\n".
"\t%s\n", implode($this->getStatusOptions(), ', ')));
return 0;
}
$ids = $this->getArgument('task_id'); $ids = $this->getArgument('task_id');
$message = $this->getArgument('message'); $message = $this->getArgument('message');
$status = strtolower($this->getArgument('status')); $status = strtolower($this->getArgument('status'));
$status_options = $this->getStatusOptions();
if (!isset($status) || $status == '') { if (!isset($status) || $status == '') {
$status = head_key($this->statusOptions); $status = $this->getDefaultClosedStatus();
} }
if (isset($this->statusOptions[$status])) { if (!isset($status_options[$status])) {
$status = $this->statusOptions[$status]; $options = array_keys($status_options);
} else {
$options = array_keys($this->statusOptions);
$last = array_pop($options); $last = array_pop($options);
echo "Invalid status {$status}, valid options are ". echo "Invalid status {$status}, valid options are ".
implode(', ', $options).", or {$last}.\n"; implode(', ', $options).", or {$last}.\n";
@ -94,7 +115,6 @@ EOTEXT
} }
$id = ltrim($id, 'T'); $id = ltrim($id, 'T');
$result = $this->closeTask($id, $status, $message); $result = $this->closeTask($id, $status, $message);
$status_options = array_flip($this->statusOptions);
$current_status = $status_options[$status]; $current_status = $status_options[$status];
if ($result) { if ($result) {
echo "T{$id}'s status is now set to {$current_status}.\n"; echo "T{$id}'s status is now set to {$current_status}.\n";
@ -105,7 +125,7 @@ EOTEXT
return 0; return 0;
} }
private function closeTask($task_id, $status = 1, $comment = "") { private function closeTask($task_id, $status, $comment = "") {
$conduit = $this->getConduit(); $conduit = $this->getConduit();
$info = $conduit->callMethodSynchronous( $info = $conduit->callMethodSynchronous(
'maniphest.info', 'maniphest.info',