~ubuntu-branches/ubuntu/wily/phabricator/wily

« back to all changes in this revision

Viewing changes to src/workflow/ArcanistTodoWorkflow.php

  • Committer: Package Import Robot
  • Author(s): Richard Sellam
  • Date: 2014-11-01 23:20:06 UTC
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: package-import@ubuntu.com-20141101232006-mvlnp0cil67tsboe
Tags: upstream-0~git20141101/arcanist
Import upstream version 0~git20141101, component arcanist

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
<?php
 
2
 
 
3
/**
 
4
 * Quickly create a task.
 
5
 */
 
6
final class ArcanistTodoWorkflow extends ArcanistWorkflow {
 
7
 
 
8
  public function getWorkflowName() {
 
9
    return 'todo';
 
10
  }
 
11
 
 
12
  public function getCommandSynopses() {
 
13
    return phutil_console_format(<<<EOTEXT
 
14
      **todo** __summary__ [__options__]
 
15
EOTEXT
 
16
      );
 
17
  }
 
18
 
 
19
  public function getCommandHelp() {
 
20
    return phutil_console_format(<<<EOTEXT
 
21
        Quickly create a task for yourself.
 
22
EOTEXT
 
23
      );
 
24
  }
 
25
 
 
26
  public function requiresConduit() {
 
27
    return true;
 
28
  }
 
29
 
 
30
  public function desiresWorkingCopy() {
 
31
    return true;
 
32
  }
 
33
 
 
34
  public function requiresAuthentication() {
 
35
    return true;
 
36
  }
 
37
 
 
38
  public function getArguments() {
 
39
    return array(
 
40
      '*' => 'summary',
 
41
      'cc' => array(
 
42
        'param'  => 'cc',
 
43
        'short'  => 'C',
 
44
        'repeat' => true,
 
45
        'help'   => pht('Other users to CC on the new task.'),
 
46
      ),
 
47
      'project' => array(
 
48
        'param'  => 'project',
 
49
        'repeat' => true,
 
50
        'help'   => pht('Projects to assign to the task.'),
 
51
      ),
 
52
      'browse' => array(
 
53
        'help' => pht('After creating the task, open it in a web browser.'),
 
54
      ),
 
55
    );
 
56
  }
 
57
 
 
58
  public function run() {
 
59
    $summary = implode(' ', $this->getArgument('summary'));
 
60
    $ccs = $this->getArgument('cc');
 
61
    $slugs = $this->getArgument('project');
 
62
 
 
63
    $conduit = $this->getConduit();
 
64
 
 
65
    if (trim($summary) == '') {
 
66
      echo "Please provide a summary.\n";
 
67
      return;
 
68
    }
 
69
 
 
70
    $args = array(
 
71
      'title' => $summary,
 
72
      'ownerPHID' => $this->getUserPHID(),
 
73
    );
 
74
 
 
75
    if ($ccs) {
 
76
      $phids = array();
 
77
      $users = $conduit->callMethodSynchronous(
 
78
        'user.query',
 
79
        array(
 
80
          'usernames' => $ccs,
 
81
        ));
 
82
      foreach ($users as $user => $info) {
 
83
        $phids[] = $info['phid'];
 
84
      }
 
85
      $args['ccPHIDs'] = $phids;
 
86
    }
 
87
 
 
88
    if ($slugs) {
 
89
      $phids = array();
 
90
      $projects = $conduit->callMethodSynchronous(
 
91
        'project.query',
 
92
        array(
 
93
          'slugs' => $slugs,
 
94
        ));
 
95
 
 
96
      foreach ($slugs as $slug) {
 
97
        $project = idx($projects['slugMap'], $slug);
 
98
 
 
99
        if (!$project) {
 
100
          throw new ArcanistUsageException('No such project: "'.$slug.'"');
 
101
        }
 
102
        $phids[] = $project;
 
103
      }
 
104
 
 
105
      $args['projectPHIDs'] = $phids;
 
106
    }
 
107
 
 
108
    $result = $conduit->callMethodSynchronous('maniphest.createtask', $args);
 
109
    echo phutil_console_format(
 
110
      "Created task T%s: '<fg:green>**%s**</fg>' at <fg:blue>**%s**</fg>\n",
 
111
      $result['id'],
 
112
      $result['title'],
 
113
      $result['uri']);
 
114
 
 
115
    if ($this->getArgument('browse')) {
 
116
      $this->openURIsInBrowser(array($result['uri']));
 
117
    }
 
118
 
 
119
  }
 
120
 
 
121
}