2011-01-10 00:22:25 +01:00
|
|
|
<?php
|
|
|
|
|
2011-02-19 20:36:08 +01:00
|
|
|
/**
|
|
|
|
* Lists open revisions in Differential.
|
|
|
|
*/
|
2014-07-21 23:49:15 +02:00
|
|
|
final class ArcanistListWorkflow extends ArcanistWorkflow {
|
2011-01-10 00:22:25 +01:00
|
|
|
|
Make Arcanist workflow names explicit
Summary:
Currently, adding a new workflow requires you to override ArcanistConfiguration, which is messy. Instead, just load everything that extends ArcanistBaseWorkflow.
Remove all the rules tying workflow names to class names through arcane incantations.
This has a very small performance cost in that we need to load every Workflow class every time now, but we don't hit __init__ and such anymore and it was pretty negligible on my machine (98ms vs 104ms or something).
Test Plan: Ran "arc help", "arc which", "arc diff", etc.
Reviewers: edward, vrana, btrahan
Reviewed By: edward
CC: aran, zeeg
Differential Revision: https://secure.phabricator.com/D3691
2012-10-17 17:35:03 +02:00
|
|
|
public function getWorkflowName() {
|
|
|
|
return 'list';
|
|
|
|
}
|
|
|
|
|
2012-03-05 19:02:37 +01:00
|
|
|
public function getCommandSynopses() {
|
2011-01-10 00:22:25 +01:00
|
|
|
return phutil_console_format(<<<EOTEXT
|
|
|
|
**list**
|
2012-03-05 19:02:37 +01:00
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getCommandHelp() {
|
|
|
|
return phutil_console_format(<<<EOTEXT
|
2012-02-06 22:08:01 +01:00
|
|
|
Supports: git, svn, hg
|
2011-01-10 00:22:25 +01:00
|
|
|
List your open Differential revisions.
|
|
|
|
EOTEXT
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresConduit() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresRepositoryAPI() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function requiresAuthentication() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run() {
|
2014-06-17 19:42:53 +02:00
|
|
|
static $color_map = array(
|
|
|
|
'Closed' => 'cyan',
|
|
|
|
'Needs Review' => 'magenta',
|
|
|
|
'Needs Revision' => 'red',
|
|
|
|
'Changes Planned' => 'red',
|
|
|
|
'Accepted' => 'green',
|
|
|
|
'No Revision' => 'blue',
|
|
|
|
'Abandoned' => 'default',
|
|
|
|
);
|
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$revisions = $this->getConduit()->callMethodSynchronous(
|
|
|
|
'differential.query',
|
2011-01-10 00:22:25 +01:00
|
|
|
array(
|
2012-02-06 22:08:01 +01:00
|
|
|
'authors' => array($this->getUserPHID()),
|
|
|
|
'status' => 'status-open',
|
2011-01-10 00:22:25 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
if (!$revisions) {
|
2015-05-13 10:05:15 +02:00
|
|
|
echo pht('You have no open Differential revisions.')."\n";
|
2011-01-10 00:22:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$repository_api = $this->getRepositoryAPI();
|
|
|
|
|
|
|
|
$info = array();
|
|
|
|
foreach ($revisions as $key => $revision) {
|
|
|
|
$revision_path = Filesystem::resolvePath($revision['sourcePath']);
|
2011-01-10 00:22:25 +01:00
|
|
|
$current_path = Filesystem::resolvePath($repository_api->getPath());
|
2012-02-06 22:08:01 +01:00
|
|
|
if ($revision_path == $current_path) {
|
2014-06-17 19:42:53 +02:00
|
|
|
$info[$key]['exists'] = 1;
|
2012-02-06 22:08:01 +01:00
|
|
|
} else {
|
2014-06-17 19:42:53 +02:00
|
|
|
$info[$key]['exists'] = 0;
|
2012-02-06 22:08:01 +01:00
|
|
|
}
|
|
|
|
$info[$key]['sort'] = sprintf(
|
|
|
|
'%d%04d%08d',
|
2014-06-17 19:42:53 +02:00
|
|
|
$info[$key]['exists'],
|
2012-02-06 22:08:01 +01:00
|
|
|
$revision['status'],
|
|
|
|
$revision['id']);
|
2012-06-26 19:50:43 +02:00
|
|
|
$info[$key]['statusName'] = $revision['statusName'];
|
2014-06-17 19:42:53 +02:00
|
|
|
$info[$key]['color'] = idx(
|
|
|
|
$color_map, $revision['statusName'], 'default');
|
2012-02-06 22:08:01 +01:00
|
|
|
}
|
2011-01-10 00:22:25 +01:00
|
|
|
|
2014-06-17 19:42:53 +02:00
|
|
|
$table = id(new PhutilConsoleTable())
|
|
|
|
->setShowHeader(false)
|
|
|
|
->addColumn('exists', array('title' => ''))
|
2015-06-08 23:17:39 +02:00
|
|
|
->addColumn('status', array('title' => pht('Status')))
|
|
|
|
->addColumn('title', array('title' => pht('Title')));
|
2014-06-17 19:42:53 +02:00
|
|
|
|
2012-02-06 22:08:01 +01:00
|
|
|
$info = isort($info, 'sort');
|
|
|
|
foreach ($info as $key => $spec) {
|
|
|
|
$revision = $revisions[$key];
|
2014-06-17 19:42:53 +02:00
|
|
|
|
|
|
|
$table->addRow(array(
|
2015-09-21 21:40:06 +02:00
|
|
|
'exists' => $spec['exists'] ? tsprintf('**%s**', '*') : '',
|
|
|
|
'status' => tsprintf(
|
2015-05-13 10:05:15 +02:00
|
|
|
"<fg:{$spec['color']}>%s</fg>",
|
|
|
|
$spec['statusName']),
|
2015-09-21 21:40:06 +02:00
|
|
|
'title' => tsprintf(
|
2015-05-13 10:05:15 +02:00
|
|
|
'**D%d:** %s',
|
|
|
|
$revision['id'],
|
|
|
|
$revision['title']),
|
2014-06-17 19:42:53 +02:00
|
|
|
));
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|
|
|
|
|
2014-06-17 19:42:53 +02:00
|
|
|
$table->draw();
|
2011-01-10 00:22:25 +01:00
|
|
|
return 0;
|
|
|
|
}
|
2014-07-09 01:12:13 +02:00
|
|
|
|
2011-01-10 00:22:25 +01:00
|
|
|
}
|