Welcome to mirror list, hosted at ThFree Co, Russian Federation.

project.js « actions « stores « ide « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 75e332090cb232cbabe687306397be8094f949a1 (plain)
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
import service from '../../services';
import flash from '../../../flash';
import * as types from '../mutation_types';

// eslint-disable-next-line import/prefer-default-export
export const getProjectData = (
  { commit, state, dispatch },
  { namespace, projectId, force = false } = {},
) => new Promise((resolve, reject) => {
  if (!state.projects[`${namespace}/${projectId}`] || force) {
    service.getProjectData(namespace, projectId)
    .then(res => res.data)
    .then((data) => {
      commit(types.SET_PROJECT, { projectPath: `${namespace}/${projectId}`, project: data });
      if (!state.currentProjectId) commit(types.SET_CURRENT_PROJECT, `${namespace}/${projectId}`);
      resolve(data);
    })
    .catch(() => {
      flash('Error loading project data. Please try again.');
      reject(new Error(`Project not loaded ${namespace}/${projectId}`));
    });
  } else {
    resolve(state.projects[`${namespace}/${projectId}`]);
  }
});