gitlab-org--gitlab-foss/app/assets/javascripts/ide/services/index.js

102 lines
3.1 KiB
JavaScript
Raw Normal View History

2018-06-27 05:43:26 -04:00
import axios from '~/lib/utils/axios_utils';
import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility';
import Api from '~/api';
import getUserPermissions from '../queries/getUserPermissions.query.graphql';
import { query } from './gql';
const fetchApiProjectData = projectPath => Api.project(projectPath).then(({ data }) => data);
const fetchGqlProjectData = projectPath =>
query({
query: getUserPermissions,
variables: { projectPath },
}).then(({ data }) => data.project);
export default {
getFileData(endpoint) {
return axios.get(endpoint, {
params: { format: 'json', viewer: 'none' },
});
},
getRawFileData(file) {
if (file.tempFile && !file.prevPath) {
return Promise.resolve(file.content);
}
if (file.raw || !file.rawPath) {
return Promise.resolve(file.raw);
}
return axios
.get(file.rawPath, {
2018-07-26 04:34:05 -04:00
transformResponse: [f => f],
})
.then(({ data }) => data);
},
getBaseRawFileData(file, projectId, ref) {
if (file.tempFile || file.baseRaw) return Promise.resolve(file.baseRaw);
2018-03-25 08:02:09 -04:00
// if files are renamed, their base path has changed
const filePath =
file.mrChange && file.mrChange.renamed_file ? file.mrChange.old_path : file.path;
2018-03-25 08:02:09 -04:00
return axios
.get(
joinPaths(
gon.relative_url_root || '/',
projectId,
'-',
'raw',
ref,
escapeFileUrl(filePath),
),
{
transformResponse: [f => f],
},
)
.then(({ data }) => data);
2018-03-25 08:02:09 -04:00
},
getProjectData(namespace, project) {
const projectPath = `${namespace}/${project}`;
return Promise.all([fetchApiProjectData(projectPath), fetchGqlProjectData(projectPath)]).then(
([apiProjectData, gqlProjectData]) => ({
data: {
...apiProjectData,
...gqlProjectData,
},
}),
);
},
getProjectMergeRequests(projectId, params = {}) {
return Api.projectMergeRequests(projectId, params);
},
getProjectMergeRequestData(projectId, mergeRequestId, params = {}) {
return Api.projectMergeRequest(projectId, mergeRequestId, params);
2018-03-23 06:45:43 -04:00
},
getProjectMergeRequestChanges(projectId, mergeRequestId) {
return Api.projectMergeRequestChanges(projectId, mergeRequestId);
2018-03-23 06:45:43 -04:00
},
2018-03-25 08:02:09 -04:00
getProjectMergeRequestVersions(projectId, mergeRequestId) {
return Api.projectMergeRequestVersions(projectId, mergeRequestId);
2018-03-25 08:02:09 -04:00
},
getBranchData(projectId, currentBranchId) {
return Api.branchSingle(projectId, currentBranchId);
},
commit(projectId, payload) {
return Api.commitMultiple(projectId, payload);
},
getFiles(projectPath, ref) {
const url = `${gon.relative_url_root}/${projectPath}/-/files/${ref}`;
2018-06-27 05:43:26 -04:00
return axios.get(url, { params: { format: 'json' } });
},
lastCommitPipelines({ getters }) {
const commitSha = getters.lastCommit.id;
return Api.commitPipelines(getters.currentProject.path_with_namespace, commitSha);
},
pingUsage(projectPath) {
const url = `${gon.relative_url_root}/${projectPath}/usage_ping/web_ide_pipelines_count`;
return axios.post(url);
},
};