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

« back to all changes in this revision

Viewing changes to src/workflow/ArcanistInlinesWorkflow.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
final class ArcanistInlinesWorkflow extends ArcanistWorkflow {
 
4
 
 
5
  public function getWorkflowName() {
 
6
    return 'inlines';
 
7
  }
 
8
 
 
9
  public function getCommandSynopses() {
 
10
    return phutil_console_format(<<<EOTEXT
 
11
      **inlines** [--revision __revision_id__]
 
12
EOTEXT
 
13
      );
 
14
  }
 
15
 
 
16
  public function getCommandHelp() {
 
17
    return phutil_console_format(<<<EOTEXT
 
18
          Display inline comments related to a particular revision.
 
19
EOTEXT
 
20
      );
 
21
  }
 
22
 
 
23
  public function getArguments() {
 
24
    return array(
 
25
      'revision' => array(
 
26
        'param' => 'revision_id',
 
27
        'help' =>
 
28
          'Display inline comments for a specific revision. If you do not '.
 
29
          'specify a revision, arc will look in the commit message at HEAD.',
 
30
      ),
 
31
      'root' => array(
 
32
        'param' => 'directory',
 
33
        'help' => 'Specify a string printed in front of each path.',
 
34
      ),
 
35
    );
 
36
  }
 
37
 
 
38
  public function requiresConduit() {
 
39
    return true;
 
40
  }
 
41
 
 
42
  public function requiresAuthentication() {
 
43
    return true;
 
44
  }
 
45
 
 
46
  public function requiresRepositoryAPI() {
 
47
    return true;
 
48
  }
 
49
 
 
50
  public function run() {
 
51
    if ($this->getArgument('revision')) {
 
52
      $revision_id = $this->normalizeRevisionID($this->getArgument('revision'));
 
53
    } else {
 
54
      $revisions = $this->getRepositoryAPI()
 
55
        ->loadWorkingCopyDifferentialRevisions($this->getConduit(), array());
 
56
      $revision_id = head(ipull($revisions, 'id'));
 
57
    }
 
58
 
 
59
    if (!$revision_id) {
 
60
      throw new ArcanistUsageException('No revisions found.');
 
61
    }
 
62
 
 
63
    $comments = array_mergev(
 
64
      $this->getConduit()->callMethodSynchronous(
 
65
        'differential.getrevisioncomments',
 
66
        array(
 
67
          'ids' => array($revision_id),
 
68
          'inlines' => true,
 
69
        )));
 
70
 
 
71
    $authors = array();
 
72
    if ($comments) {
 
73
      $authors = $this->getConduit()->callMethodSynchronous(
 
74
        'user.query',
 
75
        array(
 
76
          'phids' => array_unique(ipull($comments, 'authorPHID')),
 
77
        ));
 
78
      $authors = ipull($authors, 'userName', 'phid');
 
79
    }
 
80
 
 
81
    $inlines = array();
 
82
    foreach ($comments as $comment) {
 
83
      $author = idx($authors, $comment['authorPHID']);
 
84
      foreach ($comment['inlines'] as $inline) {
 
85
        $file = $inline['filePath'];
 
86
        $line = $inline['lineNumber'];
 
87
        $inlines[$file][$line][] = "({$author}) {$inline['content']}";
 
88
      }
 
89
    }
 
90
 
 
91
    $root = $this->getArgument('root');
 
92
    ksort($inlines);
 
93
    foreach ($inlines as $file => $file_inlines) {
 
94
      ksort($file_inlines);
 
95
      foreach ($file_inlines as $line => $line_inlines) {
 
96
        foreach ($line_inlines as $content) {
 
97
          echo "{$root}{$file}:{$line}:{$content}\n";
 
98
        }
 
99
      }
 
100
    }
 
101
  }
 
102
 
 
103
}