Page MenuHomePhabricator

D7327.id23798.diff
No OneTemporary

D7327.id23798.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
@@ -5,7 +5,6 @@
* @generated
* @phutil-library-version 2
*/
-
phutil_register_library_map(array(
'__library_version__' => 2,
'class' =>
@@ -161,6 +160,8 @@
'ArcanistSingleLintEngine' => 'lint/engine/ArcanistSingleLintEngine.php',
'ArcanistSpellingLinter' => 'lint/linter/ArcanistSpellingLinter.php',
'ArcanistSpellingLinterTestCase' => 'lint/linter/__tests__/ArcanistSpellingLinterTestCase.php',
+ 'ArcanistStartWorkflow' => 'workflow/ArcanistStartWorkflow.php',
+ 'ArcanistStopWorkflow' => 'workflow/ArcanistStopWorkflow.php',
'ArcanistSubversionAPI' => 'repository/api/ArcanistSubversionAPI.php',
'ArcanistSubversionHookAPI' => 'repository/hookapi/ArcanistSubversionHookAPI.php',
'ArcanistSvnHookPreCommitWorkflow' => 'workflow/ArcanistSvnHookPreCommitWorkflow.php',
@@ -169,6 +170,7 @@
'ArcanistTextLinter' => 'lint/linter/ArcanistTextLinter.php',
'ArcanistTextLinterTestCase' => 'lint/linter/__tests__/ArcanistTextLinterTestCase.php',
'ArcanistTodoWorkflow' => 'workflow/ArcanistTodoWorkflow.php',
+ 'ArcanistTrackingWorkflow' => 'workflow/ArcanistTrackingWorkflow.php',
'ArcanistUncommittedChangesException' => 'exception/usage/ArcanistUncommittedChangesException.php',
'ArcanistUnitConsoleRenderer' => 'unit/renderer/ArcanistUnitConsoleRenderer.php',
'ArcanistUnitRenderer' => 'unit/renderer/ArcanistUnitRenderer.php',
@@ -332,6 +334,8 @@
'ArcanistSingleLintEngine' => 'ArcanistLintEngine',
'ArcanistSpellingLinter' => 'ArcanistLinter',
'ArcanistSpellingLinterTestCase' => 'ArcanistArcanistLinterTestCase',
+ 'ArcanistStartWorkflow' => 'ArcanistTrackingWorkflow',
+ 'ArcanistStopWorkflow' => 'ArcanistTrackingWorkflow',
'ArcanistSubversionAPI' => 'ArcanistRepositoryAPI',
'ArcanistSubversionHookAPI' => 'ArcanistHookAPI',
'ArcanistSvnHookPreCommitWorkflow' => 'ArcanistBaseWorkflow',
@@ -340,6 +344,7 @@
'ArcanistTextLinter' => 'ArcanistLinter',
'ArcanistTextLinterTestCase' => 'ArcanistArcanistLinterTestCase',
'ArcanistTodoWorkflow' => 'ArcanistBaseWorkflow',
+ 'ArcanistTrackingWorkflow' => 'ArcanistBaseWorkflow',
'ArcanistUncommittedChangesException' => 'ArcanistUsageException',
'ArcanistUnitConsoleRenderer' => 'ArcanistUnitRenderer',
'ArcanistUnitWorkflow' => 'ArcanistBaseWorkflow',
diff --git a/src/workflow/ArcanistStartWorkflow.php b/src/workflow/ArcanistStartWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/workflow/ArcanistStartWorkflow.php
@@ -0,0 +1,100 @@
+<?php
+
+/**
+ * Start time tracking on an object
+ */
+final class ArcanistStartWorkflow extends ArcanistTrackingWorkflow {
+
+ public function getWorkflowName() {
+ return 'start';
+ }
+
+ public function getCommandSynopses() {
+ return phutil_console_format(<<<EOTEXT
+ **start** __object__
+EOTEXT
+ );
+ }
+
+ public function getCommandHelp() {
+ return phutil_console_format(<<<EOTEXT
+Start tracking work in Phrequent.
+EOTEXT
+ );
+ }
+
+ public function requiresConduit() {
+ return true;
+ }
+
+ public function desiresWorkingCopy() {
+ return false;
+ }
+
+ public function requiresAuthentication() {
+ return true;
+ }
+
+ public function getArguments() {
+ return array(
+ 'object' => array(
+ 'param' => 'T1234',
+ 'help' =>
+ "An object in Phabricator, such as T1234 or D5678. You can ".
+ "use `arc start T1234` as short hand.",
+ ),
+ '*' => 'name',
+ );
+ }
+
+ public function run() {
+ $conduit = $this->getConduit();
+
+ $object_name = null;
+ $short_name = $this->getArgument('name');
+ if (count($short_name) > 0) {
+ $object_name = $short_name[0];
+ } else {
+ $object_name = $this->getArgument('object');
+ }
+
+ $object_lookup = $conduit->callMethodSynchronous(
+ 'phid.lookup',
+ array(
+ 'names' => array($object_name),
+ ));
+
+ if (!array_key_exists($object_name, $object_lookup)) {
+ echo "No such object '".$object_name."' found.\n";
+ return 1;
+ }
+
+ $object_phid = $object_lookup[$object_name]['phid'];
+
+ $started_phid = $conduit->callMethodSynchronous(
+ 'phrequent.push',
+ array(
+ 'objectPHID' => $object_phid
+ ));
+
+ $phid_query = $conduit->callMethodSynchronous(
+ 'phid.query',
+ array(
+ 'phids' => array($started_phid),
+ ));
+
+ $name = $phid_query[$started_phid]['fullName'];
+
+ echo phutil_console_format(
+ "Started: %s\n\n",
+ $name);
+
+ // TODO This is pretty terrible... but it seems to be needed to
+ // calculate the current work being tracked?
+ sleep(1);
+
+ $this->printCurrentTracking();
+ }
+
+}
+
diff --git a/src/workflow/ArcanistStopWorkflow.php b/src/workflow/ArcanistStopWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/workflow/ArcanistStopWorkflow.php
@@ -0,0 +1,121 @@
+<?php
+
+/**
+ * Stop time tracking on an object
+ */
+final class ArcanistStopWorkflow extends ArcanistTrackingWorkflow {
+
+ public function getWorkflowName() {
+ return 'stop';
+ }
+
+ public function getCommandSynopses() {
+ return phutil_console_format(<<<EOTEXT
+ **stop** [--note __note__] [__object__]
+EOTEXT
+ );
+ }
+
+ public function getCommandHelp() {
+ return phutil_console_format(<<<EOTEXT
+Start tracking work in Phrequent.
+EOTEXT
+ );
+ }
+
+ public function requiresConduit() {
+ return true;
+ }
+
+ public function desiresWorkingCopy() {
+ return false;
+ }
+
+ public function requiresAuthentication() {
+ return true;
+ }
+
+ public function getArguments() {
+ return array(
+ 'object' => array(
+ 'param' => 'T1234',
+ 'help' =>
+ "The object to stop tracking in Phabricator, such as T1234 or ".
+ "D5678. You can omit this to stop tracking the current object. ".
+ "Use `arc stop T1234` or `arc stop` as short hand.",
+ ),
+ 'note' => array(
+ 'param' => 'note',
+ 'help' =>
+ "A note to attach to the tracked time.",
+ ),
+ '*' => 'name',
+ );
+ }
+
+ public function run() {
+ $conduit = $this->getConduit();
+
+ $object_name = null;
+ $short_name = $this->getArgument('name');
+ if (count($short_name) > 0) {
+ $object_name = $short_name[0];
+ } else {
+ $object_name = $this->getArgument('object');
+ }
+
+ $object_phid = null;
+ if ($object_name !== null) {
+ $object_lookup = $conduit->callMethodSynchronous(
+ 'phid.lookup',
+ array(
+ 'names' => array($object_name),
+ ));
+
+ if (!array_key_exists($object_name, $object_lookup)) {
+ echo "No such object '".$object_name."' found.\n";
+ return 1;
+ }
+
+ $object_phid = $object_lookup[$object_name]['phid'];
+ }
+
+ $stopped_phid = $conduit->callMethodSynchronous(
+ 'phrequent.pop',
+ array(
+ 'objectPHID' => $object_phid,
+ 'note' => $this->getArgument('note'),
+ ));
+
+ if ($stopped_phid === null) {
+ if ($object_name === null) {
+ echo phutil_console_format(
+ "Not currently tracking time against any object\n");
+ } else {
+ echo phutil_console_format(
+ "Not currently tracking time against <fg:blue>**%s**</fg>\n",
+ $object_name);
+ }
+ return 1;
+ }
+
+ $phid_query = $conduit->callMethodSynchronous(
+ 'phid.query',
+ array(
+ 'phids' => array($stopped_phid),
+ ));
+
+ $name = $phid_query[$stopped_phid]['fullName'];
+
+ echo phutil_console_format(
+ "Stopped: %s\n\n",
+ $name);
+
+ // TODO This is pretty terrible... but it seems to be needed to
+ // calculate the current work being tracked?
+ sleep(1);
+
+ $this->printCurrentTracking();
+ }
+
+}
diff --git a/src/workflow/ArcanistTrackingWorkflow.php b/src/workflow/ArcanistTrackingWorkflow.php
new file mode 100644
--- /dev/null
+++ b/src/workflow/ArcanistTrackingWorkflow.php
@@ -0,0 +1,113 @@
+<?php
+
+/**
+ * Show time being tracked in Phrequent
+ *
+ * @concrete-extensible
+ */
+class ArcanistTrackingWorkflow extends ArcanistBaseWorkflow {
+
+ public function getWorkflowName() {
+ return 'tracking';
+ }
+
+ public function getCommandSynopses() {
+ return phutil_console_format(<<<EOTEXT
+ **tracking**
+EOTEXT
+ );
+ }
+
+ public function getCommandHelp() {
+ return phutil_console_format(<<<EOTEXT
+Show what you're currently tracking in Phrequent.
+EOTEXT
+ );
+ }
+
+ public function requiresConduit() {
+ return true;
+ }
+
+ public function desiresWorkingCopy() {
+ return false;
+ }
+
+ public function requiresAuthentication() {
+ return true;
+ }
+
+ public function getArguments() {
+ return array(
+ );
+ }
+
+ public function run() {
+ $this->printCurrentTracking();
+ }
+
+ protected function printCurrentTracking() {
+ $conduit = $this->getConduit();
+
+ $results = $conduit->callMethodSynchronous(
+ 'phrequent.tracking',
+ array());
+ $results = $results['data'];
+
+ if (count($results) === 0) {
+ echo phutil_console_format(
+ "Not currently tracking time against any object\n");
+
+ return 0;
+ }
+
+ $phids_to_lookup = array();
+ foreach ($results as $result) {
+ $phids_to_lookup[] = $result['phid'];
+ }
+
+ $phid_query = $conduit->callMethodSynchronous(
+ 'phid.query',
+ array(
+ 'phids' => $phids_to_lookup,
+ ));
+
+ $phid_map = array();
+ foreach ($phids_to_lookup as $lookup) {
+ if (array_key_exists($lookup, $phid_query)) {
+ $phid_map[$lookup] = $phid_query[$lookup]['fullName'];
+ } else {
+ $phid_map[$lookup] = 'Unknown Object';
+ }
+ }
+
+ foreach ($results as $result) {
+ $column_type = '';
+ $column_name = '';
+ $column_time = '';
+
+ switch ($result['type']) {
+ case 'active':
+ $column_type = 'In Progress';
+ break;
+ case 'suspended':
+ $column_type = 'Suspended';
+ break;
+ case 'inactive';
+ $column_type = 'Stopped';
+ break;
+ }
+
+ $column_type = '('.$column_type.')';
+ $column_type = str_pad($column_type, 14);
+ $column_time = phutil_format_relative_time($result['time']);
+ $column_time = str_pad($column_time, 7, " ", STR_PAD_LEFT);
+ $column_name = $phid_map[$result['phid']];
+
+ echo $column_type.$column_time." ".$column_name."\n";
+ }
+
+ return 0;
+ }
+
+}

File Metadata

Mime Type
text/plain
Expires
Sun, Oct 5, 10:38 PM (3 d, 9 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
12381275
Default Alt Text
D7327.id23798.diff (10 KB)

Event Timeline