function getComparison()

in beta-stability-pushlog.js [91:268]


function getComparison() {
  if (!getOption("beta1") || !getOption("beta2")) {
    return;
  }

  while (table.rows.length > 1) {
    table.deleteRow(table.rows.length - 1);
  }

  let url = new URL(location.href);
  url.search =
    "?product=" +
    getOption("product") +
    "&beta1=" +
    getOption("beta1") +
    "&beta2=" +
    getOption("beta2");
  history.replaceState({}, document.title, url.href);

  fetch(
    "https://product-details.mozilla.org/1.0/firefox_history_development_releases.json"
  )
    .then((response) => response.json())
    .then((release_history) => {
      let date1 = getReleaseDate(getOption("beta1"), release_history);
      let date2 = getReleaseDate(getOption("beta2"), release_history);
      let endDate1 = addDays(date1, 7);
      let endDate2 = addDays(date2, 7);

      document.getElementById("dates").innerHTML =
        getOption("beta1") +
        " released on " +
        dateToStr(date1) +
        " (crashes from " +
        dateToStr(date1) +
        " to " +
        dateToStr(endDate1) +
        ")<br>" +
        getOption("beta2") +
        " released on " +
        dateToStr(date2) +
        " (crashes from " +
        dateToStr(date2) +
        " to " +
        dateToStr(endDate2) +
        ")";

      let fromchange = getTag(getOption("beta1"));
      let tochange = getTag(getOption("beta2"));

      fetch(
        "https://hg.mozilla.org/releases/mozilla-beta/pushloghtml?fromchange=" +
          fromchange +
          "&tochange=" +
          tochange
      )
        .then((response) => response.text())
        .then((data) => {
          let bugs = new Set();
          let regex = /Bug ([0-9]+)/gi;
          let res;
          while ((res = regex.exec(data)) !== null) {
            bugs.add(res[1]);
          }

          let table = document.getElementById("table");

          bugs.forEach((bug) =>
            fetch(
              "https://bugzilla.mozilla.org/rest/bug/" +
                bug +
                "?include_fields=product,component,cf_crash_signature"
            )
              .then((response) => response.json())
              .then((data) => {
                // Skip bugs with no signatures.
                if (
                  "bugs" in data &&
                  data["bugs"][0]["cf_crash_signature"] == ""
                ) {
                  return;
                }

                // Skip bugs that are not related to the current product.
                if (
                  "bugs" in data &&
                  getOption("product") === "Firefox" &&
                  (data["bugs"][0]["product"] === "Firefox for Android" ||
                    data["bugs"][0]["component"] === "WebExtensions: Android")
                ) {
                  return;
                }

                // Skip bugs where the cf_crash_signature field is not defined.
                if (
                  "bugs" in data &&
                  !("cf_crash_signature" in data["bugs"][0])
                ) {
                  return;
                }

                let row = table.insertRow(table.rows.length);
                let bugElem = row.insertCell(0);
                let aElem = document.createElement("a");
                aElem.href =
                  "https://bugzilla.mozilla.org/show_bug.cgi?id=" + bug;
                aElem.textContent = bug;
                bugElem.appendChild(aElem);

                let signaturesCell = row.insertCell(1);

                let evolution = row.insertCell(2);

                let result = document.createElement("span");

                if (!("bugs" in data)) {
                  result.style.color = "maroon";
                  result.textContent = "Not accessible.";
                } else {
                  let signatures = data["bugs"][0]["cf_crash_signature"];
                  signatures = signatures.replace(/\[@ /g, "[@");
                  signatures = signatures.replace(/\[@/g, "");
                  signatures = signatures.replace(/ ]\r\n/g, "\\");
                  signatures = signatures.replace(/]\r\n/g, "\\");
                  signatures = signatures.replace("]", "");

                  signatures = signatures.split("\\");

                  for (let signature of signatures) {
                    let signatureElem = document.createElement("a");
                    signatureElem.href =
                      "https://crash-stats.mozilla.org/signature/?signature=" +
                      signature;
                    signatureElem.textContent = signature;
                    signaturesCell.appendChild(signatureElem);
                    signaturesCell.appendChild(document.createElement("br"));
                  }

                  let query1 = fetch(
                    "https://crash-stats.mozilla.org/api/SuperSearch/?product=" +
                      getOption("product") +
                      "&_results_number=0&_facets_size=0&version=" +
                      getOption("beta1") +
                      "&date=>%3D" +
                      dateToStr(date1) +
                      "&date=<%3D" +
                      dateToStr(endDate1) +
                      "&signature=%3D" +
                      signatures.join("&signature=%3D")
                  ).then((response) => response.json());
                  let query2 = fetch(
                    "https://crash-stats.mozilla.org/api/SuperSearch/?product=" +
                      getOption("product") +
                      "&_results_number=0&_facets_size=0&version=" +
                      getOption("beta2") +
                      "&date=>%3D" +
                      dateToStr(date2) +
                      "&date=<%3D" +
                      dateToStr(endDate2) +
                      "&signature=%3D" +
                      signatures.join("&signature=%3D")
                  ).then((response) => response.json());

                  Promise.all([query1, query2]).then((data) => {
                    result.textContent =
                      data[0]["total"] +
                      " before; " +
                      data[1]["total"] +
                      " after.";
                  });
                }

                evolution.appendChild(result);
              })
          );
        });
    });
}