2021-03-11 19:13:27 +05:30
|
|
|
import Api from '~/api';
|
2022-01-26 12:08:38 +05:30
|
|
|
import getIdeProject from 'ee_else_ce/ide/queries/get_ide_project.query.graphql';
|
2021-06-08 01:23:25 +05:30
|
|
|
import dismissUserCallout from '~/graphql_shared/mutations/dismiss_user_callout.mutation.graphql';
|
2022-01-26 12:08:38 +05:30
|
|
|
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
|
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';
|
2023-03-04 22:38:38 +05:30
|
|
|
import ciConfig from '~/ci/pipeline_editor/graphql/queries/ci_config.query.graphql';
|
2021-06-08 01:23:25 +05:30
|
|
|
import { query, mutate } from './gql';
|
2020-03-13 15:44:24 +05:30
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
const options = file.binary ? { responseType: 'arraybuffer' } : {};
|
|
|
|
|
2018-11-08 19:23:39 +05:30
|
|
|
return axios
|
|
|
|
.get(file.rawPath, {
|
2021-03-08 18:12:59 +05:30
|
|
|
transformResponse: [(f) => f],
|
|
|
|
...options,
|
2018-11-08 19:23:39 +05:30
|
|
|
})
|
|
|
|
.then(({ data }) => data);
|
2018-05-09 12:01:36 +05:30
|
|
|
},
|
2020-11-24 15:15:51 +05:30
|
|
|
getBaseRawFileData(file, projectId, ref) {
|
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 || '/',
|
2020-11-24 15:15:51 +05:30
|
|
|
projectId,
|
2020-03-13 15:44:24 +05:30
|
|
|
'-',
|
2019-12-26 22:10:19 +05:30
|
|
|
'raw',
|
2020-11-24 15:15:51 +05:30
|
|
|
ref,
|
2019-12-26 22:10:19 +05:30
|
|
|
escapeFileUrl(filePath),
|
|
|
|
),
|
|
|
|
{
|
2021-03-08 18:12:59 +05:30
|
|
|
transformResponse: [(f) => f],
|
2019-12-26 22:10:19 +05:30
|
|
|
},
|
|
|
|
)
|
2018-11-08 19:23:39 +05:30
|
|
|
.then(({ data }) => data);
|
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
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
getFiles(projectPath, ref) {
|
|
|
|
const url = `${gon.relative_url_root}/${projectPath}/-/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
|
|
|
},
|
2020-05-24 23:13:21 +05:30
|
|
|
pingUsage(projectPath) {
|
2021-09-30 23:02:18 +05:30
|
|
|
const url = `${gon.relative_url_root}/${projectPath}/service_ping/web_ide_pipelines_count`;
|
2020-05-24 23:13:21 +05:30
|
|
|
return axios.post(url);
|
|
|
|
},
|
2021-06-08 01:23:25 +05:30
|
|
|
getCiConfig(projectPath, content) {
|
|
|
|
return query({
|
|
|
|
query: ciConfig,
|
|
|
|
variables: { projectPath, content },
|
|
|
|
}).then(({ data }) => data.ciConfig);
|
|
|
|
},
|
|
|
|
dismissUserCallout(name) {
|
|
|
|
return mutate({
|
|
|
|
mutation: dismissUserCallout,
|
|
|
|
variables: { input: { featureName: name } },
|
|
|
|
}).then(({ data }) => data);
|
|
|
|
},
|
2022-01-26 12:08:38 +05:30
|
|
|
getProjectPermissionsData(projectPath) {
|
|
|
|
return query({
|
|
|
|
query: getIdeProject,
|
|
|
|
variables: { projectPath },
|
|
|
|
}).then(({ data }) => ({
|
|
|
|
...data.project,
|
|
|
|
id: getIdFromGraphQLId(data.project.id),
|
|
|
|
}));
|
|
|
|
},
|
2018-05-09 12:01:36 +05:30
|
|
|
};
|