2012-04-09 05:55:10 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Close a task
|
|
|
|
*
|
|
|
|
* @group workflow
|
|
|
|
*/
|
|
|
|
final class ArcanistCloseWorkflow extends ArcanistBaseWorkflow {
|
|
|
|
|
|
|
|
private $tasks;
|
|
|
|
private $statusOptions = array(
|
|
|
|
"resolved" => 1,
|
|
|
|
"wontfix" => 2,
|
|
|
|
"invalid" => 3,
|
|
|
|
"duplicate" => 4,
|
|
|
|
"spite" => 5,
|
|
|
|
"open" => 0
|
|
|
|
);
|
|
|
|
|
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 'close';
|
|
|
|
}
|
|
|
|
|
2012-04-09 05:55:10 +02:00
|
|
|
public function getCommandSynopses() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**close** __task_id__ [__options__]
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
Close a task.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public function getArguments() {
|
|
|
|
$options = array_keys($this->statusOptions);
|
|
|
|
$last = array_pop($options);
|
|
|
|
return array(
|
|
|
|
'*' => 'task_id',
|
|
|
|
'message' => array(
|
|
|
|
'short' => 'm',
|
|
|
|
'param' => 'comment',
|
|
|
|
'help' => "Provide a comment with your status change.",
|
|
|
|
),
|
|
|
|
'status' => array(
|
|
|
|
'param' => 'status',
|
|
|
|
'short' => 's',
|
|
|
|
'help' => "New status. Valid options are ".
|
|
|
|
implode(', ', $options).", or {$last}. Default is resolved.\n"
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
|
|
|
$ids = $this->getArgument('task_id');
|
|
|
|
$message = $this->getArgument('message');
|
|
|
|
$status = strtolower($this->getArgument('status'));
|
|
|
|
|
|
|
|
if (!isset($status) || $status == '') {
|
|
|
|
$status = head_key($this->statusOptions);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($this->statusOptions[$status])) {
|
|
|
|
$status = $this->statusOptions[$status];
|
|
|
|
} else {
|
|
|
|
$options = array_keys($this->statusOptions);
|
|
|
|
$last = array_pop($options);
|
|
|
|
echo "Invalid status {$status}, valid options are ".
|
|
|
|
implode(', ', $options).", or {$last}.\n";
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($ids as $id) {
|
|
|
|
if (!preg_match("/^T?\d+$/", $id)) {
|
|
|
|
echo "Invalid Task ID: {$id}.\n";
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
$id = ltrim($id, 'T');
|
|
|
|
$result = $this->closeTask($id, $status, $message);
|
|
|
|
$status_options = array_flip($this->statusOptions);
|
|
|
|
$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;
|
|
|
|
}
|
|
|
|
|
|
|
|
private function closeTask($task_id, $status = 1, $comment = "") {
|
|
|
|
$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
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|