Page MenuHomePhabricator

D7327.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -147,6 +147,7 @@
'ArcanistTextLinter' => 'lint/linter/ArcanistTextLinter.php',
'ArcanistTextLinterTestCase' => 'lint/linter/__tests__/ArcanistTextLinterTestCase.php',
'ArcanistTodoWorkflow' => 'workflow/ArcanistTodoWorkflow.php',
+ 'ArcanistTrackWorkflow' => 'workflow/ArcanistTrackWorkflow.php',
'ArcanistUncommittedChangesException' => 'exception/usage/ArcanistUncommittedChangesException.php',
'ArcanistUnitConsoleRenderer' => 'unit/renderer/ArcanistUnitConsoleRenderer.php',
'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
@@ -295,6 +296,7 @@
'ArcanistTextLinter' => 'ArcanistLinter',
'ArcanistTextLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistTodoWorkflow' => 'ArcanistBaseWorkflow',
+ 'ArcanistTrackWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistUncommittedChangesException' => 'ArcanistUsageException',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
'ArcanistUnitWorkflow' => 'ArcanistBaseWorkflow',
diff --git a/src/workflow/ArcanistTrackWorkflow.php b/src/workflow/ArcanistTrackWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/workflow/ArcanistTrackWorkflow.php
@@ -0,0 +1,115 @@
+<?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);
+ }
+ }
+
+}

File Metadata

Mime Type
text/x-diff
Storage Engine
amazon-s3
Storage Format
Raw Data
Storage Handle
phabricator/jp/ry/oylcd3ikpnbdx5m5
Default Alt Text
D7327.diff (3 KB)

Event Timeline