diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php index 00688167..1250ef8d 100644 --- a/src/__phutil_library_map__.php +++ b/src/__phutil_library_map__.php @@ -59,6 +59,7 @@ phutil_register_library_map(array( 'ArcanistHgProxyServer' => 'hgdaemon/ArcanistHgProxyServer.php', 'ArcanistHgServerChannel' => 'hgdaemon/ArcanistHgServerChannel.php', 'ArcanistHookAPI' => 'repository/hookapi/ArcanistHookAPI.php', + 'ArcanistInlinesWorkflow' => 'workflow/ArcanistInlinesWorkflow.php', 'ArcanistInstallCertificateWorkflow' => 'workflow/ArcanistInstallCertificateWorkflow.php', 'ArcanistJSHintLinter' => 'lint/linter/ArcanistJSHintLinter.php', 'ArcanistLandWorkflow' => 'workflow/ArcanistLandWorkflow.php', @@ -174,6 +175,7 @@ phutil_register_library_map(array( 'ArcanistHelpWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistHgClientChannel' => 'PhutilProtocolChannel', 'ArcanistHgServerChannel' => 'PhutilProtocolChannel', + 'ArcanistInlinesWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistInstallCertificateWorkflow' => 'ArcanistBaseWorkflow', 'ArcanistJSHintLinter' => 'ArcanistLinter', 'ArcanistLandWorkflow' => 'ArcanistBaseWorkflow', diff --git a/src/workflow/ArcanistInlinesWorkflow.php b/src/workflow/ArcanistInlinesWorkflow.php new file mode 100644 index 00000000..771d778e --- /dev/null +++ b/src/workflow/ArcanistInlinesWorkflow.php @@ -0,0 +1,112 @@ + array( + 'param' => 'revision_id', + 'help' => + "Display inline comments for a specific revision. If you do not ". + "specify a revision, arc will look in the commit message at HEAD.", + ), + ); + } + + public function requiresConduit() { + return true; + } + + public function requiresAuthentication() { + return true; + } + + public function requiresRepositoryAPI() { + return true; + } + + public function run() { + if ($this->getArgument('revision')) { + $revision_id = $this->normalizeRevisionID($this->getArgument('revision')); + } else { + $revisions = $this->getRepositoryAPI() + ->loadWorkingCopyDifferentialRevisions($this->getConduit(), array()); + $revision_id = head(ipull($revisions, 'id')); + } + + if (!$revision_id) { + throw new ArcanistUsageException("No revisions found."); + } + + $comments = array_mergev( + $this->getConduit()->callMethodSynchronous( + 'differential.getrevisioncomments', + array( + 'ids' => array($revision_id), + 'inlines' => true, + ))); + + $authors = array(); + if ($comments) { + $authors = $this->getConduit()->callMethodSynchronous( + 'user.query', + array( + 'phids' => array_unique(ipull($comments, 'authorPHID')), + )); + $authors = ipull($authors, 'userName', 'phid'); + } + + $inlines = array(); + foreach ($comments as $comment) { + $author = idx($authors, $comment['authorPHID']); + foreach ($comment['inlines'] as $inline) { + $file = $inline['filePath']; + $line = $inline['lineNumber']; + $inlines[$file][$line][] = "({$author}) {$inline['content']}"; + } + } + + ksort($inlines); + foreach ($inlines as $file => $file_inlines) { + ksort($file_inlines); + foreach ($file_inlines as $line => $line_inlines) { + foreach ($line_inlines as $content) { + echo "{$file}:{$line}:{$content}\n"; + } + } + } + } +}