2012-04-08 20:55:10 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
2014-07-09 09:12:13 +10:00
|
|
|
* Close a task.
|
2012-04-08 20:55:10 -07:00
|
|
|
*/
|
|
|
|
final class ArcanistCloseWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
private $tasks;
|
2014-05-01 16:14:03 -07:00
|
|
|
private $statusOptions;
|
|
|
|
private $statusData;
|
|
|
|
|
|
|
|
private function loadStatusData() {
|
|
|
|
$this->statusData = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'maniphest.querystatuses',
|
|
|
|
array());
|
|
|
|
return $this;
|
|
|
|
}
|
2012-04-08 20:55:10 -07:00
|
|
|
|
2014-05-01 16:14:03 -07:00
|
|
|
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');
|
|
|
|
}
|
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 08:35:03 -07:00
|
|
|
|
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'close';
|
|
|
|
}
|
|
|
|
|
2012-04-08 20:55:10 -07:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**close** __task_id__ [__options__]
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2014-05-01 16:14:03 -07:00
|
|
|
Close a task or otherwise update its status.
|
2012-04-08 20:55:10 -07:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
return array(
|
|
|
|
'*' => 'task_id',
|
|
|
|
'message' => array(
|
|
|
|
'short' => 'm',
|
|
|
|
'param' => 'comment',
|
2014-05-01 16:14:03 -07:00
|
|
|
'help' => pht('Provide a comment with your status change.'),
|
2012-04-08 20:55:10 -07:00
|
|
|
),
|
|
|
|
'status' => array(
|
|
|
|
'param' => 'status',
|
|
|
|
'short' => 's',
|
2014-07-09 09:12:13 +10:00
|
|
|
'help' => pht(
|
|
|
|
'Specify a new status. Valid status options can be '.
|
|
|
|
'seen with the `list-statuses` argument.'),
|
2014-05-01 16:14:03 -07:00
|
|
|
),
|
|
|
|
'list-statuses' => array(
|
|
|
|
'help' => 'Show available status options and exit.',
|
2012-04-08 20:55:10 -07:00
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
2014-05-01 16:14:03 -07:00
|
|
|
$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;
|
|
|
|
}
|
2012-04-08 20:55:10 -07:00
|
|
|
$ids = $this->getArgument('task_id');
|
|
|
|
$message = $this->getArgument('message');
|
|
|
|
$status = strtolower($this->getArgument('status'));
|
|
|
|
|
2014-05-01 16:14:03 -07:00
|
|
|
$status_options = $this->getStatusOptions();
|
2012-04-08 20:55:10 -07:00
|
|
|
if (!isset($status) || $status == '') {
|
2014-05-01 16:14:03 -07:00
|
|
|
$status = $this->getDefaultClosedStatus();
|
2012-04-08 20:55:10 -07:00
|
|
|
}
|
|
|
|
|
2014-05-01 16:14:03 -07:00
|
|
|
if (!isset($status_options[$status])) {
|
|
|
|
$options = array_keys($status_options);
|
2012-04-08 20:55:10 -07:00
|
|
|
$last = array_pop($options);
|
|
|
|
echo "Invalid status {$status}, valid options are ".
|
|
|
|
implode(', ', $options).", or {$last}.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
2014-05-23 13:53:05 -07:00
|
|
|
if (!preg_match('/^T?\d+$/', $id)) {
|
2012-04-08 20:55:10 -07:00
|
|
|
echo "Invalid Task ID: {$id}.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$id = ltrim($id, 'T');
|
|
|
|
$result = $this->closeTask($id, $status, $message);
|
|
|
|
$current_status = $status_options[$status];
|
|
|
|
if ($result) {
|
|
|
|
echo "T{$id}'s status is now set to {$current_status}.\n";
|
|
|
|
} else {
|
|
|
|
echo "T{$id} is already set to {$current_status}.\n";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2014-05-23 13:53:05 -07:00
|
|
|
private function closeTask($task_id, $status, $comment = '') {
|
2012-04-08 20:55:10 -07:00
|
|
|
$conduit = $this->getConduit();
|
|
|
|
$info = $conduit->callMethodSynchronous(
|
|
|
|
'maniphest.info',
|
|
|
|
array(
|
|
|
|
'task_id' => $task_id
|
|
|
|
));
|
|
|
|
if ($info['status'] == $status) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $conduit->callMethodSynchronous(
|
|
|
|
'maniphest.update',
|
|
|
|
array(
|
|
|
|
'id' => $task_id,
|
|
|
|
'status' => $status,
|
|
|
|
'comments' => $comment
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|