All files / app/assets/javascripts/ide/stores/modules/merge_requests actions.js

89.47% Statements 17/19
100% Branches 5/5
77.77% Functions 7/9
88.23% Lines 15/17

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          48x 48x 1x                         1x   48x 1x   48x       6x 6x   6x 6x       6x 5x 1x     48x  
import Api from '~/api';
import { __ } from '~/locale';
import { scopes } from './constants';
import * as types from './mutation_types';
 
export const requestMergeRequests = ({ commit }) => commit(types.REQUEST_MERGE_REQUESTS);
export const receiveMergeRequestsError = ({ commit, dispatch }, { type, search }) => {
  dispatch(
    'setErrorMessage',
    {
      text: __('Error loading merge requests.'),
      action: (payload) =>
        dispatch('fetchMergeRequests', payload).then(() =>
          dispatch('setErrorMessage', null, { root: true }),
        ),
      actionText: __('Please try again'),
      actionPayload: { type, search },
    },
    { root: true },
  );
  commit(types.RECEIVE_MERGE_REQUESTS_ERROR);
};
export const receiveMergeRequestsSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, data);
 
export const fetchMergeRequests = (
  { dispatch, state: { state }, rootState: { currentProjectId } },
  { type, search = '' },
) => {
  dispatch('requestMergeRequests');
  dispatch('resetMergeRequests');
 
  const scope = type && scopes[type];
  const request = scope
    ? Api.mergeRequests({ scope, state, search })
    : Api.projectMergeRequest(currentProjectId, '', { state, search });
 
  return request
    .then(({ data }) => dispatch('receiveMergeRequestsSuccess', data))
    .catch(() => dispatch('receiveMergeRequestsError', { type, search }));
};
 
export const resetMergeRequests = ({ commit }) => commit(types.RESET_MERGE_REQUESTS);