All files / ee/app/assets/javascripts/codequality_report/store actions.js

100% Statements 18/18
100% Branches 2/2
100% Functions 7/7
100% Lines 15/15

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                  1x   1x 2x   2x   1x 1x 1x   1x   1x 3x   3x     3x 1x     2x 2x          
import Api from '~/api';
import createFlash from '~/flash';
import axios from '~/lib/utils/axios_utils';
import { s__ } from '~/locale';
 
import { parseCodeclimateMetrics } from '~/reports/codequality_report/store/utils/codequality_parser';
import { VIEW_EVENT_NAME } from './constants';
import * as types from './mutation_types';
 
export const setPage = ({ commit }, page) => commit(types.SET_PAGE, page);
 
export const requestReport = ({ commit }) => {
  commit(types.REQUEST_REPORT);
 
  Api.trackRedisHllUserEvent(VIEW_EVENT_NAME);
};
export const receiveReportSuccess = ({ state, commit }, data) => {
  const parsedIssues = parseCodeclimateMetrics(data, state.blobPath);
  commit(types.RECEIVE_REPORT_SUCCESS, parsedIssues);
};
export const receiveReportError = ({ commit }, error) => commit(types.RECEIVE_REPORT_ERROR, error);
 
export const fetchReport = ({ state, dispatch }) => {
  dispatch('requestReport');
 
  axios
    .get(state.endpoint)
    .then(({ data }) => {
      if (!state.blobPath) throw new Error();
      dispatch('receiveReportSuccess', data);
    })
    .catch((error) => {
      dispatch('receiveReportError', error);
      createFlash({
        message: s__('ciReport|There was an error fetching the codequality report.'),
      });
    });
};