Skip to content

Commit

Permalink
Store all external data services in one Enum
Browse files Browse the repository at this point in the history
  • Loading branch information
pascalchevrel committed May 5, 2024
1 parent ac28539 commit 2520d1c
Show file tree
Hide file tree
Showing 13 changed files with 64 additions and 33 deletions.
8 changes: 6 additions & 2 deletions app/classes/ReleaseInsights/Bugzilla.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace ReleaseInsights;

use ReleaseInsights\URL;

class Bugzilla
{
/**
Expand All @@ -17,7 +19,8 @@ public static function getBugListLink(array $bug_numbers): string
{
$bug_numbers = array_unique($bug_numbers);
$bug_numbers = array_filter($bug_numbers, 'is_numeric');
return 'https://bugzilla.mozilla.org/buglist.cgi?bug_id=' . implode('%2C', $bug_numbers);

return URL::Bugzilla->value . 'buglist.cgi?bug_id=' . implode('%2C', $bug_numbers);
}

/**
Expand All @@ -27,7 +30,8 @@ public static function linkify(string $text): ?string
{
return preg_replace_callback(
"/bug +\d+/i",
fn(array $matches) => '<a href="https://bugzilla.mozilla.org/'
fn(array $matches) => '<a href="'
. URL::Bugzilla->value
. trim(str_ireplace('bug', '', (string) $matches[0]))
. '">'
. $matches[0]
Expand Down
4 changes: 3 additions & 1 deletion app/classes/ReleaseInsights/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace ReleaseInsights;

use ReleaseInsights\URL;

class Data
{
/** @var array<string, string> $future_releases */
Expand All @@ -13,7 +15,7 @@ class Data
private readonly array $release_owners;

public function __construct(
private readonly string $pd_url = 'https://product-details.mozilla.org/1.0/',
private readonly string $pd_url = URL::ProductDetails->value,
public int $cache_duration = 900 // 15 minutes
) {
$this->release_owners = include DATA . 'release_owners.php';
Expand Down
8 changes: 4 additions & 4 deletions app/classes/ReleaseInsights/Nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@

namespace ReleaseInsights;

Use ReleaseInsights\URL;

class Nightly
{
public string $version;
public bool $auto_updates = true;
public string $emergency_message = '';

public function __construct(
public string $pd = 'https://product-details.mozilla.org/1.0/',
public string $AUS = 'https://aus-api.mozilla.org/api/v1/',
// Testing url below
// string $AUS = 'https://stage.balrog.nonprod.cloudops.mozgcp.net/api/v1/',
public string $pd = URL::ProductDetails->value,
public string $AUS = URL::Balrog->value,
public string $update_status = 'emergency_shutoff/Firefox/nightly',
) {
$this->version = Utils::getJson(
Expand Down
3 changes: 2 additions & 1 deletion app/classes/ReleaseInsights/Release.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use DateTime;
use ReleaseInsights\ReleaseStatus as Status;
use ReleaseInsights\URL;

class Release
{
Expand All @@ -19,7 +20,7 @@ class Release

public function __construct(
string $version,
public readonly string $product_details = 'https://product-details.mozilla.org/1.0/',
public readonly string $product_details = URL::ProductDetails->value,
)
{
$this->version = (new Version($version))->normalized;
Expand Down
15 changes: 15 additions & 0 deletions app/classes/ReleaseInsights/URL.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace ReleaseInsights;

enum URL: string {
case Bugzilla = 'https://bugzilla.mozilla.org/';
case BuildHub = 'https://buildhub.moz.tools/api/search';
case ProductDetails = 'https://product-details.mozilla.org/1.0/';
case Mercurial = 'https://hg.mozilla.org/';
case Balrog = 'https://aus-api.mozilla.org/api/v1/';
case Socorro = 'https://crash-stats.mozilla.org/api/';
// Balrog staging: https://stage.balrog.nonprod.cloudops.mozgcp.net
}
5 changes: 3 additions & 2 deletions app/classes/ReleaseInsights/Utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use DateTime;
use GuzzleHttp\Client;
use Json\Json;
use ReleaseInsights\URL;

class Utils
{
Expand All @@ -21,7 +22,7 @@ class Utils
public static function getCrashesForBuildID(int $buildid): array
{
// The date in the string varies so we create a unique file name in cache
$cache_id = 'https://crash-stats.mozilla.org/api/SuperSearch/?build_id=' . $buildid . '&_facets=signature&product=Firefox';
$cache_id = URL::Socorro->value . 'SuperSearch/?build_id=' . $buildid . '&_facets=signature&product=Firefox';

if (defined('TESTING_CONTEXT')) {
if ($buildid == '20190927094817') {
Expand Down Expand Up @@ -55,7 +56,7 @@ public static function getCrashesForBuildID(int $buildid): array
public static function getBugsforCrashSignature(string $signature): array
{
// The signature in the string varies so we create a unique file name in cache
$cache_id = 'https://crash-stats.mozilla.org/api/Bugs/?signatures=' . $signature;
$cache_id = URL::Socorro->value . 'Bugs/?signatures=' . $signature;

if (defined('TESTING_CONTEXT')) {
if ($signature == 'failure') {
Expand Down
4 changes: 2 additions & 2 deletions app/models/api/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use Cache\Cache;
use ReleaseInsights\Utils;
use ReleaseInsights\{URL, Utils};

$date = Utils::getDate();

Expand Down Expand Up @@ -34,7 +34,7 @@
// We cache because we want to avoid http request latency
if (! $data = Cache::getKey($cache_id, 900)) {
$data = file_get_contents(
'https://buildhub.moz.tools/api/search',
URL::BuildHub->value,
false,
stream_context_create($options)
);
Expand Down
4 changes: 2 additions & 2 deletions app/models/api/nightly_crashes.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
declare(strict_types=1);

use Cache\Cache;
use ReleaseInsights\Utils;
use ReleaseInsights\{URL, Utils};

$buildid = Utils::getBuildID((int) ($_GET['buildid'] ?? 1));

$cache_id = 'https://crash-stats.mozilla.org/api/SuperSearch/?build_id=' . (string) $buildid . '&_facets=signature&product=Firefox';
$cache_id = URL::Socorro->value . 'SuperSearch/?build_id=' . (string) $buildid . '&_facets=signature&product=Firefox';

// If we can't retrieve cached data, we create and cache it.
// We cache because we want to avoid http request latency
Expand Down
7 changes: 4 additions & 3 deletions app/models/future_release.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

declare(strict_types=1);

use ReleaseInsights\{Bugzilla, Data, Duration, Nightly, Release, Utils, Version};
use ReleaseInsights\{Bugzilla, Data, Duration, Nightly, Release, URL, Utils, Version};

$requested_version = Version::get();

Expand Down Expand Up @@ -40,7 +40,8 @@
if ((int) $requested_version === BETA && (int) $requested_version != 126 ) {
// Number of bugs fixed in nightly
$nightly_fixes = Bugzilla::getBugsFromHgWeb(
'https://hg.mozilla.org/mozilla-central/json-pushes'
URL::Mercurial->value
. 'mozilla-central/json-pushes'
. '?fromchange=FIREFOX_NIGHTLY_' . ((int) $requested_version - 1) . '_END'
. '&tochange=FIREFOX_NIGHTLY_' . (int) $requested_version .'_END'
. '&full&version=2',
Expand Down Expand Up @@ -99,7 +100,7 @@

// Check current rollout for the beta channel
if ((int) $requested_version === BETA) {
$rollout = Utils::getJson('https://aus-api.mozilla.org/api/v1/rules/firefox-beta')['backgroundRate'];
$rollout = Utils::getJson(URL::Balrog->value . 'rules/firefox-beta')['backgroundRate'];
}

return [
Expand Down
7 changes: 3 additions & 4 deletions app/models/home.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use ReleaseInsights\Data;
use ReleaseInsights\ESR;
use ReleaseInsights\URL;
use ReleaseInsights\Utils;
use ReleaseInsights\Version;

Expand All @@ -23,8 +24,6 @@
$firefox_version_on_release_day = FIREFOX_BETA;
}

$aus_url = 'https://aus-api.mozilla.org/api/v1/';

// Calculation of rc_week interval
$is_rc_week = false;
$today = new DateTime();
Expand All @@ -38,7 +37,7 @@
// Check if we have already shipped a Release Candidate build to the beta channel

// Remote balrog API can give a 404, we have a fallback to N/A
$rc_build = Utils::getJson($aus_url . 'rules/firefox-beta', 900)['mapping'] ?? 'N/A';
$rc_build = Utils::getJson(URL::Balrog->value . 'rules/firefox-beta', 900)['mapping'] ?? 'N/A';

if ($rc_build !== 'N/A') {
$rc_build = explode('-', (string) $rc_build)[1];
Expand All @@ -53,7 +52,7 @@

// Get the latest nightly build ID, used as a tooltip on the nightly version number
$latest_nightly = Utils::getJson(
$aus_url . 'releases/Firefox-mozilla-central-nightly-latest',
URL::Balrog->value . 'releases/Firefox-mozilla-central-nightly-latest',
900
);

Expand Down
11 changes: 8 additions & 3 deletions app/models/nightly.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use BzKarma\Scoring;
use ReleaseInsights\{Bugzilla as Bz, Utils};
use ReleaseInsights\{Bugzilla as Bz, URL, Utils};

/*
We need previous and next days for navigation and changelog
Expand Down Expand Up @@ -108,7 +108,12 @@

foreach ($nightly_pairs as $dataset) {
$bugs = Bz::getBugsFromHgWeb(
'https://hg.mozilla.org/mozilla-central/json-pushes?fromchange=' . $dataset['prev_changeset'] . '&tochange=' . $dataset['changeset'] . '&full&version=2'
URL::Mercurial->value
. 'mozilla-central/json-pushes?fromchange='
. $dataset['prev_changeset']
. '&tochange='
. $dataset['changeset']
. '&full&version=2'
)['total'];

$bug_list_karma = array_unique([...$bugs,...$bug_list_karma]);
Expand All @@ -126,7 +131,7 @@
$url = Bz::getBugListLink($bugs);

// Bugzilla REST API https://wiki.mozilla.org/Bugzilla:REST_API
$bug_list_details = Utils::getJson('https://bugzilla.mozilla.org/rest/bug?include_fields=id,summary,priority,severity,keywords,product,component,type,duplicates,regressions,cf_webcompat_priority,cf_performance_impact,cf_tracking_firefox' . NIGHTLY . ',cf_tracking_firefox' . BETA . ',cf_tracking_firefox' . RELEASE . ',cf_status_firefox' . NIGHTLY . ',cf_status_firefox' . BETA . ',cf_status_firefox' . RELEASE . ',cc,see_also&bug_id=' . implode('%2C', $bugs))['bugs'] ?? [];
$bug_list_details = Utils::getJson(URL::Bugzilla->value . 'rest/bug?include_fields=id,summary,priority,severity,keywords,product,component,type,duplicates,regressions,cf_webcompat_priority,cf_performance_impact,cf_tracking_firefox' . NIGHTLY . ',cf_tracking_firefox' . BETA . ',cf_tracking_firefox' . RELEASE . ',cf_status_firefox' . NIGHTLY . ',cf_status_firefox' . BETA . ',cf_status_firefox' . RELEASE . ',cc,see_also&bug_id=' . implode('%2C', $bugs))['bugs'] ?? [];

$bug_list[$dataset['buildid']] = [
'bugs' => $bug_list_details,
Expand Down
17 changes: 10 additions & 7 deletions app/models/past_release.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@

declare(strict_types=1);

use ReleaseInsights\{Bugzilla as Bz, Release, Utils, Version};
use ReleaseInsights\{Bugzilla as Bz, Release, URL, Utils, Version};

// Historical data from Product Details
$firefox_releases = Utils::getJson('https://product-details.mozilla.org/1.0/firefox.json')['releases'];
$devedition_releases = Utils::getJson('https://product-details.mozilla.org/1.0/devedition.json')['releases'];
$firefox_releases = Utils::getJson(URL::ProductDetails->value . 'firefox.json')['releases'];
$devedition_releases = Utils::getJson(URL::ProductDetails->value . 'devedition.json')['releases'];
$requested_version = Version::get();

if ($requested_version == '14.0') {
Expand Down Expand Up @@ -46,7 +46,8 @@
// Before 4 week schedule, uplifts started with beta 3
$uplift_start = (int) $requested_version > 72 ? '_0b1_RELEASE' : '_0b3_RELEASE';

$beta_changelog = 'https://hg.mozilla.org/releases/mozilla-beta/json-pushes'
$beta_changelog = URL::Mercurial->value
. 'releases/mozilla-beta/json-pushes'
. '?fromchange=FIREFOX_' . (int) $requested_version . $uplift_start
. '&tochange=FIREFOX_BETA_' . (int) $requested_version .'_END'
. '&full&version=2';
Expand Down Expand Up @@ -78,7 +79,8 @@
}

// Get RC uplifts
$rc_changelog = 'https://hg.mozilla.org/releases/mozilla-release/json-pushes'
$rc_changelog = URL::Mercurial->value
. 'releases/mozilla-release/json-pushes'
. '?fromchange=FIREFOX_RELEASE_' . ((int) $requested_version) . '_BASE'
. '&tochange=FIREFOX_' . ((int) $requested_version) . '_0_RELEASE'
. '&full&version=2';
Expand Down Expand Up @@ -135,7 +137,8 @@

// Number of bugs fixed in nightly
$nightly_fixes = Bz::getBugsFromHgWeb(
'https://hg.mozilla.org/mozilla-central/json-pushes'
URL::Mercurial->value
.'mozilla-central/json-pushes'
. '?fromchange=FIREFOX_NIGHTLY_' . ((int) $requested_version - 1) . '_END'
. '&tochange=FIREFOX_NIGHTLY_' . (int) $requested_version .'_END'
. '&full&version=2',
Expand All @@ -147,7 +150,7 @@

// Check current rollout for the release channel
if ((int) $requested_version === RELEASE) {
$rollout = Utils::getJson('https://aus-api.mozilla.org/api/v1/rules/firefox-release')['backgroundRate'];
$rollout = Utils::getJson(URL::Balrog->value . 'rules/firefox-release')['backgroundRate'];
}

return [
Expand Down
4 changes: 2 additions & 2 deletions app/models/pre4_release.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

declare(strict_types=1);

use ReleaseInsights\{Utils, Version};
use ReleaseInsights\{URL,Utils, Version};

// Historical data from Product Details
$firefox_releases = Utils::getJson('https://product-details.mozilla.org/1.0/firefox.json')['releases'];
$firefox_releases = Utils::getJson(URL::ProductDetails->value . 'firefox.json')['releases'];

// Number of dot releases
$dot_release_count = count((array) array_filter(
Expand Down

0 comments on commit 2520d1c

Please sign in to comment.