All files / app/assets/javascripts/ide/stores/modules/pipelines mutations.js

95.83% Statements 23/24
83.33% Branches 15/18
94.11% Functions 16/17
100% Lines 19/19

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          2x     1x     7x 7x   7x 4x                 4x 8x 8x                     3x       2x           2x           4x             4x           1x     1x     1x     1x 1x      
import * as types from './mutation_types';
import { normalizeJob } from './utils';
 
export default {
  [types.REQUEST_LATEST_PIPELINE](state) {
    state.isLoadingPipeline = true;
  },
  [types.RECEIVE_LASTEST_PIPELINE_ERROR](state) {
    state.isLoadingPipeline = false;
  },
  [types.RECEIVE_LASTEST_PIPELINE_SUCCESS](state, pipeline) {
    state.isLoadingPipeline = false;
    state.hasLoadedPipeline = true;
 
    if (pipeline) {
      state.latestPipeline = {
        id: pipeline.id,
        path: pipeline.path,
        commit: pipeline.commit,
        details: {
          status: pipeline.details.status,
        },
        yamlError: pipeline.yaml_errors,
      };
      state.stages = pipeline.details.stages.map((stage, i) => {
        const foundStage = state.stages.find((s) => s.id === i);
        return {
          id: i,
          dropdownPath: stage.dropdown_path,
          name: stage.name,
          status: stage.status,
          isCollapsed: foundStage ? foundStage.isCollapsed : false,
          isLoading: foundStage ? foundStage.isLoading : false,
          jobs: foundStage ? foundStage.jobs : [],
        };
      });
    } else {
      state.latestPipeline = null;
    }
  },
  [types.REQUEST_JOBS](state, id) {
    state.stages = state.stages.map((stage) => ({
      ...stage,
      isLoading: stage.id === id ? true : stage.isLoading,
    }));
  },
  [types.RECEIVE_JOBS_ERROR](state, id) {
    state.stages = state.stages.map((stage) => ({
      ...stage,
      isLoading: stage.id === id ? false : stage.isLoading,
    }));
  },
  [types.RECEIVE_JOBS_SUCCESS](state, { id, data }) {
    state.stages = state.stages.map((stage) => ({
      ...stage,
      isLoading: stage.id === id ? false : stage.isLoading,
      jobs: stage.id === id ? data.latest_statuses.map(normalizeJob) : stage.jobs,
    }));
  },
  [types.TOGGLE_STAGE_COLLAPSE](state, id) {
    state.stages = state.stages.map((stage) => ({
      ...stage,
      isCollapsed: stage.id === id ? !stage.isCollapsed : stage.isCollapsed,
    }));
  },
  [types.SET_DETAIL_JOB](state, job) {
    state.detailJob = { ...job };
  },
  [types.REQUEST_JOB_LOGS](state) {
    state.detailJob.isLoading = true;
  },
  [types.RECEIVE_JOB_LOGS_ERROR](state) {
    state.detailJob.isLoading = false;
  },
  [types.RECEIVE_JOB_LOGS_SUCCESS](state, data) {
    state.detailJob.isLoading = false;
    state.detailJob.output = data.html;
  },
};