Skip to content

Commit

Permalink
Fix ignoring uplifts logic, make it a public bool, add tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed Nov 6, 2024
1 parent a94cfb4 commit 43dac56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 25 deletions.
39 changes: 20 additions & 19 deletions src/pchevrel/BzKarma/Scoring.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class Scoring
This array contains our uplift value business logic.
This is a public property, we can manipulate this array to run
multiple scenarios meant to surface interesting bugs.
We can set a field value to -100 as a strong criteria to ignore a bug.
We can set a field value to -100 as a magic value to ignore a bug.
*/
const SKIP = -100;
public array $karma = [
Expand Down Expand Up @@ -129,7 +129,7 @@ class Scoring
The library returns a value of 0 for bugs already uplifted,
We may want to bypass this setting to look at bugs in past trains
*/
private bool $ignoreUpliftStatus = false;
public bool $ignoreUpliftedBugs = true;

private bool $nightlyScoreOnly;

Expand All @@ -152,15 +152,6 @@ public function __construct(array $bugsDetails, int $release)
$this->nightly = strval($this->release + 2);
}

/*
Pass true to this method before calling getScore()
to get the value of an already uplifted bug
*/
public function ignoreUplifts(bool $status): void
{
$this->nightlyScoreOnly = $status;
}

public function getAllBugsScores(): array
{
$bugs = [];
Expand Down Expand Up @@ -198,7 +189,7 @@ public function getBugScoreDetails(int $bugNumber): array
return $this->zeroBugScore();
}

if ($this->ignoreUpliftStatus === false) {
if ($this->ignoreUpliftedBugs === true) {
/*
Bug already uplifted, uplift value is 0
*/
Expand Down Expand Up @@ -226,7 +217,7 @@ public function getBugScoreDetails(int $bugNumber): array
*/
foreach (array_keys($this->karma) as $key) {
// Some bugs have missing fields
if (!isset($this->bugsDetails[$bugNumber][$key])) {
if (! isset($this->bugsDetails[$bugNumber][$key])) {
continue;
}

Expand Down Expand Up @@ -258,14 +249,24 @@ public function getBugScoreDetails(int $bugNumber): array
'perf_impact' => $this->getFieldValue($bugNumber, 'cf_performance_impact', 'perf_impact'),
'cc' => (int) floor(count($this->bugsDetails[$bugNumber]['cc'] ?? []) * $this->karma['cc']),
'see_also' => (int) floor(count($this->bugsDetails[$bugNumber]['see_also'] ?? []) * $this->karma['see_also']),
'tracking_firefox' . $this->nightly =>
$this->getFieldValue($bugNumber, 'cf_tracking_firefox' . $this->nightly, 'tracking_firefox_nightly'),
'tracking_firefox' . $this->beta =>
$this->getFieldValue($bugNumber, 'cf_tracking_firefox' . $this->beta, 'tracking_firefox_beta'),
'tracking_firefox' . $this->release =>
$this->getFieldValue($bugNumber, 'cf_tracking_firefox' . $this->release, 'tracking_firefox_release'),
'tracking_firefox' . $this->nightly => $this->getFieldValue(
$bugNumber,
'cf_tracking_firefox' . $this->nightly,
'tracking_firefox_nightly'
),
'tracking_firefox' . $this->beta => $this->getFieldValue(
$bugNumber,
'cf_tracking_firefox' . $this->beta,
'tracking_firefox_beta'
),
'tracking_firefox' . $this->release => $this->getFieldValue(
$bugNumber,
'cf_tracking_firefox' . $this->release,
'tracking_firefox_release'
),
];
}

/**
*
*/
Expand Down
11 changes: 5 additions & 6 deletions tests/Unit/BzKarma/ScoringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,11 @@
});

test('Scoring->getAllBugsScore()', function () use ($obj) {
$obj->ignoreUplifts(false);
$obj->ignoreUpliftedBugs = false;
expect($obj->getAllBugsScores(1876311))
->toBe([1916038 => 16, 1912088 => 6, 1876311 => 4, 1876312 => 2, 1916946 => 0, ]);

$obj->ignoreUpliftedBugs = true;
expect($obj->getAllBugsScores(1876311))
->toBe([1912088 => 6, 1876311 => 4, 1876312 => 2, 1916038 => 0, 1916946 => 0, ]);
});
Expand All @@ -50,8 +54,3 @@
->toBe([1876311 => 4, 1876312 => 2, 1912088 => 0, 1916038 => 0, 1916946 => 0,]);
});

test('Scoring->ignoreUplifts()', function () use ($obj) {
expect($obj->ignoreUplifts(true))
->toBeNull();
});

0 comments on commit 43dac56

Please sign in to comment.