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

88.24% Statements 15/17
0% Branches 0/1
77.78% Functions 7/9
86.67% Lines 13/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        51x 51x 1x                         1x   51x 1x   51x 3x 3x   3x 2x 1x     51x  
import Api from '~/api';
import { __ } from '~/locale';
import * as types from './mutation_types';
 
export const requestBranches = ({ commit }) => commit(types.REQUEST_BRANCHES);
export const receiveBranchesError = ({ commit, dispatch }, { search }) => {
  dispatch(
    'setErrorMessage',
    {
      text: __('Error loading branches.'),
      action: (payload) =>
        dispatch('fetchBranches', payload).then(() =>
          dispatch('setErrorMessage', null, { root: true }),
        ),
      actionText: __('Please try again'),
      actionPayload: { search },
    },
    { root: true },
  );
  commit(types.RECEIVE_BRANCHES_ERROR);
};
export const receiveBranchesSuccess = ({ commit }, data) =>
  commit(types.RECEIVE_BRANCHES_SUCCESS, data);
 
export const fetchBranches = ({ dispatch, rootGetters }, { search = '' }) => {
  dispatch('requestBranches');
  dispatch('resetBranches');
 
  return Api.branches(rootGetters.currentProject.id, search, { sort: 'updated_desc' })
    .then(({ data }) => dispatch('receiveBranchesSuccess', data))
    .catch(() => dispatch('receiveBranchesError', { search }));
};
 
export const resetBranches = ({ commit }) => commit(types.RESET_BRANCHES);