Changeset View
Changeset View
Standalone View
Standalone View
src/workflow/ArcanistTrackWorkflow.php
- This file was added.
<?php | |||||
/** | |||||
* Start time tracking on a task | |||||
* | |||||
* @group workflow | |||||
*/ | |||||
final class ArcanistTrackWorkflow extends ArcanistBaseWorkflow { | |||||
public function getWorkflowName() { | |||||
return 'track'; | |||||
} | |||||
public function getCommandSynopses() { | |||||
return phutil_console_format(<<<EOTEXT | |||||
**track** [__options__] | |||||
EOTEXT | |||||
); | |||||
} | |||||
public function getCommandHelp() { | |||||
return phutil_console_format(<<<EOTEXT | |||||
Track starting and ending work on Phrequent time tracker. | |||||
EOTEXT | |||||
); | |||||
} | |||||
public function requiresConduit() { | |||||
return true; | |||||
} | |||||
public function desiresWorkingCopy() { | |||||
return false; | |||||
} | |||||
public function requiresAuthentication() { | |||||
return true; | |||||
} | |||||
public function getArguments() { | |||||
return array( | |||||
'task' => array( | |||||
'param' => 'T1234', | |||||
'help' => "A maniphest task that you are working on.", | |||||
), | |||||
'start' => array( | |||||
'help' => "Start tracking.", | |||||
), | |||||
'stop' => array( | |||||
'help' => "Stop tracking.", | |||||
) | |||||
); | |||||
} | |||||
public function run() { | |||||
$start_flag = $this->getArgument('start'); | |||||
$stop_flag = $this->getArgument('stop'); | |||||
if (!$start_flag && !$stop_flag) { | |||||
echo "Please specify whether to --start or --stop tracking.\n"; | |||||
} | |||||
$object_exists = false; | |||||
$object_id = null; | |||||
$object_name = ""; | |||||
$conduit = $this->getConduit(); | |||||
if ($this->getArgument('task')) { | |||||
$object_exists = true; | |||||
$id = $this->getArgument('task'); | |||||
if (!preg_match("/^T?\d+$/", $id)) { | |||||
echo "Invalid Task ID: {$id}.\n"; | |||||
return 1; | |||||
} | |||||
$id = ltrim($id, 'T'); | |||||
$info = $conduit->callMethodSynchronous( | |||||
'maniphest.info', | |||||
array( | |||||
'task_id' => $id | |||||
)); | |||||
$object_id = $info['phid']; | |||||
$object_name = "T$id: ".$info['title']; | |||||
} | |||||
if (!$object_exists) { | |||||
echo "Please specify an object you are working on,"; | |||||
echo "like '--task T1234' for a task\n"; | |||||
return 1; | |||||
} | |||||
$method_name = $start_flag ? "phrequent.start" : "phrequent.stop"; | |||||
$info = $conduit->callMethodSynchronous( | |||||
$method_name, | |||||
array( | |||||
'object' => $object_id | |||||
)); | |||||
if ($start_flag) { | |||||
echo phutil_console_format( | |||||
"<fg:green>Started</fg> tracking time for <fg:blue>**%s**</fg>\n", | |||||
$object_name); | |||||
} | |||||
else { | |||||
echo phutil_console_format( | |||||
"<fg:red>Stopped</fg> tracking time for <fg:blue>**%s**</fg>\n", | |||||
$object_name); | |||||
} | |||||
} | |||||
} |