async update()

in src/GitHubStatusDisplay.js [256:368]


  async update() {
    const currentTime = new Date();
    this.setState({ currentTime: currentTime });

    const branch = this.props.branch;
    const user = this.props.user;
    const repo = this.props.repo;
    const jsonUrl = `https://s3.amazonaws.com/ossci-job-status/v6/${user}/${repo}/${branch.replace(
      "/",
      "_"
    )}.json`;
    let commits = null;
    try {
      commits = await axios.get(jsonUrl);
    } catch {
      this.setState({ fetchError: true });
      return;
    }

    // Marshal new build format into the old build format
    const builds = [];
    for (const commit of commits.data) {
      const build_map = new Map();
      for (const job of commit.jobs) {
        let status = job.status;
        if (status === "neutral") {
          status = "skipped";
        }
        if (status === "queued") {
          status = "pending";
        }
        build_map.set(job.name, {
          build_url: job.url,
          status: status,
        });
      }
      builds.push({
        author: {
          username: commit.author,
        },
        message: commit.headline + "\n" + commit.body,
        sb_map: build_map,
        id: commit.sha,
        timestamp: commit.date,
        url: `https://github.com/${this.props.user}/${this.props.repo}/commit/${commit.sha}`,
      });
    }

    if (this.props.repo === "pytorch" && branch === "master") {
      await this.addJenkinsResults(builds);
    }

    const data = {};

    data.updateTime = new Date();
    data.lastUpdateDate = new Date(commits.headers["last-modified"]);
    data.fetchedBuilds = true;
    data.connectedIn = data.updateTime - currentTime;

    const known_jobs_set = new Set();
    builds.forEach((build) => {
      build.sb_map.forEach((sb, job_name) => {
        known_jobs_set.add(job_name);
      });
    });

    data.known_jobs = [...known_jobs_set.values()].sort();
    data.builds = builds;

    // Figure out if we think something is broken or not.
    //  1. Consider the MOST RECENT finished build for any given sub
    //     build type.  If it is success, it's fine.
    //  2. Otherwise, check builds prior to it.  If the previous build
    //     also failed, we think it's broken!
    //
    // Special cases:
    //  - pytorch_doc_push: don't care about this
    //  - nightlies: these don't run all the time

    if (this.props.repo === "pytorch") {
      data.consecutive_failure_count = computeConsecutiveFailureCount(data);

      // Compute what notifications to show
      // We'll take a diff and then give notifications for keys that
      // changed
      if (!isMobile()) {
        if (this.state.consecutive_failure_count) {
          this.state.consecutive_failure_count.forEach((v, key) => {
            if (!data.consecutive_failure_count.has(key)) {
              // It's fixed!
              new window.Notification("✅ " + this.props.job, {
                body: summarize_job(key),
              });
            }
          });
        }
        data.consecutive_failure_count.forEach((v, key) => {
          // Don't produce notifications for initial failure!
          if (
            this.state.consecutive_failure_count &&
            !this.state.consecutive_failure_count.has(key)
          ) {
            // It's failed!
            new window.Notification("❌ " + this.props.job, {
              body: summarize_job(key),
            });
          }
        });
      }
    }

    this.setState(data);
  }