debian-mirror-gitlab/app/assets/javascripts/api.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

1023 lines
30 KiB
JavaScript
Raw Normal View History

2023-05-27 22:25:52 +05:30
import { createAlert } from '~/alert';
2019-12-26 22:10:19 +05:30
import { __ } from '~/locale';
2021-03-11 19:13:27 +05:30
import axios from './lib/utils/axios_utils';
import { joinPaths } from './lib/utils/url_utility';
2017-09-10 17:25:29 +05:30
2021-09-30 23:02:18 +05:30
export const DEFAULT_PER_PAGE = 20;
2020-01-01 13:55:28 +05:30
2021-03-08 18:12:59 +05:30
/**
* Slow deprecation Notice: Please rather use for new calls
* or during refactors /rest_api as this is doing named exports
* which support treeshaking
*/
2017-09-10 17:25:29 +05:30
const Api = {
2021-01-29 00:20:46 +05:30
DEFAULT_PER_PAGE,
2017-09-10 17:25:29 +05:30
groupsPath: '/api/:version/groups.json',
2018-03-17 18:26:18 +05:30
groupPath: '/api/:version/groups/:id',
2019-03-02 22:35:43 +05:30
groupMembersPath: '/api/:version/groups/:id/members',
2020-10-24 23:57:45 +05:30
groupMilestonesPath: '/api/:version/groups/:id/milestones',
2019-02-15 15:39:39 +05:30
subgroupsPath: '/api/:version/groups/:id/subgroups',
2021-09-04 01:27:46 +05:30
descendantGroupsPath: '/api/:version/groups/:id/descendant_groups',
2017-09-10 17:25:29 +05:30
namespacesPath: '/api/:version/namespaces.json',
2021-03-08 18:12:59 +05:30
groupInvitationsPath: '/api/:version/groups/:id/invitations',
2020-07-28 23:09:34 +05:30
groupPackagesPath: '/api/:version/groups/:id/packages',
projectPackagesPath: '/api/:version/projects/:id/packages',
projectPackagePath: '/api/:version/projects/:id/packages/:package_id',
2021-09-04 01:27:46 +05:30
projectPackageFilePath:
'/api/:version/projects/:id/packages/:package_id/package_files/:package_file_id',
2017-09-10 17:25:29 +05:30
groupProjectsPath: '/api/:version/groups/:id/projects.json',
2021-04-17 20:07:23 +05:30
groupSharePath: '/api/:version/groups/:id/share',
2018-03-17 18:26:18 +05:30
projectsPath: '/api/:version/projects.json',
projectPath: '/api/:version/projects/:id',
2019-09-30 21:07:59 +05:30
forkedProjectsPath: '/api/:version/projects/:id/forks',
2019-09-04 21:01:54 +05:30
projectLabelsPath: '/:namespace_path/:project_path/-/labels',
2020-11-24 15:15:51 +05:30
projectFileSchemaPath: '/:namespace_path/:project_path/-/schema/:ref/:filename',
2019-12-04 20:38:33 +05:30
projectUsersPath: '/api/:version/projects/:id/users',
2021-03-08 18:12:59 +05:30
projectInvitationsPath: '/api/:version/projects/:id/invitations',
2021-01-29 00:20:46 +05:30
projectMembersPath: '/api/:version/projects/:id/members',
2019-07-07 11:18:12 +05:30
projectMergeRequestsPath: '/api/:version/projects/:id/merge_requests',
2019-02-15 15:39:39 +05:30
projectMergeRequestPath: '/api/:version/projects/:id/merge_requests/:mrid',
projectMergeRequestChangesPath: '/api/:version/projects/:id/merge_requests/:mrid/changes',
projectMergeRequestVersionsPath: '/api/:version/projects/:id/merge_requests/:mrid/versions',
projectRunnersPath: '/api/:version/projects/:id/runners',
2020-03-13 15:44:24 +05:30
projectProtectedBranchesPath: '/api/:version/projects/:id/protected_branches',
2022-06-21 17:19:12 +05:30
projectProtectedBranchesNamePath: '/api/:version/projects/:id/protected_branches/:name',
2020-05-24 23:13:21 +05:30
projectSearchPath: '/api/:version/projects/:id/search',
2021-04-17 20:07:23 +05:30
projectSharePath: '/api/:version/projects/:id/share',
2020-05-24 23:13:21 +05:30
projectMilestonesPath: '/api/:version/projects/:id/milestones',
2021-01-03 14:25:43 +05:30
projectIssuePath: '/api/:version/projects/:id/issues/:issue_iid',
2022-10-11 01:57:18 +05:30
projectCreateIssuePath: '/api/:version/projects/:id/issues',
2018-11-08 19:23:39 +05:30
mergeRequestsPath: '/api/:version/merge_requests',
2021-04-29 21:17:54 +05:30
groupLabelsPath: '/api/:version/groups/:namespace_path/labels',
2017-09-10 17:25:29 +05:30
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
2021-01-29 00:20:46 +05:30
issuableTemplatesPath: '/:namespace_path/:project_path/templates/:type',
2018-12-05 23:21:45 +05:30
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
projectTemplatesPath: '/api/:version/projects/:id/templates/:type',
2019-09-30 21:07:59 +05:30
userCountsPath: '/api/:version/user_counts',
2017-09-10 17:25:29 +05:30
usersPath: '/api/:version/users.json',
2019-02-15 15:39:39 +05:30
userPath: '/api/:version/users/:id',
userStatusPath: '/api/:version/users/:id/status',
2019-12-26 22:10:19 +05:30
userProjectsPath: '/api/:version/users/:id/projects',
2019-02-15 15:39:39 +05:30
userPostStatusPath: '/api/:version/user/status',
2020-07-28 23:09:34 +05:30
commitPath: '/api/:version/projects/:id/repository/commits/:sha',
commitsPath: '/api/:version/projects/:id/repository/commits',
2019-02-15 15:39:39 +05:30
applySuggestionPath: '/api/:version/suggestions/:id/apply',
2020-06-23 00:09:42 +05:30
applySuggestionBatchPath: '/api/:version/suggestions/batch_apply',
2018-11-08 19:23:39 +05:30
commitPipelinesPath: '/:project_id/commit/:sha/pipelines',
2018-03-17 18:26:18 +05:30
branchSinglePath: '/api/:version/projects/:id/repository/branches/:branch',
createBranchPath: '/api/:version/projects/:id/repository/branches',
2019-02-15 15:39:39 +05:30
releasesPath: '/api/:version/projects/:id/releases',
2019-12-21 20:55:43 +05:30
releasePath: '/api/:version/projects/:id/releases/:tag_name',
2020-04-22 19:07:51 +05:30
releaseLinksPath: '/api/:version/projects/:id/releases/:tag_name/assets/links',
releaseLinkPath: '/api/:version/projects/:id/releases/:tag_name/assets/links/:link_id',
2019-12-04 20:38:33 +05:30
mergeRequestsPipeline: '/api/:version/projects/:id/merge_requests/:merge_request_iid/pipelines',
2020-01-01 13:55:28 +05:30
adminStatisticsPath: '/api/:version/application/statistics',
2021-01-03 14:25:43 +05:30
pipelineJobsPath: '/api/:version/projects/:id/pipelines/:pipeline_id/jobs',
2020-03-13 15:44:24 +05:30
pipelineSinglePath: '/api/:version/projects/:id/pipelines/:pipeline_id',
2020-05-24 23:13:21 +05:30
pipelinesPath: '/api/:version/projects/:id/pipelines/',
2020-10-24 23:57:45 +05:30
createPipelinePath: '/api/:version/projects/:id/pipeline',
2020-04-08 14:13:33 +05:30
environmentsPath: '/api/:version/projects/:id/environments',
2020-10-24 23:57:45 +05:30
contextCommitsPath:
'/api/:version/projects/:id/merge_requests/:merge_request_iid/context_commits',
2020-04-22 19:07:51 +05:30
rawFilePath: '/api/:version/projects/:id/repository/files/:path/raw',
2020-06-23 00:09:42 +05:30
issuePath: '/api/:version/projects/:id/issues/:issue_iid',
tagsPath: '/api/:version/projects/:id/repository/tags',
2020-10-24 23:57:45 +05:30
freezePeriodsPath: '/api/:version/projects/:id/freeze_periods',
2021-04-29 21:17:54 +05:30
freezePeriodPath: '/api/:version/projects/:id/freeze_periods/:freeze_period_id',
2021-09-30 23:02:18 +05:30
serviceDataIncrementCounterPath: '/api/:version/usage_data/increment_counter',
serviceDataIncrementUniqueUsersPath: '/api/:version/usage_data/increment_unique_users',
2021-01-03 14:25:43 +05:30
featureFlagUserLists: '/api/:version/projects/:id/feature_flags_user_lists',
featureFlagUserList: '/api/:version/projects/:id/feature_flags_user_lists/:list_iid',
2021-01-29 00:20:46 +05:30
containerRegistryDetailsPath: '/api/:version/registry/repositories/:id/',
2021-03-11 19:13:27 +05:30
projectNotificationSettingsPath: '/api/:version/projects/:id/notification_settings',
groupNotificationSettingsPath: '/api/:version/groups/:id/notification_settings',
notificationSettingsPath: '/api/:version/notification_settings',
2022-01-26 12:08:38 +05:30
deployKeysPath: '/api/:version/deploy_keys',
2022-07-16 23:28:13 +05:30
secureFilePath: '/api/:version/projects/:project_id/secure_files/:secure_file_id',
2022-05-07 20:08:51 +05:30
secureFilesPath: '/api/:version/projects/:project_id/secure_files',
2022-06-21 17:19:12 +05:30
dependencyProxyPath: '/api/:version/groups/:id/dependency_proxy/cache',
2017-09-10 17:25:29 +05:30
2020-06-23 00:09:42 +05:30
group(groupId, callback = () => {}) {
2018-05-09 12:01:36 +05:30
const url = Api.buildUrl(Api.groupPath).replace(':id', groupId);
return axios.get(url).then(({ data }) => {
callback(data);
2018-03-17 18:26:18 +05:30
2018-05-09 12:01:36 +05:30
return data;
});
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2020-07-28 23:09:34 +05:30
groupPackages(id, options = {}) {
const url = Api.buildUrl(this.groupPackagesPath).replace(':id', id);
return axios.get(url, options);
},
projectPackages(id, options = {}) {
const url = Api.buildUrl(this.projectPackagesPath).replace(':id', id);
return axios.get(url, options);
},
buildProjectPackageUrl(projectId, packageId) {
return Api.buildUrl(this.projectPackagePath)
.replace(':id', projectId)
.replace(':package_id', packageId);
},
projectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.get(url);
},
deleteProjectPackage(projectId, packageId) {
const url = this.buildProjectPackageUrl(projectId, packageId);
return axios.delete(url);
},
2021-09-04 01:27:46 +05:30
deleteProjectPackageFile(projectId, packageId, fileId) {
const url = Api.buildUrl(this.projectPackageFilePath)
.replace(':id', projectId)
.replace(':package_id', packageId)
.replace(':package_file_id', fileId);
return axios.delete(url);
},
2021-01-29 00:20:46 +05:30
containerRegistryDetails(registryId, options = {}) {
const url = Api.buildUrl(this.containerRegistryDetailsPath).replace(':id', registryId);
return axios.get(url, options);
},
2020-03-13 15:44:24 +05:30
groupMembers(id, options) {
2019-03-02 22:35:43 +05:30
const url = Api.buildUrl(this.groupMembersPath).replace(':id', encodeURIComponent(id));
2020-03-13 15:44:24 +05:30
return axios.get(url, {
params: {
per_page: DEFAULT_PER_PAGE,
...options,
},
});
2019-03-02 22:35:43 +05:30
},
2022-06-21 17:19:12 +05:30
inviteGroupMembers(id, data) {
2021-03-08 18:12:59 +05:30
const url = Api.buildUrl(this.groupInvitationsPath).replace(':id', encodeURIComponent(id));
return axios.post(url, data);
},
2020-10-24 23:57:45 +05:30
groupMilestones(id, options) {
const url = Api.buildUrl(this.groupMilestonesPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: {
per_page: DEFAULT_PER_PAGE,
...options,
},
});
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getGroups` method in `~/rest_api` instead.
*/
2020-04-08 14:13:33 +05:30
groups(query, options, callback = () => {}) {
2017-09-10 17:25:29 +05:30
const url = Api.buildUrl(Api.groupsPath);
2018-05-09 12:01:36 +05:30
return axios
.get(url, {
2020-05-24 23:13:21 +05:30
params: {
search: query,
per_page: DEFAULT_PER_PAGE,
...options,
},
2018-05-09 12:01:36 +05:30
})
2018-03-17 18:26:18 +05:30
.then(({ data }) => {
callback(data);
return data;
});
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2021-03-11 19:13:27 +05:30
groupLabels(namespace, options = {}) {
2019-12-21 20:55:43 +05:30
const url = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespace);
2021-03-11 19:13:27 +05:30
return axios.get(url, options).then(({ data }) => data);
2019-12-21 20:55:43 +05:30
},
2017-08-17 22:00:37 +05:30
// Return namespaces list. Filtered by query
2017-09-10 17:25:29 +05:30
namespaces(query, callback) {
const url = Api.buildUrl(Api.namespacesPath);
2018-05-09 12:01:36 +05:30
return axios
.get(url, {
params: {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2018-05-09 12:01:36 +05:30
},
})
2018-03-17 18:26:18 +05:30
.then(({ data }) => callback(data));
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getProjects` method in `~/rest_api` instead.
*/
2020-04-08 14:13:33 +05:30
projects(query, options, callback = () => {}) {
2017-09-10 17:25:29 +05:30
const url = Api.buildUrl(Api.projectsPath);
2018-03-17 18:26:18 +05:30
const defaults = {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2018-03-17 18:26:18 +05:30
simple: true,
};
if (gon.current_user_id) {
defaults.membership = true;
}
2018-05-09 12:01:36 +05:30
return axios
.get(url, {
2022-06-21 17:19:12 +05:30
params: { ...defaults, ...options },
2018-05-09 12:01:36 +05:30
})
2019-12-26 22:10:19 +05:30
.then(({ data, headers }) => {
2018-03-17 18:26:18 +05:30
callback(data);
2019-12-26 22:10:19 +05:30
return { data, headers };
2018-03-17 18:26:18 +05:30
});
},
2019-12-04 20:38:33 +05:30
projectUsers(projectPath, query = '', options = {}) {
const url = Api.buildUrl(this.projectUsersPath).replace(':id', encodeURIComponent(projectPath));
return axios
.get(url, {
params: {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2019-12-04 20:38:33 +05:30
...options,
},
})
.then(({ data }) => data);
},
2022-06-21 17:19:12 +05:30
inviteProjectMembers(id, data) {
2021-03-08 18:12:59 +05:30
const url = Api.buildUrl(this.projectInvitationsPath).replace(':id', encodeURIComponent(id));
return axios.post(url, data);
},
2018-03-17 18:26:18 +05:30
// Return single project
project(projectPath) {
2018-05-09 12:01:36 +05:30
const url = Api.buildUrl(Api.projectPath).replace(':id', encodeURIComponent(projectPath));
return axios.get(url);
},
2020-03-13 15:44:24 +05:30
// Update a single project
updateProject(projectPath, data) {
const url = Api.buildUrl(Api.projectPath).replace(':id', encodeURIComponent(projectPath));
return axios.put(url, data);
},
2019-09-30 21:07:59 +05:30
/**
* Get all projects for a forked relationship to a specified project
* @param {string} projectPath - Path or ID of a project
* @param {Object} params - Get request parameters
* @returns {Promise} - Request promise
*/
projectForks(projectPath, params) {
const url = Api.buildUrl(Api.forkedProjectsPath).replace(
':id',
encodeURIComponent(projectPath),
);
return axios.get(url, { params });
},
2019-07-07 11:18:12 +05:30
/**
2021-04-29 21:17:54 +05:30
* Get all merge requests for a project, eventually filtering based on
2019-07-07 11:18:12 +05:30
* supplied parameters
* @param projectPath
* @param params
* @returns {Promise}
*/
projectMergeRequests(projectPath, params = {}) {
const url = Api.buildUrl(Api.projectMergeRequestsPath).replace(
':id',
encodeURIComponent(projectPath),
);
return axios.get(url, { params });
},
2020-04-22 19:07:51 +05:30
createProjectMergeRequest(projectPath, options) {
const url = Api.buildUrl(Api.projectMergeRequestsPath).replace(
':id',
encodeURIComponent(projectPath),
);
return axios.post(url, options);
},
2021-04-29 21:17:54 +05:30
// Return merge request for project
2019-02-15 15:39:39 +05:30
projectMergeRequest(projectPath, mergeRequestId, params = {}) {
const url = Api.buildUrl(Api.projectMergeRequestPath)
2018-05-09 12:01:36 +05:30
.replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId);
2018-11-08 19:23:39 +05:30
return axios.get(url, { params });
},
2019-02-15 15:39:39 +05:30
projectMergeRequestChanges(projectPath, mergeRequestId) {
const url = Api.buildUrl(Api.projectMergeRequestChangesPath)
2018-05-09 12:01:36 +05:30
.replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId);
2018-03-17 18:26:18 +05:30
return axios.get(url);
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2019-02-15 15:39:39 +05:30
projectMergeRequestVersions(projectPath, mergeRequestId) {
const url = Api.buildUrl(Api.projectMergeRequestVersionsPath)
2019-01-03 12:48:30 +05:30
.replace(':id', encodeURIComponent(projectPath))
.replace(':mrid', mergeRequestId);
2018-12-23 12:14:25 +05:30
2019-01-03 12:48:30 +05:30
return axios.get(url);
2018-12-23 12:14:25 +05:30
},
2019-02-15 15:39:39 +05:30
projectRunners(projectPath, config = {}) {
const url = Api.buildUrl(Api.projectRunnersPath).replace(
':id',
encodeURIComponent(projectPath),
);
return axios.get(url, config);
},
2020-03-13 15:44:24 +05:30
projectProtectedBranches(id, query = '') {
const url = Api.buildUrl(Api.projectProtectedBranchesPath).replace(
':id',
encodeURIComponent(id),
);
return axios
.get(url, {
params: {
search: query,
per_page: DEFAULT_PER_PAGE,
},
})
.then(({ data }) => data);
},
2022-06-21 17:19:12 +05:30
projectProtectedBranch(id, branchName) {
const url = Api.buildUrl(Api.projectProtectedBranchesNamePath)
.replace(':id', encodeURIComponent(id))
.replace(':name', branchName);
return axios.get(url).then(({ data }) => data);
},
2020-05-24 23:13:21 +05:30
projectSearch(id, options = {}) {
const url = Api.buildUrl(Api.projectSearchPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: {
search: options.search,
scope: options.scope,
},
});
},
2021-04-17 20:07:23 +05:30
projectShareWithGroup(id, options = {}) {
const url = Api.buildUrl(Api.projectSharePath).replace(':id', encodeURIComponent(id));
return axios.post(url, {
expires_at: options.expires_at,
group_access: options.group_access,
group_id: options.group_id,
});
},
2020-11-24 15:15:51 +05:30
projectMilestones(id, params = {}) {
2020-05-24 23:13:21 +05:30
const url = Api.buildUrl(Api.projectMilestonesPath).replace(':id', encodeURIComponent(id));
2020-11-24 15:15:51 +05:30
return axios.get(url, {
params,
});
2020-05-24 23:13:21 +05:30
},
2021-01-03 14:25:43 +05:30
addProjectIssueAsTodo(projectId, issueIid) {
const url = Api.buildUrl(Api.projectIssuePath)
.replace(':id', encodeURIComponent(projectId))
.replace(':issue_iid', encodeURIComponent(issueIid));
return axios.post(`${url}/todo`);
},
2019-02-15 15:39:39 +05:30
mergeRequests(params = {}) {
const url = Api.buildUrl(Api.mergeRequestsPath);
return axios.get(url, { params });
},
2017-09-10 17:25:29 +05:30
newLabel(namespacePath, projectPath, data, callback) {
2018-03-17 18:26:18 +05:30
let url;
2021-04-29 21:17:54 +05:30
let payload;
2018-03-17 18:26:18 +05:30
if (projectPath) {
url = Api.buildUrl(Api.projectLabelsPath)
.replace(':namespace_path', namespacePath)
.replace(':project_path', projectPath);
2021-04-29 21:17:54 +05:30
payload = {
label: data,
};
2018-03-17 18:26:18 +05:30
} else {
url = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespacePath);
2021-04-29 21:17:54 +05:30
// groupLabelsPath uses public API which accepts
// `name` and `color` props.
payload = {
name: data.title,
color: data.color,
};
2018-03-17 18:26:18 +05:30
}
2018-05-09 12:01:36 +05:30
return axios
.post(url, {
2021-04-29 21:17:54 +05:30
...payload,
2018-05-09 12:01:36 +05:30
})
2021-03-08 18:12:59 +05:30
.then((res) => callback(res.data))
.catch((e) => callback(e.response.data));
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2017-08-17 22:00:37 +05:30
// Return group projects list. Filtered by query
2022-07-23 23:45:48 +05:30
groupProjects(groupId, query, options, callback = () => {}) {
2018-05-09 12:01:36 +05:30
const url = Api.buildUrl(Api.groupProjectsPath).replace(':id', groupId);
2018-11-08 19:23:39 +05:30
const defaults = {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2018-11-08 19:23:39 +05:30
};
2018-05-09 12:01:36 +05:30
return axios
.get(url, {
2020-05-24 23:13:21 +05:30
params: { ...defaults, ...options },
2018-05-09 12:01:36 +05:30
})
2022-06-21 17:19:12 +05:30
.then(({ data, headers }) => {
callback(data);
return { data, headers };
2021-02-22 17:27:13 +05:30
});
2017-09-10 17:25:29 +05:30
},
2021-04-17 20:07:23 +05:30
groupShareWithGroup(id, options = {}) {
const url = Api.buildUrl(Api.groupSharePath).replace(':id', encodeURIComponent(id));
return axios.post(url, {
expires_at: options.expires_at,
group_access: options.group_access,
group_id: options.group_id,
});
},
2020-07-28 23:09:34 +05:30
commit(id, sha, params = {}) {
const url = Api.buildUrl(this.commitPath)
.replace(':id', encodeURIComponent(id))
.replace(':sha', encodeURIComponent(sha));
return axios.get(url, { params });
},
2018-03-17 18:26:18 +05:30
commitMultiple(id, data) {
2021-01-03 14:25:43 +05:30
// see https://docs.gitlab.com/ee/api/commits.html#create-a-commit-with-multiple-files-and-actions
2020-07-28 23:09:34 +05:30
const url = Api.buildUrl(Api.commitsPath).replace(':id', encodeURIComponent(id));
2018-03-17 18:26:18 +05:30
return axios.post(url, JSON.stringify(data), {
headers: {
'Content-Type': 'application/json; charset=utf-8',
},
});
},
2021-03-11 19:13:27 +05:30
applySuggestion(id, message = '') {
2019-02-15 15:39:39 +05:30
const url = Api.buildUrl(Api.applySuggestionPath).replace(':id', encodeURIComponent(id));
2021-04-17 20:07:23 +05:30
const params = { commit_message: message };
2019-02-15 15:39:39 +05:30
2021-03-11 19:13:27 +05:30
return axios.put(url, params);
2019-02-15 15:39:39 +05:30
},
2021-11-18 22:05:49 +05:30
applySuggestionBatch(ids, message) {
2020-06-23 00:09:42 +05:30
const url = Api.buildUrl(Api.applySuggestionBatchPath);
2021-11-18 22:05:49 +05:30
return axios.put(url, { ids, commit_message: message });
2020-06-23 00:09:42 +05:30
},
2018-11-08 19:23:39 +05:30
commitPipelines(projectId, sha) {
const encodedProjectId = projectId
.split('/')
2021-03-08 18:12:59 +05:30
.map((fragment) => encodeURIComponent(fragment))
2018-11-08 19:23:39 +05:30
.join('/');
const url = Api.buildUrl(Api.commitPipelinesPath)
.replace(':project_id', encodedProjectId)
.replace(':sha', encodeURIComponent(sha));
return axios.get(url);
},
2018-03-17 18:26:18 +05:30
branchSingle(id, branch) {
const url = Api.buildUrl(Api.branchSinglePath)
.replace(':id', encodeURIComponent(id))
2018-05-09 12:01:36 +05:30
.replace(':branch', encodeURIComponent(branch));
2018-03-17 18:26:18 +05:30
return axios.get(url);
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
projectTemplate(id, type, key, options, callback) {
const url = Api.buildUrl(this.projectTemplatePath)
.replace(':id', encodeURIComponent(id))
.replace(':type', type)
.replace(':key', encodeURIComponent(key));
2017-09-10 17:25:29 +05:30
2021-03-08 18:12:59 +05:30
return axios.get(url, { params: options }).then((res) => {
2018-12-05 23:21:45 +05:30
if (callback) callback(res.data);
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
return res;
});
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2018-12-05 23:21:45 +05:30
projectTemplates(id, type, params = {}, callback) {
const url = Api.buildUrl(this.projectTemplatesPath)
.replace(':id', encodeURIComponent(id))
.replace(':type', type);
2021-03-08 18:12:59 +05:30
return axios.get(url, { params }).then((res) => {
2018-12-05 23:21:45 +05:30
if (callback) callback(res.data);
return res;
});
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
issueTemplate(namespacePath, projectPath, key, type, callback) {
2021-01-29 00:20:46 +05:30
const url = this.buildIssueTemplateUrl(
Api.issuableTemplatePath,
type,
projectPath,
namespacePath,
).replace(':key', encodeURIComponent(key));
return axios
.get(url)
.then(({ data }) => callback(null, data))
.catch(callback);
},
issueTemplates(namespacePath, projectPath, type, callback) {
const url = this.buildIssueTemplateUrl(
Api.issuableTemplatesPath,
type,
projectPath,
namespacePath,
);
2018-05-09 12:01:36 +05:30
return axios
.get(url)
2018-03-17 18:26:18 +05:30
.then(({ data }) => callback(null, data))
.catch(callback);
2017-08-17 22:00:37 +05:30
},
2017-09-10 17:25:29 +05:30
2021-01-29 00:20:46 +05:30
buildIssueTemplateUrl(path, type, projectPath, namespacePath) {
return Api.buildUrl(path)
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getUsers` method in `~/rest_api` instead.
*/
2017-09-10 17:25:29 +05:30
users(query, options) {
const url = Api.buildUrl(this.usersPath);
2018-03-17 18:26:18 +05:30
return axios.get(url, {
2020-05-24 23:13:21 +05:30
params: {
search: query,
per_page: DEFAULT_PER_PAGE,
...options,
},
2017-09-10 17:25:29 +05:30
});
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getUser` method in `~/rest_api` instead.
*/
2019-02-15 15:39:39 +05:30
user(id, options) {
const url = Api.buildUrl(this.userPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: options,
});
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getUserCounts` method in `~/rest_api` instead.
*/
2019-09-30 21:07:59 +05:30
userCounts() {
const url = Api.buildUrl(this.userCountsPath);
return axios.get(url);
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getUserStatus` method in `~/rest_api` instead.
*/
2019-02-15 15:39:39 +05:30
userStatus(id, options) {
const url = Api.buildUrl(this.userStatusPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: options,
});
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `getUserProjects` method in `~/rest_api` instead.
*/
2019-12-26 22:10:19 +05:30
userProjects(userId, query, options, callback) {
const url = Api.buildUrl(Api.userProjectsPath).replace(':id', userId);
const defaults = {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2019-12-26 22:10:19 +05:30
};
return axios
.get(url, {
2020-05-24 23:13:21 +05:30
params: { ...defaults, ...options },
2019-12-26 22:10:19 +05:30
})
.then(({ data }) => callback(data))
2021-09-04 01:27:46 +05:30
.catch(() =>
2022-07-23 23:45:48 +05:30
createAlert({
2021-09-04 01:27:46 +05:30
message: __('Something went wrong while fetching projects'),
}),
);
2019-12-26 22:10:19 +05:30
},
2018-11-18 11:00:15 +05:30
branches(id, query = '', options = {}) {
const url = Api.buildUrl(this.createBranchPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: {
search: query,
2020-01-01 13:55:28 +05:30
per_page: DEFAULT_PER_PAGE,
2018-11-18 11:00:15 +05:30
...options,
},
});
},
2018-11-08 19:23:39 +05:30
createBranch(id, { ref, branch }) {
const url = Api.buildUrl(this.createBranchPath).replace(':id', encodeURIComponent(id));
return axios.post(url, {
ref,
branch,
});
},
2021-03-08 18:12:59 +05:30
/**
* @deprecated This method will be removed soon. Use the
* `updateUserStatus` method in `~/rest_api` instead.
*/
2021-01-29 00:20:46 +05:30
postUserStatus({ emoji, message, availability }) {
2019-02-15 15:39:39 +05:30
const url = Api.buildUrl(this.userPostStatusPath);
2018-11-20 20:47:30 +05:30
2018-12-05 23:21:45 +05:30
return axios.put(url, {
emoji,
message,
2021-01-29 00:20:46 +05:30
availability,
2018-12-05 23:21:45 +05:30
});
2018-11-20 20:47:30 +05:30
},
2019-12-04 20:38:33 +05:30
postMergeRequestPipeline(id, { mergeRequestId }) {
const url = Api.buildUrl(this.mergeRequestsPipeline)
.replace(':id', encodeURIComponent(id))
.replace(':merge_request_iid', mergeRequestId);
return axios.post(url);
},
2020-01-01 13:55:28 +05:30
releases(id, options = {}) {
2019-02-15 15:39:39 +05:30
const url = Api.buildUrl(this.releasesPath).replace(':id', encodeURIComponent(id));
2020-01-01 13:55:28 +05:30
return axios.get(url, {
params: {
per_page: DEFAULT_PER_PAGE,
...options,
},
});
2019-02-15 15:39:39 +05:30
},
2019-12-21 20:55:43 +05:30
release(projectPath, tagName) {
const url = Api.buildUrl(this.releasePath)
.replace(':id', encodeURIComponent(projectPath))
.replace(':tag_name', encodeURIComponent(tagName));
return axios.get(url);
},
2020-10-24 23:57:45 +05:30
createRelease(projectPath, release) {
const url = Api.buildUrl(this.releasesPath).replace(':id', encodeURIComponent(projectPath));
return axios.post(url, release);
},
2019-12-21 20:55:43 +05:30
updateRelease(projectPath, tagName, release) {
const url = Api.buildUrl(this.releasePath)
.replace(':id', encodeURIComponent(projectPath))
.replace(':tag_name', encodeURIComponent(tagName));
return axios.put(url, release);
},
2020-04-22 19:07:51 +05:30
createReleaseLink(projectPath, tagName, link) {
const url = Api.buildUrl(this.releaseLinksPath)
.replace(':id', encodeURIComponent(projectPath))
.replace(':tag_name', encodeURIComponent(tagName));
return axios.post(url, link);
},
deleteReleaseLink(projectPath, tagName, linkId) {
const url = Api.buildUrl(this.releaseLinkPath)
.replace(':id', encodeURIComponent(projectPath))
.replace(':tag_name', encodeURIComponent(tagName))
.replace(':link_id', encodeURIComponent(linkId));
return axios.delete(url);
},
2019-12-04 20:38:33 +05:30
adminStatistics() {
const url = Api.buildUrl(this.adminStatisticsPath);
return axios.get(url);
},
2020-03-13 15:44:24 +05:30
pipelineSingle(id, pipelineId) {
const url = Api.buildUrl(this.pipelineSinglePath)
.replace(':id', encodeURIComponent(id))
.replace(':pipeline_id', encodeURIComponent(pipelineId));
return axios.get(url);
},
2021-01-29 00:20:46 +05:30
pipelineJobs(projectId, pipelineId, params) {
2021-01-03 14:25:43 +05:30
const url = Api.buildUrl(this.pipelineJobsPath)
.replace(':id', encodeURIComponent(projectId))
.replace(':pipeline_id', encodeURIComponent(pipelineId));
2021-01-29 00:20:46 +05:30
return axios.get(url, { params });
2021-01-03 14:25:43 +05:30
},
2020-05-24 23:13:21 +05:30
// Return all pipelines for a project or filter by query params
pipelines(id, options = {}) {
const url = Api.buildUrl(this.pipelinesPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: options,
});
},
2020-10-24 23:57:45 +05:30
createPipeline(id, data) {
const url = Api.buildUrl(this.createPipelinePath).replace(':id', encodeURIComponent(id));
return axios.post(url, data, {
headers: {
'Content-Type': 'application/json',
},
});
},
2020-04-08 14:13:33 +05:30
environments(id) {
const url = Api.buildUrl(this.environmentsPath).replace(':id', encodeURIComponent(id));
return axios.get(url);
2020-03-13 15:44:24 +05:30
},
2020-10-24 23:57:45 +05:30
createContextCommits(id, mergeRequestIid, data) {
const url = Api.buildUrl(this.contextCommitsPath)
.replace(':id', encodeURIComponent(id))
.replace(':merge_request_iid', mergeRequestIid);
return axios.post(url, data);
},
allContextCommits(id, mergeRequestIid) {
const url = Api.buildUrl(this.contextCommitsPath)
.replace(':id', encodeURIComponent(id))
.replace(':merge_request_iid', mergeRequestIid);
return axios.get(url);
},
removeContextCommits(id, mergeRequestIid, data) {
const url = Api.buildUrl(this.contextCommitsPath)
.replace(':id', id)
.replace(':merge_request_iid', mergeRequestIid);
return axios.delete(url, { data });
},
2021-04-29 21:17:54 +05:30
getRawFile(id, path, params = {}) {
2020-04-22 19:07:51 +05:30
const url = Api.buildUrl(this.rawFilePath)
.replace(':id', encodeURIComponent(id))
.replace(':path', encodeURIComponent(path));
return axios.get(url, { params });
},
2020-06-23 00:09:42 +05:30
updateIssue(project, issue, data = {}) {
const url = Api.buildUrl(Api.issuePath)
.replace(':id', encodeURIComponent(project))
.replace(':issue_iid', encodeURIComponent(issue));
return axios.put(url, data);
},
updateMergeRequest(project, mergeRequest, data = {}) {
const url = Api.buildUrl(Api.projectMergeRequestPath)
.replace(':id', encodeURIComponent(project))
.replace(':mrid', encodeURIComponent(mergeRequest));
return axios.put(url, data);
},
tags(id, query = '', options = {}) {
const url = Api.buildUrl(this.tagsPath).replace(':id', encodeURIComponent(id));
return axios.get(url, {
params: {
search: query,
per_page: DEFAULT_PER_PAGE,
...options,
},
});
},
2022-07-16 23:28:13 +05:30
tag(id, tagName) {
const url = Api.buildUrl(this.tagPath)
.replace(':id', encodeURIComponent(id))
.replace(':tag_name', encodeURIComponent(tagName));
return axios.get(url);
},
2020-10-24 23:57:45 +05:30
freezePeriods(id) {
const url = Api.buildUrl(this.freezePeriodsPath).replace(':id', encodeURIComponent(id));
return axios.get(url);
},
createFreezePeriod(id, freezePeriod = {}) {
const url = Api.buildUrl(this.freezePeriodsPath).replace(':id', encodeURIComponent(id));
return axios.post(url, freezePeriod);
},
2021-04-29 21:17:54 +05:30
updateFreezePeriod(id, freezePeriod = {}) {
const url = Api.buildUrl(this.freezePeriodPath)
.replace(':id', encodeURIComponent(id))
.replace(':freeze_period_id', encodeURIComponent(freezePeriod.id));
return axios.put(url, freezePeriod);
},
2021-11-11 11:23:49 +05:30
deleteFreezePeriod(id, freezePeriodId) {
const url = Api.buildUrl(this.freezePeriodPath)
.replace(':id', encodeURIComponent(id))
.replace(':freeze_period_id', encodeURIComponent(freezePeriodId));
return axios.delete(url);
},
2021-02-22 17:27:13 +05:30
trackRedisCounterEvent(event) {
if (!gon.features?.usageDataApi) {
return null;
}
2021-09-30 23:02:18 +05:30
const url = Api.buildUrl(this.serviceDataIncrementCounterPath);
2021-02-22 17:27:13 +05:30
const headers = {
'Content-Type': 'application/json',
};
return axios.post(url, { event }, { headers });
},
2021-01-03 14:25:43 +05:30
trackRedisHllUserEvent(event) {
2021-09-04 01:27:46 +05:30
if (!gon.current_user_id || !gon.features?.usageDataApi) {
2021-01-03 14:25:43 +05:30
return null;
}
2021-09-30 23:02:18 +05:30
const url = Api.buildUrl(this.serviceDataIncrementUniqueUsersPath);
2021-01-03 14:25:43 +05:30
const headers = {
'Content-Type': 'application/json',
};
return axios.post(url, { event }, { headers });
},
2017-09-10 17:25:29 +05:30
buildUrl(url) {
2019-07-31 22:56:46 +05:30
return joinPaths(gon.relative_url_root || '', url.replace(':version', gon.api_version));
2017-09-10 17:25:29 +05:30
},
2021-01-03 14:25:43 +05:30
fetchFeatureFlagUserLists(id, page) {
const url = Api.buildUrl(this.featureFlagUserLists).replace(':id', id);
return axios.get(url, { params: { page } });
},
2021-01-29 00:20:46 +05:30
searchFeatureFlagUserLists(id, search) {
const url = Api.buildUrl(this.featureFlagUserLists).replace(':id', id);
return axios.get(url, { params: { search } });
},
2021-01-03 14:25:43 +05:30
createFeatureFlagUserList(id, list) {
const url = Api.buildUrl(this.featureFlagUserLists).replace(':id', id);
return axios.post(url, list);
},
fetchFeatureFlagUserList(id, listIid) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':id', id)
.replace(':list_iid', listIid);
return axios.get(url);
},
updateFeatureFlagUserList(id, list) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':id', id)
.replace(':list_iid', list.iid);
return axios.put(url, list);
},
deleteFeatureFlagUserList(id, listIid) {
const url = Api.buildUrl(this.featureFlagUserList)
.replace(':id', id)
.replace(':list_iid', listIid);
return axios.delete(url);
},
2022-01-26 12:08:38 +05:30
deployKeys(params = {}) {
const url = Api.buildUrl(this.deployKeysPath);
return axios.get(url, { params: { per_page: DEFAULT_PER_PAGE, ...params } });
},
2022-05-07 20:08:51 +05:30
// TODO: replace this when GraphQL support has been added https://gitlab.com/gitlab-org/gitlab/-/issues/352184
projectSecureFiles(projectId, options = {}) {
const url = Api.buildUrl(this.secureFilesPath).replace(':project_id', projectId);
return axios.get(url, { params: { per_page: DEFAULT_PER_PAGE, ...options } });
},
2022-07-16 23:28:13 +05:30
uploadProjectSecureFile(projectId, fileData) {
const url = Api.buildUrl(this.secureFilesPath).replace(':project_id', projectId);
const headers = { 'Content-Type': 'multipart/form-data' };
return axios.post(url, fileData, { headers });
},
deleteProjectSecureFile(projectId, secureFileId) {
const url = Api.buildUrl(this.secureFilePath)
.replace(':project_id', projectId)
.replace(':secure_file_id', secureFileId);
return axios.delete(url);
},
2021-03-11 19:13:27 +05:30
async updateNotificationSettings(projectId, groupId, data = {}) {
let url = Api.buildUrl(this.notificationSettingsPath);
if (projectId) {
url = Api.buildUrl(this.projectNotificationSettingsPath).replace(':id', projectId);
} else if (groupId) {
url = Api.buildUrl(this.groupNotificationSettingsPath).replace(':id', groupId);
}
const result = await axios.put(url, data);
return result;
},
2021-01-03 14:25:43 +05:30
2021-03-11 19:13:27 +05:30
async getNotificationSettings(projectId, groupId) {
let url = Api.buildUrl(this.notificationSettingsPath);
2021-03-08 18:12:59 +05:30
2021-03-11 19:13:27 +05:30
if (projectId) {
url = Api.buildUrl(this.projectNotificationSettingsPath).replace(':id', projectId);
} else if (groupId) {
url = Api.buildUrl(this.groupNotificationSettingsPath).replace(':id', groupId);
2021-03-08 18:12:59 +05:30
}
2021-03-11 19:13:27 +05:30
const result = await axios.get(url);
return result;
2021-01-03 14:25:43 +05:30
},
2022-06-21 17:19:12 +05:30
deleteDependencyProxyCacheList(groupId, options = {}) {
const url = Api.buildUrl(this.dependencyProxyPath).replace(':id', groupId);
return axios.delete(url, { params: { ...options } });
},
2017-08-17 22:00:37 +05:30
};
2016-09-13 17:45:13 +05:30
2017-09-10 17:25:29 +05:30
export default Api;