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

100 lines
2.9 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';
2020-03-13 15:44:24 +05:30
import getUserPermissions from '../queries/getUserPermissions.query.graphql';
import gqClient from './gql';
const fetchApiProjectData = projectPath => Api.project(projectPath).then(({ data }) => data);
const fetchGqlProjectData = projectPath =>
gqClient
.query({
query: getUserPermissions,
variables: { projectPath },
})
.then(({ data }) => data.project);
2018-05-09 12:01:36 +05:30
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);
}
2020-04-22 19:07:51 +05:30
if (file.raw || !file.rawPath) {
2018-05-09 12:01:36 +05:30
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,
2020-03-13 15:44:24 +05:30
'-',
2019-12-26 22:10:19 +05:30
'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) {
2020-03-13 15:44:24 +05:30
const projectPath = `${namespace}/${project}`;
return Promise.all([fetchApiProjectData(projectPath), fetchGqlProjectData(projectPath)]).then(
([apiProjectData, gqlProjectData]) => ({
data: {
...apiProjectData,
...gqlProjectData,
},
}),
);
2018-05-09 12:01:36 +05:30
},
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) {
2020-03-13 15:44:24 +05:30
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
},
};