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