2018-03-09 20:18:59 +00:00
|
|
|
import $ from 'jquery';
|
2018-01-30 09:10:58 +00:00
|
|
|
import _ from 'underscore';
|
2017-12-21 15:05:47 +00:00
|
|
|
import axios from './lib/utils/axios_utils';
|
2019-04-24 17:30:46 +00:00
|
|
|
import { joinPaths } from './lib/utils/url_utility';
|
2017-05-19 21:22:46 +00:00
|
|
|
|
|
|
|
const Api = {
|
|
|
|
groupsPath: '/api/:version/groups.json',
|
2018-01-30 09:10:58 +00:00
|
|
|
groupPath: '/api/:version/groups/:id',
|
2019-01-16 21:57:50 +00:00
|
|
|
groupMembersPath: '/api/:version/groups/:id/members',
|
2018-10-17 20:47:18 +00:00
|
|
|
subgroupsPath: '/api/:version/groups/:id/subgroups',
|
2017-05-19 21:22:46 +00:00
|
|
|
namespacesPath: '/api/:version/namespaces.json',
|
|
|
|
groupProjectsPath: '/api/:version/groups/:id/projects.json',
|
2017-09-04 15:41:55 +00:00
|
|
|
projectsPath: '/api/:version/projects.json',
|
2017-12-21 15:05:47 +00:00
|
|
|
projectPath: '/api/:version/projects/:id',
|
2019-06-19 10:21:48 +00:00
|
|
|
forkedProjectsPath: '/api/:version/projects/:id/forks',
|
2019-05-29 13:04:03 +00:00
|
|
|
projectLabelsPath: '/:namespace_path/:project_path/-/labels',
|
2019-03-01 16:33:18 +00:00
|
|
|
projectMergeRequestsPath: '/api/:version/projects/:id/merge_requests',
|
2018-11-28 15:09:38 +00:00
|
|
|
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',
|
2018-12-05 07:22:00 +00:00
|
|
|
projectRunnersPath: '/api/:version/projects/:id/runners',
|
2018-05-11 09:37:10 +00:00
|
|
|
mergeRequestsPath: '/api/:version/merge_requests',
|
2018-02-21 14:28:47 +00:00
|
|
|
groupLabelsPath: '/groups/:namespace_path/-/labels',
|
2017-05-19 21:22:46 +00:00
|
|
|
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
|
2018-10-02 23:00:38 +00:00
|
|
|
projectTemplatePath: '/api/:version/projects/:id/templates/:type/:key',
|
|
|
|
projectTemplatesPath: '/api/:version/projects/:id/templates/:type',
|
2019-07-09 08:44:19 +00:00
|
|
|
userCountsPath: '/api/:version/user_counts',
|
2017-05-19 21:22:46 +00:00
|
|
|
usersPath: '/api/:version/users.json',
|
2018-12-08 03:12:23 +00:00
|
|
|
userPath: '/api/:version/users/:id',
|
|
|
|
userStatusPath: '/api/:version/users/:id/status',
|
|
|
|
userPostStatusPath: '/api/:version/user/status',
|
2017-07-25 13:18:45 +00:00
|
|
|
commitPath: '/api/:version/projects/:id/repository/commits',
|
2018-12-13 19:17:19 +00:00
|
|
|
applySuggestionPath: '/api/:version/suggestions/:id/apply',
|
2018-05-25 10:08:53 +00:00
|
|
|
commitPipelinesPath: '/:project_id/commit/:sha/pipelines',
|
2017-10-12 21:04:17 +00:00
|
|
|
branchSinglePath: '/api/:version/projects/:id/repository/branches/:branch',
|
2017-10-26 10:14:31 +00:00
|
|
|
createBranchPath: '/api/:version/projects/:id/repository/branches',
|
2018-12-21 11:53:03 +00:00
|
|
|
releasesPath: '/api/:version/projects/:id/releases',
|
2017-05-19 21:22:46 +00:00
|
|
|
|
|
|
|
group(groupId, callback) {
|
2018-03-23 10:45:43 +00:00
|
|
|
const url = Api.buildUrl(Api.groupPath).replace(':id', groupId);
|
|
|
|
return axios.get(url).then(({ data }) => {
|
|
|
|
callback(data);
|
2018-01-29 10:12:32 +00:00
|
|
|
|
2018-03-23 10:45:43 +00:00
|
|
|
return data;
|
|
|
|
});
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2019-01-16 21:57:50 +00:00
|
|
|
groupMembers(id) {
|
|
|
|
const url = Api.buildUrl(this.groupMembersPath).replace(':id', encodeURIComponent(id));
|
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
// Return groups list. Filtered by query
|
2018-02-21 15:17:03 +00:00
|
|
|
groups(query, options, callback = $.noop) {
|
2017-05-19 21:22:46 +00:00
|
|
|
const url = Api.buildUrl(Api.groupsPath);
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: Object.assign(
|
|
|
|
{
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
},
|
|
|
|
options,
|
|
|
|
),
|
|
|
|
})
|
2018-01-29 11:42:27 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
// Return namespaces list. Filtered by query
|
2017-05-19 21:22:46 +00:00
|
|
|
namespaces(query, callback) {
|
|
|
|
const url = Api.buildUrl(Api.namespacesPath);
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
},
|
|
|
|
})
|
2018-01-25 16:40:31 +00:00
|
|
|
.then(({ data }) => callback(data));
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
// Return projects list. Filtered by query
|
2018-01-30 09:10:58 +00:00
|
|
|
projects(query, options, callback = _.noop) {
|
2017-05-19 21:22:46 +00:00
|
|
|
const url = Api.buildUrl(Api.projectsPath);
|
2017-08-22 15:10:49 +00:00
|
|
|
const defaults = {
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
2017-09-04 15:41:55 +00:00
|
|
|
simple: true,
|
2017-08-22 15:10:49 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (gon.current_user_id) {
|
|
|
|
defaults.membership = true;
|
|
|
|
}
|
|
|
|
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.get(url, {
|
|
|
|
params: Object.assign(defaults, options),
|
|
|
|
})
|
2018-01-29 11:42:27 +00:00
|
|
|
.then(({ data }) => {
|
|
|
|
callback(data);
|
|
|
|
|
|
|
|
return data;
|
|
|
|
});
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2017-12-21 15:05:47 +00:00
|
|
|
// Return single project
|
|
|
|
project(projectPath) {
|
2018-03-25 18:16:20 +00:00
|
|
|
const url = Api.buildUrl(Api.projectPath).replace(':id', encodeURIComponent(projectPath));
|
2018-03-23 10:45:43 +00:00
|
|
|
|
|
|
|
return axios.get(url);
|
2019-06-19 10:21:48 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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 });
|
2018-03-23 10:45:43 +00:00
|
|
|
},
|
|
|
|
|
2019-03-01 16:33:18 +00:00
|
|
|
/**
|
|
|
|
* Get all Merge Requests for a project, eventually filtering based on
|
|
|
|
* 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 });
|
|
|
|
},
|
|
|
|
|
2018-03-23 10:45:43 +00:00
|
|
|
// Return Merge Request for project
|
2018-11-28 15:09:38 +00:00
|
|
|
projectMergeRequest(projectPath, mergeRequestId, params = {}) {
|
|
|
|
const url = Api.buildUrl(Api.projectMergeRequestPath)
|
2018-03-23 10:45:43 +00:00
|
|
|
.replace(':id', encodeURIComponent(projectPath))
|
|
|
|
.replace(':mrid', mergeRequestId);
|
|
|
|
|
2018-07-03 08:09:20 +00:00
|
|
|
return axios.get(url, { params });
|
2018-03-23 10:45:43 +00:00
|
|
|
},
|
|
|
|
|
2018-11-28 15:09:38 +00:00
|
|
|
projectMergeRequestChanges(projectPath, mergeRequestId) {
|
|
|
|
const url = Api.buildUrl(Api.projectMergeRequestChangesPath)
|
2018-03-23 10:45:43 +00:00
|
|
|
.replace(':id', encodeURIComponent(projectPath))
|
|
|
|
.replace(':mrid', mergeRequestId);
|
2017-12-21 15:05:47 +00:00
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2018-11-28 15:09:38 +00:00
|
|
|
projectMergeRequestVersions(projectPath, mergeRequestId) {
|
|
|
|
const url = Api.buildUrl(Api.projectMergeRequestVersionsPath)
|
2018-03-25 12:02:09 +00:00
|
|
|
.replace(':id', encodeURIComponent(projectPath))
|
|
|
|
.replace(':mrid', mergeRequestId);
|
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2018-12-05 07:22:00 +00:00
|
|
|
projectRunners(projectPath, config = {}) {
|
|
|
|
const url = Api.buildUrl(Api.projectRunnersPath).replace(
|
|
|
|
':id',
|
|
|
|
encodeURIComponent(projectPath),
|
|
|
|
);
|
|
|
|
|
|
|
|
return axios.get(url, config);
|
|
|
|
},
|
|
|
|
|
2018-11-28 15:09:38 +00:00
|
|
|
mergeRequests(params = {}) {
|
|
|
|
const url = Api.buildUrl(Api.mergeRequestsPath);
|
|
|
|
|
|
|
|
return axios.get(url, { params });
|
|
|
|
},
|
|
|
|
|
2017-05-19 21:22:46 +00:00
|
|
|
newLabel(namespacePath, projectPath, data, callback) {
|
2017-09-06 14:17:06 +00:00
|
|
|
let url;
|
|
|
|
|
|
|
|
if (projectPath) {
|
|
|
|
url = Api.buildUrl(Api.projectLabelsPath)
|
|
|
|
.replace(':namespace_path', namespacePath)
|
|
|
|
.replace(':project_path', projectPath);
|
|
|
|
} else {
|
2018-03-25 18:16:20 +00:00
|
|
|
url = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespacePath);
|
2017-09-06 14:17:06 +00:00
|
|
|
}
|
|
|
|
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.post(url, {
|
|
|
|
label: data,
|
|
|
|
})
|
2018-01-25 16:40:31 +00:00
|
|
|
.then(res => callback(res.data))
|
|
|
|
.catch(e => callback(e.response.data));
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2017-03-11 07:30:44 +00:00
|
|
|
// Return group projects list. Filtered by query
|
2018-07-02 08:04:43 +00:00
|
|
|
groupProjects(groupId, query, options, callback) {
|
2018-03-23 10:45:43 +00:00
|
|
|
const url = Api.buildUrl(Api.groupProjectsPath).replace(':id', groupId);
|
2018-07-02 08:04:43 +00:00
|
|
|
const defaults = {
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
};
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.get(url, {
|
2018-07-02 08:04:43 +00:00
|
|
|
params: Object.assign({}, defaults, options),
|
2018-03-23 10:45:43 +00:00
|
|
|
})
|
2018-01-25 16:40:31 +00:00
|
|
|
.then(({ data }) => callback(data));
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2017-08-17 18:05:09 +00:00
|
|
|
commitMultiple(id, data) {
|
|
|
|
// see https://docs.gitlab.com/ce/api/commits.html#create-a-commit-with-multiple-files-and-actions
|
2018-03-25 18:16:20 +00:00
|
|
|
const url = Api.buildUrl(Api.commitPath).replace(':id', encodeURIComponent(id));
|
2018-01-25 16:40:31 +00:00
|
|
|
return axios.post(url, JSON.stringify(data), {
|
|
|
|
headers: {
|
|
|
|
'Content-Type': 'application/json; charset=utf-8',
|
|
|
|
},
|
2017-08-09 13:24:48 +00:00
|
|
|
});
|
2017-10-12 21:04:17 +00:00
|
|
|
},
|
|
|
|
|
2018-12-13 19:17:19 +00:00
|
|
|
applySuggestion(id) {
|
|
|
|
const url = Api.buildUrl(Api.applySuggestionPath).replace(':id', encodeURIComponent(id));
|
|
|
|
|
|
|
|
return axios.put(url);
|
|
|
|
},
|
|
|
|
|
2018-05-25 10:08:53 +00:00
|
|
|
commitPipelines(projectId, sha) {
|
|
|
|
const encodedProjectId = projectId
|
|
|
|
.split('/')
|
|
|
|
.map(fragment => encodeURIComponent(fragment))
|
|
|
|
.join('/');
|
|
|
|
|
|
|
|
const url = Api.buildUrl(Api.commitPipelinesPath)
|
|
|
|
.replace(':project_id', encodedProjectId)
|
|
|
|
.replace(':sha', encodeURIComponent(sha));
|
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2017-10-12 21:04:17 +00:00
|
|
|
branchSingle(id, branch) {
|
|
|
|
const url = Api.buildUrl(Api.branchSinglePath)
|
2017-12-21 15:05:47 +00:00
|
|
|
.replace(':id', encodeURIComponent(id))
|
2018-03-23 10:45:43 +00:00
|
|
|
.replace(':branch', encodeURIComponent(branch));
|
2017-10-12 21:04:17 +00:00
|
|
|
|
2018-01-25 16:40:31 +00:00
|
|
|
return axios.get(url);
|
2017-07-25 13:18:45 +00:00
|
|
|
},
|
|
|
|
|
2018-10-02 23:00:38 +00:00
|
|
|
projectTemplate(id, type, key, options, callback) {
|
|
|
|
const url = Api.buildUrl(this.projectTemplatePath)
|
|
|
|
.replace(':id', encodeURIComponent(id))
|
|
|
|
.replace(':type', type)
|
|
|
|
.replace(':key', encodeURIComponent(key));
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2018-10-02 23:00:38 +00:00
|
|
|
return axios.get(url, { params: options }).then(res => {
|
|
|
|
if (callback) callback(res.data);
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2018-10-02 23:00:38 +00:00
|
|
|
return res;
|
|
|
|
});
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
2018-10-02 23:00:38 +00:00
|
|
|
projectTemplates(id, type, params = {}, callback) {
|
|
|
|
const url = Api.buildUrl(this.projectTemplatesPath)
|
|
|
|
.replace(':id', encodeURIComponent(id))
|
|
|
|
.replace(':type', type);
|
|
|
|
|
|
|
|
return axios.get(url, { params }).then(res => {
|
|
|
|
if (callback) callback(res.data);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
});
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
|
|
|
issueTemplate(namespacePath, projectPath, key, type, callback) {
|
|
|
|
const url = Api.buildUrl(Api.issuableTemplatePath)
|
2017-11-10 15:02:42 +00:00
|
|
|
.replace(':key', encodeURIComponent(key))
|
2017-03-11 07:30:44 +00:00
|
|
|
.replace(':type', type)
|
|
|
|
.replace(':project_path', projectPath)
|
|
|
|
.replace(':namespace_path', namespacePath);
|
2018-03-23 10:45:43 +00:00
|
|
|
return axios
|
|
|
|
.get(url)
|
2018-01-25 16:40:31 +00:00
|
|
|
.then(({ data }) => callback(null, data))
|
|
|
|
.catch(callback);
|
2017-03-11 07:30:44 +00:00
|
|
|
},
|
2017-05-19 21:22:46 +00:00
|
|
|
|
|
|
|
users(query, options) {
|
|
|
|
const url = Api.buildUrl(this.usersPath);
|
2018-01-25 16:40:31 +00:00
|
|
|
return axios.get(url, {
|
2018-03-23 10:45:43 +00:00
|
|
|
params: Object.assign(
|
|
|
|
{
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
},
|
|
|
|
options,
|
|
|
|
),
|
2017-05-19 21:22:46 +00:00
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-12-08 03:12:23 +00:00
|
|
|
user(id, options) {
|
|
|
|
const url = Api.buildUrl(this.userPath).replace(':id', encodeURIComponent(id));
|
|
|
|
return axios.get(url, {
|
|
|
|
params: options,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2019-07-09 08:44:19 +00:00
|
|
|
userCounts() {
|
|
|
|
const url = Api.buildUrl(this.userCountsPath);
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2018-12-08 03:12:23 +00:00
|
|
|
userStatus(id, options) {
|
|
|
|
const url = Api.buildUrl(this.userStatusPath).replace(':id', encodeURIComponent(id));
|
|
|
|
return axios.get(url, {
|
|
|
|
params: options,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-08-07 15:15:56 +00:00
|
|
|
branches(id, query = '', options = {}) {
|
|
|
|
const url = Api.buildUrl(this.createBranchPath).replace(':id', encodeURIComponent(id));
|
|
|
|
|
|
|
|
return axios.get(url, {
|
|
|
|
params: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
...options,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-06-14 17:03:17 +00:00
|
|
|
createBranch(id, { ref, branch }) {
|
|
|
|
const url = Api.buildUrl(this.createBranchPath).replace(':id', encodeURIComponent(id));
|
|
|
|
|
|
|
|
return axios.post(url, {
|
|
|
|
ref,
|
|
|
|
branch,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-10-04 08:19:51 +00:00
|
|
|
postUserStatus({ emoji, message }) {
|
2018-12-08 03:12:23 +00:00
|
|
|
const url = Api.buildUrl(this.userPostStatusPath);
|
2018-10-04 08:19:51 +00:00
|
|
|
|
|
|
|
return axios.put(url, {
|
|
|
|
emoji,
|
|
|
|
message,
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2018-12-20 09:31:32 +00:00
|
|
|
releases(id) {
|
|
|
|
const url = Api.buildUrl(this.releasesPath).replace(':id', encodeURIComponent(id));
|
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
2017-05-19 21:22:46 +00:00
|
|
|
buildUrl(url) {
|
2019-04-24 17:30:46 +00:00
|
|
|
return joinPaths(gon.relative_url_root || '', url.replace(':version', gon.api_version));
|
2017-05-19 21:22:46 +00:00
|
|
|
},
|
2017-03-11 07:30:44 +00:00
|
|
|
};
|
2016-07-24 20:45:11 +00:00
|
|
|
|
2017-05-19 21:22:46 +00:00
|
|
|
export default Api;
|