All files / app/assets/javascripts/projects/commits/store actions.js

100% Statements 8/8
66.66% Branches 2/3
100% Functions 6/6
100% Lines 8/8

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                    1x     1x     1x         2x 2x               1x   1x 1x        
import * as Sentry from '~/sentry/sentry_browser_wrapper';
import { createAlert } from '~/alert';
import axios from '~/lib/utils/axios_utils';
import { joinPaths } from '~/lib/utils/url_utility';
import { __ } from '~/locale';
import { ACTIVE_AND_BLOCKED_USER_STATES } from '~/users_select/constants';
import * as types from './mutation_types';
 
export default {
  setInitialData({ commit }, data) {
    commit(types.SET_INITIAL_DATA, data);
  },
  receiveAuthorsSuccess({ commit }, authors) {
    commit(types.COMMITS_AUTHORS, authors);
  },
  receiveAuthorsError() {
    createAlert({
      message: __('An error occurred fetching the project authors.'),
    });
  },
  fetchAuthors({ dispatch, state }, author = null) {
    const { projectId } = state;
    return axios
      .get(joinPaths(gon.relative_url_root || '', '/-/autocomplete/users.json'), {
        params: {
          project_id: projectId,
          states: ACTIVE_AND_BLOCKED_USER_STATES,
          search: author,
        },
      })
      .then(({ data }) => dispatch('receiveAuthorsSuccess', data))
      .catch((error) => {
        Sentry.captureException(error);
        dispatch('receiveAuthorsError');
      });
  },
};