All files / publisher/builds helpers.ts

100% Statements 33/33
77.77% Branches 14/18
100% Functions 2/2
100% Lines 33/33

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 1071x 1x 1x 1x 1x 1x 1x 1x 1x 1x   1x 1x 1x                   1x                                                                       12x   12x 2x 10x 3x     12x                   4x 3x 3x 3x 3x   3x 1x   2x 1x     1x   1x     1x           1x          
const NEVER_BUILT = "never_built";
const BUILDING_SOON = "building_soon";
const WONT_RELEASE = "wont_release";
const RELEASED = "released";
const RELEASE_FAILED = "release_failed";
const RELEASING_SOON = "releasing_soon";
const IN_PROGRESS = "in_progress";
const FAILED_TO_BUILD = "failed_to_build";
const CANCELLED = "cancelled";
const UNKNOWN = "unknown";
 
const ERROR = "ERROR";
const SUCCESS = "SUCCESS";
const IDLE = "IDLE";
 
export const UserFacingStatus: {
  [key: string]: {
    statusMessage: string;
    shortStatusMessage: string;
    icon: string | undefined;
    priority: number;
    badge: string;
  };
} = {
  // Used only when there is no build returned from LP.
  // When build is returned from LP (scheduled) it's 'Building soon' for BSI.
  [NEVER_BUILT]: createStatus("Never built", "Never built", 8, NEVER_BUILT),
  [BUILDING_SOON]: createStatus("Building soon", "Building", 7, BUILDING_SOON),
  [WONT_RELEASE]: createStatus(
    "Built, won’t be released",
    "Built",
    6,
    WONT_RELEASE,
  ),
  [RELEASED]: createStatus("Released", "Released", 5, "released"),
  [RELEASE_FAILED]: createStatus(
    "Built, failed to release",
    "Failed",
    4,
    RELEASE_FAILED,
  ),
  [RELEASING_SOON]: createStatus("Releasing", "Releasing", 3, RELEASING_SOON),
  [IN_PROGRESS]: createStatus("In progress", "In progress", 2, IN_PROGRESS),
  [FAILED_TO_BUILD]: createStatus(
    "Failed to build",
    "Failed",
    1,
    FAILED_TO_BUILD,
  ),
  [CANCELLED]: createStatus("Cancelled", "Cancelled", 8, CANCELLED),
  [UNKNOWN]: createStatus("Unknown", "Unknown", 8, NEVER_BUILT),
};
 
export function createStatus(
  statusMessage: string,
  shortStatusMessage: string,
  priority: number,
  badge: string,
) {
  const loadingStatus = [IN_PROGRESS, RELEASING_SOON];
  let icon;
  if (badge.indexOf("failed") > -1) {
    icon = "error";
  } else if (loadingStatus.indexOf(badge) > -1) {
    icon = "spinner u-animation--spin";
  }
 
  return {
    statusMessage,
    shortStatusMessage,
    icon: icon,
    priority,
    badge,
  };
}
 
export function createDuration(duration: string) {
  if (duration) {
    const durationParts = duration.split(":");
    const hours = parseInt(durationParts[0]);
    const minutes = parseInt(durationParts[1]);
    const seconds = Math.round(parseInt(durationParts[2]));
 
    if (hours > 0) {
      return `${hours} hour${hours > 1 ? "s" : ""}`;
    }
    if (minutes > 0) {
      return `${minutes} minute${minutes > 1 ? "s" : ""}`;
    }
 
    return `${seconds} second${seconds > 1 || seconds === 0 ? "s" : ""}`;
  }
  return "";
}
 
export const TriggerBuildStatus = {
  ERROR,
  SUCCESS,
  IDLE,
};
 
export const BuildRequestStatus = {
  PENDING: "Pending",
  COMPLETED: "Completed",
  FAILED: "Failed",
};