formatAlert()

in ui/perfherder/perf-helpers/textualSummary.js [75:133]


  formatAlert(alert) {
    const numFormat = '0,0.00';
    let amountPct;
    const { repository, framework } = this.alertSummary;
    const timeRange = getTimeRange(this.alertSummary);
    const baseURL = thBaseUrl + uiPerfherderBase.slice(1);
    const graphLink =
      baseURL + getGraphsURL(alert, timeRange, repository, framework).slice(1);
    if (alert.amount_pct.toFixed(0) === '0') {
      // have extra fraction digits when rounding ends up with 0%
      amountPct = alert.amount_pct.toFixed(2);
    } else {
      amountPct = alert.amount_pct.toFixed(0);
    }

    const prevValue = numeral(alert.prev_value).format(numFormat);
    const newValue = numeral(alert.new_value).format(numFormat);

    const { suite, test, machine_platform: platform } = alert.series_signature;
    const extraOptions = alert.series_signature.extra_options.join(' ');

    const updatedAlert = this.browsertimeAlertsExtraData.find(
      (a) => alert.id === a.id,
    );
    const frameworkName = getFrameworkName(
      this.frameworks,
      this.alertSummary.framework,
    );
    const perfdocs = new Perfdocs(frameworkName, suite, platform);
    const url = perfdocs.documentationURL;
    const suiteName = perfdocs.hasDocumentation()
      ? `[${suite}](${url})`
      : suite;
    const suiteTestName = suite === test ? suiteName : `${suiteName} ${test}`;

    const alertValues =
      updatedAlert &&
      updatedAlert.results_link &&
      updatedAlert.prev_results_link
        ? `[${prevValue}](${updatedAlert.prev_results_link}) -> [${newValue}](${updatedAlert.results_link})`
        : `${prevValue} -> ${newValue}`;

    let maybeProfileLinks = '';
    if (this.hasProfileUrls) {
      // Add an additional column for the profiler before and after so users can
      // find the profiler links easily. Only add this column if at least one alert
      // has profile urls.
      maybeProfileLinks =
        updatedAlert &&
        updatedAlert.profile_url &&
        updatedAlert.prev_profile_url
          ? `[Before](${getPerfAnalysisUrl(
              updatedAlert.prev_profile_url,
            )})/[After](${getPerfAnalysisUrl(updatedAlert.profile_url)}) |`
          : ' |';
    }

    return `| [${amountPct}%](${graphLink})  | ${suiteTestName} | ${platform} | ${extraOptions} | ${alertValues} | ${maybeProfileLinks}`;
  }