From e7d9ff18d3a21739903c18ab358e6b437e8e2105 Mon Sep 17 00:00:00 2001 From: Koolvin Date: Sun, 8 Apr 2012 20:55:10 -0700 Subject: [PATCH] Add arc close command Summary: ```arc close T1088 --status wontfix --message "I'm not going to fix this."``` T1088 is the test task to screw with, so feel free. Test Plan: ```arc close T1088 --status [ resolved | wontfix | invalid | duplicate | spite | open ] -m "Message"``` Reviewers: epriestley CC: aran Differential Revision: https://secure.phabricator.com/D2162 --- src/__phutil_library_map__.php | 2 + src/workflow/close/ArcanistCloseWorkflow.php | 138 +++++++++++++++++++ src/workflow/close/__init__.php | 15 ++ 3 files changed, 155 insertions(+) create mode 100644 src/workflow/close/ArcanistCloseWorkflow.php create mode 100644 src/workflow/close/__init__.php diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 513df7fd..e5a92876 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -21,6 +21,7 @@ phutil_register_library_map(array( 'ArcanistCapabilityNotSupportedException' => 'workflow/exception/notsupported', 'ArcanistChooseInvalidRevisionException' => 'exception', 'ArcanistChooseNoRevisionsException' => 'exception', + 'ArcanistCloseWorkflow' => 'workflow/close', 'ArcanistCommitWorkflow' => 'workflow/commit', 'ArcanistConduitLinter' => 'lint/linter/conduit', 'ArcanistConfiguration' => 'configuration', @@ -126,6 +127,7 @@ phutil_register_library_map(array( 'ArcanistBranchWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistBundleTestCase' => 'ArcanistPhutilTestCase', 'ArcanistCallConduitWorkflow' => 'ArcanistBaseWorkflow', + 'ArcanistCloseWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistCommitWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistConduitLinter' => 'ArcanistLinter', 'ArcanistCoverWorkflow' => 'ArcanistBaseWorkflow', diff --git a/src/workflow/close/ArcanistCloseWorkflow.php b/src/workflow/close/ArcanistCloseWorkflow.php new file mode 100644 index 00000000..ee2d052f --- /dev/null +++ b/src/workflow/close/ArcanistCloseWorkflow.php @@ -0,0 +1,138 @@ + 1, + "wontfix" => 2, + "invalid" => 3, + "duplicate" => 4, + "spite" => 5, + "open" => 0 + ); + + public function getCommandSynopses() { + return phutil_console_format(<<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 + )); + } + +} diff --git a/src/workflow/close/__init__.php b/src/workflow/close/__init__.php new file mode 100644 index 00000000..54b89097 --- /dev/null +++ b/src/workflow/close/__init__.php @@ -0,0 +1,15 @@ +