github.com/zppinho/prow@v0.0.0-20240510014325-1738badeb017/cmd/deck/static/job-history/job-history.ts (about)

     1  import moment from "moment";
     2  import {cell, formatDuration} from '../common/common';
     3  
     4  declare const allBuilds: any;
     5  
     6  window.onload = (): void => {
     7    const tbody = document.getElementById("history-table-body")!;
     8  
     9    for (const build of allBuilds) {
    10      const tr = document.createElement("tr");
    11  
    12      let className = "";
    13      switch (build.Result) {
    14        case "SUCCESS":
    15          className = "run-success";
    16          break;
    17        case "FAILURE":
    18          className = "run-failure";
    19          break;
    20        case "ERROR":
    21          className = "run-error";
    22          break;
    23        case "ABORTED":
    24          className = "run-aborted";
    25          break;
    26        default:
    27          className = "run-pending";
    28      }
    29      tr.classList.add(className);
    30  
    31      tr.appendChild(cell.link(build.ID, build.SpyglassLink));
    32  
    33      if (build.Refs && build.Refs.pulls) {
    34        for (const pull of build.Refs.pulls) {
    35          tr.appendChild(cell.prRevision(`${build.Refs.org}/${build.Refs.repo}`, pull));
    36        }
    37      } else {
    38        tr.appendChild(cell.text(""));
    39      }
    40  
    41      const started = Date.parse(build.Started) / 1000;
    42      tr.appendChild(cell.time(build.ID, moment.unix(started)));
    43      tr.appendChild(cell.text(formatDuration(build.Duration / 1000000000 ))); // convert from ns to s.
    44      tr.appendChild(cell.text(build.Result));
    45  
    46      for (const child of tr.children) {
    47        child.classList.add("mdl-data-table__cell--non-numeric");
    48      }
    49  
    50      tbody.appendChild(tr);
    51    }
    52  };