Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistClaimWorkflow.php
- This file was added.
| <?php | |||||
| /** | |||||
| * Claim a task. | |||||
| */ | |||||
| final class ArcanistClaimWorkflow extends ArcanistWorkflow { | |||||
| public function getWorkflowName() { | |||||
| return 'claim'; | |||||
| } | |||||
| public function getCommandSynopses() { | |||||
| return phutil_console_format(<<<EOTEXT | |||||
| **claim** __task_id__ [__options__] | |||||
| EOTEXT | |||||
| ); | |||||
| } | |||||
| public function getCommandHelp() { | |||||
| return phutil_console_format(<<<EOTEXT | |||||
| Claim a task for yourself | |||||
| EOTEXT | |||||
| ); | |||||
| } | |||||
| public function requiresConduit() { | |||||
| return true; | |||||
| } | |||||
| public function requiresRepositoryAPI() { | |||||
| return false; | |||||
| } | |||||
| public function requiresAuthentication() { | |||||
| return true; | |||||
| } | |||||
| public function getArguments() { | |||||
| return array( | |||||
| '*' => 'task_id', | |||||
| /* 'release' => array( | |||||
| 'help' => 'Place the task back up for grabs' | |||||
| )*/ | |||||
| ); | |||||
| } | |||||
| public function run() { | |||||
| $ids = $this->getArgument('task_id'); | |||||
| $release = $this->getArgument('release'); | |||||
| foreach ($ids as $id) { | |||||
| if (!preg_match('/^T?\d+$/', $id)) { | |||||
| echo "Invalid Task ID: {$id}.\n"; | |||||
| return 1; | |||||
| } | |||||
| $id = ltrim($id, 'T'); | |||||
| if ($release) { | |||||
| $result = $this->releaseTask($id); | |||||
| if ($result) { | |||||
| echo "T{$id} is up for grabs.\n"; | |||||
| } else { | |||||
| echo "T{$id} is not assigned to you.\n"; | |||||
| } | |||||
| } else { | |||||
| $result = $this->claimTask($id); | |||||
| if ($result) { | |||||
| echo "T{$id} is now assigned to you.\n"; | |||||
| } else { | |||||
| echo "T{$id} is already assigned to you.\n"; | |||||
| } | |||||
| } | |||||
| } | |||||
| return 0; | |||||
| } | |||||
| // FIXME: maniphest.update does not accept a single null value | |||||
| private function releaseTask($task_id) { | |||||
| $conduit = $this->getConduit(); | |||||
| $info = $conduit->callMethodSynchronous( | |||||
| 'maniphest.info', | |||||
| array( | |||||
| 'task_id' => $task_id, | |||||
| )); | |||||
| if ($info['ownerPHID'] != $this->getUserPHID()) { | |||||
| return false; | |||||
| } | |||||
| return $conduit->callMethodSynchronous( | |||||
| 'maniphest.update', | |||||
| array( | |||||
| 'id' => $task_id, | |||||
| 'ownerPHID' => null, | |||||
| )); | |||||
| } | |||||
| private function claimTask($task_id) { | |||||
| $conduit = $this->getConduit(); | |||||
| $info = $conduit->callMethodSynchronous( | |||||
| 'maniphest.info', | |||||
| array( | |||||
| 'task_id' => $task_id, | |||||
| )); | |||||
| if ($info['ownerPHID'] == $this->getUserPHID()) { | |||||
| return false; | |||||
| } | |||||
| return $conduit->callMethodSynchronous( | |||||
| 'maniphest.update', | |||||
| array( | |||||
| 'id' => $task_id, | |||||
| 'ownerPHID' => $this->getUserPHID(), | |||||
| )); | |||||
| } | |||||
| } | |||||