2018-06-27 05:43:26 -04:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-12-16 19:07:59 -05:00
|
|
|
import { joinPaths, escapeFileUrl } from '~/lib/utils/url_utility';
|
2018-03-20 10:12:48 -04:00
|
|
|
import Api from '~/api';
|
2020-02-14 10:09:08 -05:00
|
|
|
import getUserPermissions from '../queries/getUserPermissions.query.graphql';
|
2020-07-09 08:08:56 -04:00
|
|
|
import { query } from './gql';
|
2020-02-14 10:09:08 -05:00
|
|
|
|
|
|
|
const fetchApiProjectData = projectPath => Api.project(projectPath).then(({ data }) => data);
|
|
|
|
|
|
|
|
const fetchGqlProjectData = projectPath =>
|
2020-07-09 08:08:56 -04:00
|
|
|
query({
|
|
|
|
query: getUserPermissions,
|
|
|
|
variables: { projectPath },
|
|
|
|
}).then(({ data }) => data.project);
|
2018-03-20 10:12:48 -04:00
|
|
|
|
|
|
|
export default {
|
|
|
|
getFileData(endpoint) {
|
2018-06-28 10:09:21 -04:00
|
|
|
return axios.get(endpoint, {
|
|
|
|
params: { format: 'json', viewer: 'none' },
|
|
|
|
});
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
|
|
|
getRawFileData(file) {
|
2018-08-01 12:16:21 -04:00
|
|
|
if (file.tempFile && !file.prevPath) {
|
2018-03-20 10:12:48 -04:00
|
|
|
return Promise.resolve(file.content);
|
|
|
|
}
|
|
|
|
|
2020-04-10 08:09:36 -04:00
|
|
|
if (file.raw || !file.rawPath) {
|
2018-03-20 10:12:48 -04:00
|
|
|
return Promise.resolve(file.raw);
|
|
|
|
}
|
|
|
|
|
2018-06-28 10:09:21 -04:00
|
|
|
return axios
|
|
|
|
.get(file.rawPath, {
|
2018-07-26 04:34:05 -04:00
|
|
|
transformResponse: [f => f],
|
2018-06-28 10:09:21 -04:00
|
|
|
})
|
|
|
|
.then(({ data }) => data);
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2020-09-14 08:09:34 -04:00
|
|
|
getBaseRawFileData(file, projectId, ref) {
|
2019-11-16 16:06:10 -05:00
|
|
|
if (file.tempFile || file.baseRaw) return Promise.resolve(file.baseRaw);
|
2018-03-25 08:02:09 -04:00
|
|
|
|
2019-11-16 16:06:10 -05: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
|
|
|
|
2018-06-28 10:09:21 -04:00
|
|
|
return axios
|
2019-11-16 16:06:10 -05:00
|
|
|
.get(
|
|
|
|
joinPaths(
|
|
|
|
gon.relative_url_root || '/',
|
2020-09-14 08:09:34 -04:00
|
|
|
projectId,
|
2020-01-27 07:08:35 -05:00
|
|
|
'-',
|
2019-11-16 16:06:10 -05:00
|
|
|
'raw',
|
2020-09-14 08:09:34 -04:00
|
|
|
ref,
|
2019-11-16 16:06:10 -05:00
|
|
|
escapeFileUrl(filePath),
|
|
|
|
),
|
|
|
|
{
|
|
|
|
transformResponse: [f => f],
|
|
|
|
},
|
|
|
|
)
|
2018-06-28 10:09:21 -04:00
|
|
|
.then(({ data }) => data);
|
2018-03-25 08:02:09 -04:00
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
getProjectData(namespace, project) {
|
2020-02-14 10:09:08 -05:00
|
|
|
const projectPath = `${namespace}/${project}`;
|
|
|
|
|
|
|
|
return Promise.all([fetchApiProjectData(projectPath), fetchGqlProjectData(projectPath)]).then(
|
|
|
|
([apiProjectData, gqlProjectData]) => ({
|
|
|
|
data: {
|
|
|
|
...apiProjectData,
|
|
|
|
...gqlProjectData,
|
|
|
|
},
|
|
|
|
}),
|
|
|
|
);
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2019-03-01 11:33:18 -05:00
|
|
|
getProjectMergeRequests(projectId, params = {}) {
|
|
|
|
return Api.projectMergeRequests(projectId, params);
|
|
|
|
},
|
2018-07-03 04:09:20 -04:00
|
|
|
getProjectMergeRequestData(projectId, mergeRequestId, params = {}) {
|
2018-11-28 10:09:38 -05:00
|
|
|
return Api.projectMergeRequest(projectId, mergeRequestId, params);
|
2018-03-23 06:45:43 -04:00
|
|
|
},
|
|
|
|
getProjectMergeRequestChanges(projectId, mergeRequestId) {
|
2018-11-28 10:09:38 -05:00
|
|
|
return Api.projectMergeRequestChanges(projectId, mergeRequestId);
|
2018-03-23 06:45:43 -04:00
|
|
|
},
|
2018-03-25 08:02:09 -04:00
|
|
|
getProjectMergeRequestVersions(projectId, mergeRequestId) {
|
2018-11-28 10:09:38 -05:00
|
|
|
return Api.projectMergeRequestVersions(projectId, mergeRequestId);
|
2018-03-25 08:02:09 -04:00
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
getBranchData(projectId, currentBranchId) {
|
|
|
|
return Api.branchSingle(projectId, currentBranchId);
|
|
|
|
},
|
|
|
|
commit(projectId, payload) {
|
2019-06-26 10:07:56 -04:00
|
|
|
return Api.commitMultiple(projectId, payload);
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2020-05-11 05:09:45 -04:00
|
|
|
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' } });
|
2018-03-20 10:12:48 -04:00
|
|
|
},
|
2018-05-25 06:08:53 -04:00
|
|
|
lastCommitPipelines({ getters }) {
|
|
|
|
const commitSha = getters.lastCommit.id;
|
|
|
|
return Api.commitPipelines(getters.currentProject.path_with_namespace, commitSha);
|
|
|
|
},
|
2020-05-13 20:07:47 -04:00
|
|
|
pingUsage(projectPath) {
|
|
|
|
const url = `${gon.relative_url_root}/${projectPath}/usage_ping/web_ide_pipelines_count`;
|
|
|
|
return axios.post(url);
|
|
|
|
},
|
2018-03-20 10:12:48 -04:00
|
|
|
};
|