Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistCloseWorkflow.php
| Show All 12 Lines | private function loadStatusData() { | ||||
| $this->statusData = $this->getConduit()->callMethodSynchronous( | $this->statusData = $this->getConduit()->callMethodSynchronous( | ||||
| 'maniphest.querystatuses', | 'maniphest.querystatuses', | ||||
| array()); | array()); | ||||
| return $this; | return $this; | ||||
| } | } | ||||
| private function getStatusOptions() { | private function getStatusOptions() { | ||||
| if ($this->statusData === null) { | if ($this->statusData === null) { | ||||
| throw new Exception('loadStatusData first!'); | throw new Exception(pht('Call %s first!', 'loadStatusData()')); | ||||
| } | } | ||||
| return idx($this->statusData, 'statusMap'); | return idx($this->statusData, 'statusMap'); | ||||
| } | } | ||||
| private function getDefaultClosedStatus() { | private function getDefaultClosedStatus() { | ||||
| if ($this->statusData === null) { | if ($this->statusData === null) { | ||||
| throw new Exception('loadStatusData first!'); | throw new Exception(pht('Call %s first!', 'loadStatusData()')); | ||||
| } | } | ||||
| return idx($this->statusData, 'defaultClosedStatus'); | return idx($this->statusData, 'defaultClosedStatus'); | ||||
| } | } | ||||
| public function getWorkflowName() { | public function getWorkflowName() { | ||||
| return 'close'; | return 'close'; | ||||
| } | } | ||||
| Show All 32 Lines | return array( | ||||
| 'param' => 'comment', | 'param' => 'comment', | ||||
| 'help' => pht('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' => pht( | 'help' => pht( | ||||
| 'Specify a new status. Valid status options can be '. | 'Specify a new status. Valid status options can be '. | ||||
| 'seen with the `list-statuses` argument.'), | 'seen with the `%s` argument.', | ||||
| 'list-statuses'), | |||||
| ), | ), | ||||
| 'list-statuses' => array( | 'list-statuses' => array( | ||||
| 'help' => 'Show available status options and exit.', | 'help' => pht('Show available status options and exit.'), | ||||
| ), | ), | ||||
| ); | ); | ||||
| } | } | ||||
| public function run() { | public function run() { | ||||
| $this->loadStatusData(); | $this->loadStatusData(); | ||||
| $list_statuses = $this->getArgument('list-statuses'); | $list_statuses = $this->getArgument('list-statuses'); | ||||
| if ($list_statuses) { | if ($list_statuses) { | ||||
| echo phutil_console_format(pht( | echo phutil_console_format( | ||||
| "Valid status options are:\n". | "%s\n", | ||||
| "\t%s\n", implode($this->getStatusOptions(), ', '))); | pht( | ||||
| "Valid status options are:\n\t%s", | |||||
| implode($this->getStatusOptions(), ', '))); | |||||
| return 0; | 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(); | $status_options = $this->getStatusOptions(); | ||||
| if (!isset($status) || $status == '') { | if (!isset($status) || $status == '') { | ||||
| $status = $this->getDefaultClosedStatus(); | $status = $this->getDefaultClosedStatus(); | ||||
| } | } | ||||
| if (!isset($status_options[$status])) { | if (!isset($status_options[$status])) { | ||||
| $options = array_keys($status_options); | $options = array_keys($status_options); | ||||
| $last = array_pop($options); | $last = array_pop($options); | ||||
| echo "Invalid status {$status}, valid options are ". | echo pht( | ||||
| implode(', ', $options).", or {$last}.\n"; | "Invalid status %s, valid options are %s, or %s.\n", | ||||
| $status, | |||||
| implode(', ', $options), | |||||
| $last); | |||||
| return; | return; | ||||
| } | } | ||||
| foreach ($ids as $id) { | foreach ($ids as $id) { | ||||
| if (!preg_match('/^T?\d+$/', $id)) { | if (!preg_match('/^T?\d+$/', $id)) { | ||||
| echo "Invalid Task ID: {$id}.\n"; | echo pht('Invalid Task ID: %s.', $id)."\n"; | ||||
| return 1; | return 1; | ||||
| } | } | ||||
| $id = ltrim($id, 'T'); | $id = ltrim($id, 'T'); | ||||
| $result = $this->closeTask($id, $status, $message); | $result = $this->closeTask($id, $status, $message); | ||||
| $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 pht( | ||||
| "%s's status is now set to %s.\n", | |||||
| "T{$id}", | |||||
| $current_status); | |||||
| } else { | } else { | ||||
| echo "T{$id} is already set to {$current_status}.\n"; | echo pht( | ||||
| "%s is already set to %s.\n", | |||||
| "T{$id}", | |||||
| $current_status); | |||||
| } | } | ||||
| } | } | ||||
| return 0; | return 0; | ||||
| } | } | ||||
| private function closeTask($task_id, $status, $comment = '') { | private function closeTask($task_id, $status, $comment = '') { | ||||
| $conduit = $this->getConduit(); | $conduit = $this->getConduit(); | ||||
| $info = $conduit->callMethodSynchronous( | $info = $conduit->callMethodSynchronous( | ||||
| Show All 17 Lines | |||||