debian-mirror-gitlab/app/assets/javascripts/ide/services/index.js

78 lines
2.3 KiB
JavaScript
Raw Normal View History

2018-11-08 19:23:39 +05:30
import axios from '~/lib/utils/axios_utils';
2020-01-01 13:55:28 +05:30
import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility';
2018-05-09 12:01:36 +05:30
import Api from '~/api';
export default {
getFileData(endpoint) {
2018-11-08 19:23:39 +05:30
return axios.get(endpoint, {
params: { format: 'json', viewer: 'none' },
});
2018-05-09 12:01:36 +05:30
},
getRawFileData(file) {
2018-11-18 11:00:15 +05:30
if (file.tempFile && !file.prevPath) {
2018-05-09 12:01:36 +05:30
return Promise.resolve(file.content);
}
if (file.raw) {
return Promise.resolve(file.raw);
}
2018-11-08 19:23:39 +05:30
return axios
.get(file.rawPath, {
transformResponse: [f => f],
})
.then(({ data }) => data);
2018-05-09 12:01:36 +05:30
},
getBaseRawFileData(file, sha) {
2019-12-26 22:10:19 +05:30
if (file.tempFile || file.baseRaw) return Promise.resolve(file.baseRaw);
2018-05-09 12:01:36 +05:30
2019-12-26 22:10:19 +05:30
// if files are renamed, their base path has changed
const filePath =
file.mrChange && file.mrChange.renamed_file ? file.mrChange.old_path : file.path;
2018-05-09 12:01:36 +05:30
2018-11-08 19:23:39 +05:30
return axios
2019-12-26 22:10:19 +05:30
.get(
joinPaths(
gon.relative_url_root || '/',
file.projectId,
'raw',
sha,
escapeFileUrl(filePath),
),
{
transformResponse: [f => f],
},
)
2018-11-08 19:23:39 +05:30
.then(({ data }) => data);
2018-05-09 12:01:36 +05:30
},
getProjectData(namespace, project) {
return Api.project(`${namespace}/${project}`);
},
2019-07-07 11:18:12 +05:30
getProjectMergeRequests(projectId, params = {}) {
return Api.projectMergeRequests(projectId, params);
},
2018-11-08 19:23:39 +05:30
getProjectMergeRequestData(projectId, mergeRequestId, params = {}) {
2019-02-15 15:39:39 +05:30
return Api.projectMergeRequest(projectId, mergeRequestId, params);
2018-05-09 12:01:36 +05:30
},
getProjectMergeRequestChanges(projectId, mergeRequestId) {
2019-02-15 15:39:39 +05:30
return Api.projectMergeRequestChanges(projectId, mergeRequestId);
2018-05-09 12:01:36 +05:30
},
getProjectMergeRequestVersions(projectId, mergeRequestId) {
2019-02-15 15:39:39 +05:30
return Api.projectMergeRequestVersions(projectId, mergeRequestId);
2018-05-09 12:01:36 +05:30
},
getBranchData(projectId, currentBranchId) {
return Api.branchSingle(projectId, currentBranchId);
},
commit(projectId, payload) {
2019-10-12 21:52:04 +05:30
return Api.commitMultiple(projectId, payload);
2018-05-09 12:01:36 +05:30
},
2019-12-26 22:10:19 +05:30
getFiles(projectUrl, ref) {
const url = `${projectUrl}/files/${ref}`;
2018-11-08 19:23:39 +05:30
return axios.get(url, { params: { format: 'json' } });
},
lastCommitPipelines({ getters }) {
const commitSha = getters.lastCommit.id;
return Api.commitPipelines(getters.currentProject.path_with_namespace, commitSha);
2018-05-09 12:01:36 +05:30
},
};