All files / publisher/release/actions pendingReleases.js

91.48% Statements 43/47
76.47% Branches 13/17
90% Functions 18/20
91.48% Lines 43/47

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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 1616x 6x 6x   6x   6x 6x 6x 6x             11x 11x 11x   11x         2x 2x   11x   11x 2x   2x       2x                         2x           11x                         2x                 2x                 1x           1x           2x                 4x 4x     4x   4x   4x         4x 3x           2x 2x 2x   2x 1x 2x             3x 3x           3x               6x        
export const RELEASE_REVISION = "RELEASE_REVISION";
export const UNDO_RELEASE = "UNDO_RELEASE";
export const CANCEL_PENDING_RELEASES = "CANCEL_PENDING_RELEASES";
export const SET_PROGRESSIVE_RELEASE_PERCENTAGE =
  "SET_PROGRESSIVE_RELEASE_PERCENTAGE";
export const UPDATE_PROGRESSIVE_RELEASE_PERCENTAGE =
  "UPDATE_PROGRESSIVE_RELEASE_PERCENTAGE";
export const PAUSE_PROGRESSIVE_RELEASE = "PAUSE_PROGRESSIVE_RELEASE";
export const RESUME_PROGRESSIVE_RELEASE = "RESUME_PROGRESSIVE_RELEASE";
export const CANCEL_PROGRESSIVE_RELEASE = "CANCEL_PROGRESSIVE_RELEASE";
 
import { getPendingChannelMap, getReleases } from "../selectors";
 
import { triggerGAEvent } from "../actions/gaEventTracking";
 
export function releaseRevision(revision, channel, progressive) {
  return (dispatch, getState) => {
    const state = getState();
    const { revisions, pendingReleases } = state;
 
    const previousRevisions = getReleases(
      state,
      revision.architectures,
      channel,
    )
      .filter((release) => release.revision !== revision.revision)
      .map((release) => revisions[release.revision]);
 
    let revisionToRelease = revision;
 
    if (!progressive && previousRevisions.length > 0 && previousRevisions[0]) {
      revisionToRelease = revisions[revision.revision];
 
      let percentage = 100;
 
      // If there's already a "null" release in staging that is progressive
      // assign that value to subsequent progressive releases
      Object.keys(pendingReleases).forEach((revision) => {
        Object.keys(pendingReleases[revision]).forEach((channel) => {
          const release = pendingReleases[revision][channel];
 
          if (release.progressive && percentage === 100) {
            percentage = release.progressive.percentage;
          }
        });
      });
 
      // Set key to null as we want to set the same key for a group
      // of releases on release. In actions/releases.js the key is either
      // updated, or the progressive object is removed completely
      progressive = {
        percentage: percentage,
        paused: false,
      };
    }
 
    return dispatch({
      type: RELEASE_REVISION,
      payload: {
        revision: revisionToRelease,
        channel,
        progressive,
        previousRevisions,
      },
    });
  };
}
 
export function setProgressiveReleasePercentage(percentage) {
  return {
    type: SET_PROGRESSIVE_RELEASE_PERCENTAGE,
    payload: {
      percentage,
    },
  };
}
 
export function updateProgressiveReleasePercentage(percentage) {
  return {
    type: UPDATE_PROGRESSIVE_RELEASE_PERCENTAGE,
    payload: {
      percentage,
    },
  };
}
 
export function pauseProgressiveRelease() {
  return {
    type: PAUSE_PROGRESSIVE_RELEASE,
  };
}
 
export function resumeProgressiveRelease() {
  return {
    type: RESUME_PROGRESSIVE_RELEASE,
  };
}
 
export function cancelProgressiveRelease(previousRevision) {
  return {
    type: CANCEL_PROGRESSIVE_RELEASE,
    payload: {
      previousRevision,
    },
  };
}
 
export function promoteRevision(revision, channel) {
  return (dispatch, getState) => {
    const pendingChannelMap = getPendingChannelMap(getState());
 
    // compare given revision with released revisions in this arch and channel
    const isAlreadyReleased = revision.architectures.every((arch) => {
      const releasedRevision =
        pendingChannelMap[channel] && pendingChannelMap[channel][arch];
 
      return (
        releasedRevision && releasedRevision.revision === revision.revision
      );
    });
 
    if (!isAlreadyReleased) {
      dispatch(releaseRevision(revision, channel, undefined));
    }
  };
}
 
export function promoteChannel(channel, targetChannel) {
  return (dispatch, getState) => {
    const pendingChannelMap = getPendingChannelMap(getState());
    const pendingInChannel = pendingChannelMap[channel];
 
    if (pendingInChannel) {
      Object.values(pendingInChannel).forEach((revision) => {
        dispatch(promoteRevision(revision, targetChannel));
      });
    }
  };
}
 
export function undoRelease(revision, channel) {
  return (dispatch) => {
    dispatch(
      triggerGAEvent(
        "click-cancel-promotion",
        `${channel}/${revision.architectures[0]}`,
      ),
    );
    return dispatch({
      type: UNDO_RELEASE,
      payload: { revision, channel },
    });
  };
}
 
export function cancelPendingReleases() {
  return {
    type: CANCEL_PENDING_RELEASES,
  };
}