All files / ee/app/assets/javascripts/analytics/code_review_analytics/store/modules/merge_requests actions.js

100% Statements 17/17
100% Branches 0/0
100% Functions 5/5
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 40 41 42 43 44 45 46 47 48 49 50              2x   2x 6x   6x           6x   6x       6x           6x   1x 1x 1x           5x 5x 5x           5x  
import API from 'ee/api';
import { createAlert } from '~/alert';
import { normalizeHeaders, parseIntPagination } from '~/lib/utils/common_utils';
import { __ } from '~/locale';
import { filterToQueryObject } from '~/vue_shared/components/filtered_search_bar/filtered_search_utils';
import * as types from './mutation_types';
 
export const setProjectId = ({ commit }, projectId) => commit(types.SET_PROJECT_ID, projectId);
 
export const fetchMergeRequests = ({ commit, state, rootState }) => {
  commit(types.REQUEST_MERGE_REQUESTS);
 
  const { projectId, pageInfo } = state;
  const {
    filters: {
      milestones: { selected: selectedMilestone },
      labels: { selectedList: selectedLabelList },
    },
  } = rootState;
 
  const filterBarQuery = filterToQueryObject({
    milestone_title: selectedMilestone,
    label_name: selectedLabelList,
  });
  const params = {
    project_id: projectId,
    page: pageInfo.page,
    ...filterBarQuery,
  };
 
  return API.codeReviewAnalytics(params)
    .then((response) => {
      const { headers, data } = response;
      const normalizedHeaders = normalizeHeaders(headers);
      commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, {
        pageInfo: parseIntPagination(normalizedHeaders),
        mergeRequests: data,
      });
    })
    .catch(({ response }) => {
      const { status } = response;
      commit(types.RECEIVE_MERGE_REQUESTS_ERROR, status);
      createAlert({
        message: __('An error occurred while loading merge requests.'),
      });
    });
};
 
export const setPage = ({ commit }, page) => commit(types.SET_PAGE, page);