summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/ide/services/index.js
blob: 6e6ebf3169fb1d600b30ca0a5651d17061b2c9e6 (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
import Vue from 'vue';
import VueResource from 'vue-resource';
import Api from '~/api';

Vue.use(VueResource);

export default {
  getTreeData(endpoint) {
    return Vue.http.get(endpoint, { params: { format: 'json' } });
  },
  getFileData(endpoint) {
    return Vue.http.get(endpoint, { params: { format: 'json' } });
  },
  getRawFileData(file) {
    if (file.tempFile) {
      return Promise.resolve(file.content);
    }

    if (file.raw) {
      return Promise.resolve(file.raw);
    }

    return Vue.http.get(file.rawPath, { params: { format: 'json' } }).then(res => res.text());
  },
  getBaseRawFileData(file, sha) {
    if (file.tempFile) {
      return Promise.resolve(file.baseRaw);
    }

    if (file.baseRaw) {
      return Promise.resolve(file.baseRaw);
    }

    return Vue.http
      .get(file.rawPath.replace(file.branchId, sha), {
        params: { format: 'json' },
      })
      .then(res => res.text());
  },
  getProjectData(namespace, project) {
    return Api.project(`${namespace}/${project}`);
  },
  getProjectMergeRequestData(projectId, mergeRequestId) {
    return Api.mergeRequest(projectId, mergeRequestId);
  },
  getProjectMergeRequestChanges(projectId, mergeRequestId) {
    return Api.mergeRequestChanges(projectId, mergeRequestId);
  },
  getProjectMergeRequestVersions(projectId, mergeRequestId) {
    return Api.mergeRequestVersions(projectId, mergeRequestId);
  },
  getProjectMergeRequestVersion(projectId, mergeRequestId, versionId) {
    return Api.mergeRequestVersion(projectId, mergeRequestId, versionId);
  },
  getBranchData(projectId, currentBranchId) {
    return Api.branchSingle(projectId, currentBranchId);
  },
  createBranch(projectId, payload) {
    const url = Api.buildUrl(Api.createBranchPath).replace(':id', projectId);

    return Vue.http.post(url, payload);
  },
  commit(projectId, payload) {
    return Api.commitMultiple(projectId, payload);
  },
  getTreeLastCommit(endpoint) {
    return Vue.http.get(endpoint, {
      params: {
        format: 'json',
      },
    });
  },
  getFiles(projectUrl, branchId) {
    const url = `${projectUrl}/files/${branchId}`;
    return Vue.http.get(url, {
      params: {
        format: 'json',
      },
    });
  },
};