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

100% Statements 13/13
100% Branches 2/2
100% Functions 6/6
100% Lines 12/12

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          139x   6x 143x   143x   8x 1x   2x         140x     6x 1x     6x 139x    
import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { STATUS_NOT_FOUND } from '../../constants';
import * as types from './mutation_types';
import { parseCodeclimateMetrics } from './utils/codequality_parser';
 
export const setPaths = ({ commit }, paths) => commit(types.SET_PATHS, paths);
 
export const fetchReports = ({ state, dispatch, commit }) => {
  commit(types.REQUEST_REPORTS);
 
  return pollUntilComplete(state.reportsPath)
    .then(({ data }) => {
      if (data.status === STATUS_NOT_FOUND) {
        return dispatch('receiveReportsError', data);
      }
      return dispatch('receiveReportsSuccess', {
        newIssues: parseCodeclimateMetrics(data.new_errors, state.headBlobPath),
        resolvedIssues: parseCodeclimateMetrics(data.resolved_errors, state.baseBlobPath),
      });
    })
    .catch((error) => dispatch('receiveReportsError', error));
};
 
export const receiveReportsSuccess = ({ commit }, data) => {
  commit(types.RECEIVE_REPORTS_SUCCESS, data);
};
 
export const receiveReportsError = ({ commit }, error) => {
  commit(types.RECEIVE_REPORTS_ERROR, error);
};