4
* Covers your professional reputation by blaming changes to locate reviewers.
6
final class ArcanistCoverWorkflow extends ArcanistWorkflow {
8
public function getWorkflowName() {
12
public function getCommandSynopses() {
13
return phutil_console_format(<<<EOTEXT
14
**cover** [--rev __revision__] [__path__ ...]
19
public function getCommandHelp() {
20
return phutil_console_format(<<<EOTEXT
21
Supports: svn, git, hg
22
Cover your... professional reputation. Show blame for the lines you
23
changed in your working copy (svn) or since some commit (hg, git).
24
This will take a minute because blame takes a minute, especially under
30
public function getArguments() {
33
'param' => 'revision',
34
'help' => 'Cover changes since a specific revision.',
40
'svn' => 'cover does not currently support --rev in svn.',
47
public function requiresWorkingCopy() {
51
public function requiresConduit() {
55
public function requiresAuthentication() {
59
public function requiresRepositoryAPI() {
63
public function run() {
64
$repository_api = $this->getRepositoryAPI();
66
$in_paths = $this->getArgument('paths');
67
$in_rev = $this->getArgument('rev');
70
$this->parseBaseCommitArgument(array($in_rev));
73
$paths = $this->selectPathsForWorkflow(
76
ArcanistRepositoryAPI::FLAG_UNTRACKED |
77
ArcanistRepositoryAPI::FLAG_ADDED);
80
throw new ArcanistNoEffectException(
81
"You're covered, you didn't change anything.");
85
foreach ($paths as $path) {
86
if (is_dir($repository_api->getPath($path))) {
90
$lines = $this->getChangedLines($path, 'cover');
95
$blame = $repository_api->getBlame($path);
96
foreach ($lines as $line) {
97
list($author, $revision) = idx($blame, $line, array(null, null));
101
if (!isset($covers[$author])) {
102
$covers[$author] = array();
104
if (!isset($covers[$author][$path])) {
105
$covers[$author][$path] = array(
107
'revisions' => array(),
110
$covers[$author][$path]['lines'][] = $line;
111
$covers[$author][$path]['revisions'][] = $revision;
115
if (count($covers)) {
116
foreach ($covers as $author => $files) {
117
echo phutil_console_format(
120
foreach ($files as $file => $info) {
121
$line_noun = pht('line(s)', count($info['lines']));
122
$lines = $this->readableSequenceFromLineNumbers($info['lines']);
123
echo " {$file}: {$line_noun} {$lines}\n";
127
echo "You're covered, your changes didn't touch anyone else's code.\n";
133
private function readableSequenceFromLineNumbers(array $array) {
137
$array = array_unique(array_map('intval', $array));
139
foreach ($array as $element) {
140
if ($seq !== null && $element == ($seq + 1)) {
152
$sequence[] = $last.'-'.$seq;
160
if ($last !== null && $seq > $last) {
161
$sequence[] = $last.'-'.$seq;
162
} else if ($last !== null) {
163
$sequence[] = $element;
166
return implode(', ', $sequence);