3 final class ReleephDiffSizeFieldSpecification
4 extends ReleephFieldSpecification
{
6 const LINES_WEIGHT
= 1;
7 const PATHS_WEIGHT
= 30;
8 const MAX_POINTS
= 1000;
10 public function getFieldKey() {
14 public function getName() {
18 public function renderPropertyViewValue(array $handles) {
19 $requested_object = $this->getObject()->getRequestedObject();
20 if (!($requested_object instanceof DifferentialRevision
)) {
23 $diff_rev = $requested_object;
25 $diffs = id(new DifferentialDiff())->loadAllWhere(
26 'revisionID = %d AND creationMethod != %s',
30 $all_changesets = array();
31 $most_recent_changesets = null;
32 foreach ($diffs as $diff) {
33 $changesets = id(new DifferentialChangeset())->loadAllWhere(
36 $all_changesets +
= $changesets;
37 $most_recent_changesets = $changesets;
40 // The score is based on all changesets for all versions of this diff
41 $all_changes = $this->countLinesAndPaths($all_changesets);
43 self
::LINES_WEIGHT
* $all_changes['code']['lines'] +
44 self
::PATHS_WEIGHT
* count($all_changes['code']['paths']);
46 // The blurb is just based on the most recent version of the diff
47 $mr_changes = $this->countLinesAndPaths($most_recent_changesets);
50 if ($mr_changes['tests']['paths']) {
51 Javelin
::initBehavior('phabricator-tooltips');
52 require_celerity_resource('aphront-tooltip-css');
55 "%d line(s) and %d path(s) contain changes to test code:\n",
56 $mr_changes['tests']['lines'],
57 count($mr_changes['tests']['paths']));
58 foreach ($mr_changes['tests']['paths'] as $mr_test_path) {
59 $test_blurb .= sprintf("%s\n", $mr_test_path);
62 $test_tag = javelin_tag(
65 'sigil' => 'has-tooltip',
76 $blurb = hsprintf('%s%s.',
78 '%d line(s) and %d path(s) over %d diff(s)',
79 $mr_changes['code']['lines'],
80 $mr_changes['code']['paths'],
84 return id(new AphrontProgressBarView())
86 ->setMax(self
::MAX_POINTS
)
91 private function countLinesAndPaths(array $changesets) {
92 assert_instances_of($changesets, 'DifferentialChangeset');
94 $paths_touched = array();
96 $test_paths_touched = array();
98 foreach ($changesets as $ch) {
99 if ($this->getReleephProject()->isTestFile($ch->getFilename())) {
100 $test_lines +
= $ch->getAddLines() +
$ch->getDelLines();
101 $test_paths_touched[] = $ch->getFilename();
103 $lines +
= $ch->getAddLines() +
$ch->getDelLines();
104 $paths_touched[] = $ch->getFilename();
110 'paths' => array_unique($paths_touched),
113 'lines' => $test_lines,
114 'paths' => array_unique($test_paths_touched),