1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-12-11 08:06:12 +01:00
phorge-arcanist/src/workflow/ArcanistListWorkflow.php

108 lines
2.7 KiB
PHP
Raw Normal View History

2011-01-10 00:22:25 +01:00
<?php
/*
* Copyright 2012 Facebook, Inc.
2011-01-10 00:22:25 +01:00
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
/**
* Lists open revisions in Differential.
*
* @group workflow
*/
final class ArcanistListWorkflow extends ArcanistBaseWorkflow {
2011-01-10 00:22:25 +01:00
public function getCommandSynopses() {
2011-01-10 00:22:25 +01:00
return phutil_console_format(<<<EOTEXT
**list**
EOTEXT
);
}
public function getCommandHelp() {
return phutil_console_format(<<<EOTEXT
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() {
$revisions = $this->getConduit()->callMethodSynchronous(
'differential.query',
2011-01-10 00:22:25 +01:00
array(
'authors' => array($this->getUserPHID()),
'status' => 'status-open',
2011-01-10 00:22:25 +01:00
));
if (!$revisions) {
echo "You have no open Differential revisions.\n";
return 0;
}
$repository_api = $this->getRepositoryAPI();
$info = array();
2011-01-10 00:22:25 +01:00
$status_len = 0;
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());
if ($revision_path == $current_path) {
$info[$key]['here'] = 1;
} else {
$info[$key]['here'] = 0;
}
$info[$key]['sort'] = sprintf(
'%d%04d%08d',
$info[$key]['here'],
$revision['status'],
$revision['id']);
$info[$key]['statusColorized'] =
BranchInfo::renderColorizedRevisionStatus(
$revision['statusName']);
$status_len = max(
$status_len,
strlen($info[$key]['statusColorized']));
}
2011-01-10 00:22:25 +01:00
$info = isort($info, 'sort');
foreach ($info as $key => $spec) {
$revision = $revisions[$key];
2011-01-10 00:22:25 +01:00
printf(
"%s %-".($status_len + 4)."s D%d: %s\n",
$spec['here']
? phutil_console_format('**%s**', '*')
: ' ',
$spec['statusColorized'],
$revision['id'],
$revision['title']);
2011-01-10 00:22:25 +01:00
}
return 0;
}
}