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

mutations.js « store « import_projects « javascripts « assets « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: b3dbef896a64ed9f32fc087af75094c2b57746dd (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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
import Vue from 'vue';
import * as types from './mutation_types';
import { STATUSES } from '../constants';

export default {
  [types.SET_FILTER](state, filter) {
    state.filter = filter;
  },

  [types.REQUEST_REPOS](state) {
    state.isLoadingRepos = true;
  },

  [types.RECEIVE_REPOS_SUCCESS](
    state,
    { importedProjects, providerRepos, incompatibleRepos = [] },
  ) {
    // Normalizing structure to support legacy backend format
    // See https://gitlab.com/gitlab-org/gitlab/-/issues/27370#note_379034091 for details

    state.isLoadingRepos = false;

    state.repositories = [
      ...importedProjects.map(({ importSource, providerLink, importStatus, ...project }) => ({
        importSource: {
          id: `finished-${project.id}`,
          fullName: importSource,
          sanitizedName: project.name,
          providerLink,
        },
        importStatus,
        importedProject: project,
      })),
      ...providerRepos.map(project => ({
        importSource: project,
        importStatus: STATUSES.NONE,
        importedProject: null,
      })),
      ...incompatibleRepos.map(project => ({
        importSource: { ...project, incompatible: true },
        importStatus: STATUSES.NONE,
        importedProject: null,
      })),
    ];
  },

  [types.RECEIVE_REPOS_ERROR](state) {
    state.isLoadingRepos = false;
  },

  [types.REQUEST_IMPORT](state, { repoId, importTarget }) {
    const existingRepo = state.repositories.find(r => r.importSource.id === repoId);
    existingRepo.importStatus = STATUSES.SCHEDULING;
    existingRepo.importedProject = {
      fullPath: `/${importTarget.targetNamespace}/${importTarget.newName}`,
    };
  },

  [types.RECEIVE_IMPORT_SUCCESS](state, { importedProject, repoId }) {
    const { importStatus, ...project } = importedProject;

    const existingRepo = state.repositories.find(r => r.importSource.id === repoId);
    existingRepo.importStatus = importStatus;
    existingRepo.importedProject = project;
  },

  [types.RECEIVE_IMPORT_ERROR](state, repoId) {
    const existingRepo = state.repositories.find(r => r.importSource.id === repoId);
    existingRepo.importStatus = STATUSES.NONE;
    existingRepo.importedProject = null;
  },

  [types.RECEIVE_JOBS_SUCCESS](state, updatedProjects) {
    updatedProjects.forEach(updatedProject => {
      const repo = state.repositories.find(p => p.importedProject?.id === updatedProject.id);
      if (repo) {
        repo.importStatus = updatedProject.importStatus;
      }
    });
  },

  [types.REQUEST_NAMESPACES](state) {
    state.isLoadingNamespaces = true;
  },

  [types.RECEIVE_NAMESPACES_SUCCESS](state, namespaces) {
    state.isLoadingNamespaces = false;
    state.namespaces = namespaces;
  },

  [types.RECEIVE_NAMESPACES_ERROR](state) {
    state.isLoadingNamespaces = false;
  },

  [types.SET_IMPORT_TARGET](state, { repoId, importTarget }) {
    const existingRepo = state.repositories.find(r => r.importSource.id === repoId);

    if (
      importTarget.targetNamespace === state.defaultTargetNamespace &&
      importTarget.newName === existingRepo.importSource.sanitizedName
    ) {
      Vue.delete(state.customImportTargets, repoId);
    } else {
      Vue.set(state.customImportTargets, repoId, importTarget);
    }
  },

  [types.SET_PAGE_INFO](state, pageInfo) {
    state.pageInfo = pageInfo;
  },

  [types.SET_PAGE](state, page) {
    state.pageInfo.page = page;
  },
};