actions.js 1.8 KB
Newer Older
P
Phil Hughes 已提交
1 2 3
import { __ } from '../../../../locale';
import Api from '../../../../api';
import flash from '../../../../flash';
P
Phil Hughes 已提交
4
import router from '../../../ide_router';
P
Phil Hughes 已提交
5
import { scopes } from './constants';
P
Phil Hughes 已提交
6
import * as types from './mutation_types';
P
Phil Hughes 已提交
7
import * as rootTypes from '../../mutation_types';
P
Phil Hughes 已提交
8

P
Phil Hughes 已提交
9 10 11
export const requestMergeRequests = ({ commit }, type) =>
  commit(types.REQUEST_MERGE_REQUESTS, type);
export const receiveMergeRequestsError = ({ commit }, type) => {
P
Phil Hughes 已提交
12
  flash(__('Error loading merge requests.'));
P
Phil Hughes 已提交
13
  commit(types.RECEIVE_MERGE_REQUESTS_ERROR, type);
P
Phil Hughes 已提交
14
};
P
Phil Hughes 已提交
15 16
export const receiveMergeRequestsSuccess = ({ commit }, { type, data }) =>
  commit(types.RECEIVE_MERGE_REQUESTS_SUCCESS, { type, data });
P
Phil Hughes 已提交
17

P
Phil Hughes 已提交
18 19 20 21
export const fetchMergeRequests = ({ dispatch, state: { state } }, { type, search = '' }) => {
  const scope = scopes[type];
  dispatch('requestMergeRequests', type);
  dispatch('resetMergeRequests', type);
P
Phil Hughes 已提交
22

P
Phil Hughes 已提交
23
  Api.mergeRequests({ scope, state, search })
P
Phil Hughes 已提交
24 25
    .then(({ data }) => dispatch('receiveMergeRequestsSuccess', { type, data }))
    .catch(() => dispatch('receiveMergeRequestsError', type));
P
Phil Hughes 已提交
26
};
27

P
Phil Hughes 已提交
28
export const resetMergeRequests = ({ commit }, type) => commit(types.RESET_MERGE_REQUESTS, type);
P
Phil Hughes 已提交
29

P
Phil Hughes 已提交
30 31 32 33 34
export const openMergeRequest = ({ commit, dispatch }, { projectPath, id }) => {
  commit(rootTypes.CLEAR_PROJECTS, null, { root: true });
  commit(rootTypes.SET_CURRENT_MERGE_REQUEST, `${id}`, { root: true });
  commit(rootTypes.RESET_OPEN_FILES, null, { root: true });
  dispatch('pipelines/resetLatestPipeline', null, { root: true });
P
Phil Hughes 已提交
35
  dispatch('setCurrentBranchId', '', { root: true });
36 37 38 39 40 41 42
  dispatch('pipelines/stopPipelinePolling', null, { root: true })
    .then(() => {
      dispatch('pipelines/clearEtagPoll', null, { root: true });
    })
    .catch(e => {
      throw e;
    });
P
Phil Hughes 已提交
43

P
Phil Hughes 已提交
44
  router.push(`/project/${projectPath}/merge_requests/${id}`);
P
Phil Hughes 已提交
45 46
};

47
export default () => {};