[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class ReleephDiffSizeFieldSpecification 4 extends ReleephFieldSpecification { 5 6 const LINES_WEIGHT = 1; 7 const PATHS_WEIGHT = 30; 8 const MAX_POINTS = 1000; 9 10 public function getFieldKey() { 11 return 'commit:size'; 12 } 13 14 public function getName() { 15 return 'Size'; 16 } 17 18 public function renderPropertyViewValue(array $handles) { 19 $requested_object = $this->getObject()->getRequestedObject(); 20 if (!($requested_object instanceof DifferentialRevision)) { 21 return null; 22 } 23 $diff_rev = $requested_object; 24 25 $diffs = $diff_rev->loadRelatives( 26 new DifferentialDiff(), 27 'revisionID', 28 'getID', 29 'creationMethod <> "commit"'); 30 31 $all_changesets = array(); 32 $most_recent_changesets = null; 33 foreach ($diffs as $diff) { 34 $changesets = $diff->loadRelatives(new DifferentialChangeset(), 'diffID'); 35 $all_changesets += $changesets; 36 $most_recent_changesets = $changesets; 37 } 38 39 // The score is based on all changesets for all versions of this diff 40 $all_changes = $this->countLinesAndPaths($all_changesets); 41 $points = 42 self::LINES_WEIGHT * $all_changes['code']['lines'] + 43 self::PATHS_WEIGHT * count($all_changes['code']['paths']); 44 45 // The blurb is just based on the most recent version of the diff 46 $mr_changes = $this->countLinesAndPaths($most_recent_changesets); 47 48 $test_tag = ''; 49 if ($mr_changes['tests']['paths']) { 50 Javelin::initBehavior('phabricator-tooltips'); 51 require_celerity_resource('aphront-tooltip-css'); 52 53 $test_blurb = 54 pht('%d line(s)', $mr_changes['tests']['lines']).' and '. 55 pht('%d path(s)', count($mr_changes['tests']['paths'])). 56 " contain changes to test code:\n"; 57 foreach ($mr_changes['tests']['paths'] as $mr_test_path) { 58 $test_blurb .= pht("%s\n", $mr_test_path); 59 } 60 61 $test_tag = javelin_tag( 62 'span', 63 array( 64 'sigil' => 'has-tooltip', 65 'meta' => array( 66 'tip' => $test_blurb, 67 'align' => 'E', 68 'size' => 'auto', 69 ), 70 'style' => '', 71 ), 72 ' + tests'); 73 } 74 75 $blurb = hsprintf('%s%s.', 76 pht('%d line(s)', $mr_changes['code']['lines']).' and '. 77 pht('%d path(s)', count($mr_changes['code']['paths'])).' over '. 78 pht('%d diff(s)', count($diffs)), 79 $test_tag); 80 81 return id(new AphrontProgressBarView()) 82 ->setValue($points) 83 ->setMax(self::MAX_POINTS) 84 ->setCaption($blurb) 85 ->render(); 86 } 87 88 private function countLinesAndPaths(array $changesets) { 89 assert_instances_of($changesets, 'DifferentialChangeset'); 90 $lines = 0; 91 $paths_touched = array(); 92 $test_lines = 0; 93 $test_paths_touched = array(); 94 95 foreach ($changesets as $ch) { 96 if ($this->getReleephProject()->isTestFile($ch->getFilename())) { 97 $test_lines += $ch->getAddLines() + $ch->getDelLines(); 98 $test_paths_touched[] = $ch->getFilename(); 99 } else { 100 $lines += $ch->getAddLines() + $ch->getDelLines(); 101 $paths_touched[] = $ch->getFilename(); 102 } 103 } 104 return array( 105 'code' => array( 106 'lines' => $lines, 107 'paths' => array_unique($paths_touched), 108 ), 109 'tests' => array( 110 'lines' => $test_lines, 111 'paths' => array_unique($test_paths_touched), 112 ), 113 ); 114 } 115 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |