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',
|
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-02-21 09:28:47 -05:00
|
|
|
groupLabelsPath: '/groups/:namespace_path/-/labels',
|
2017-05-19 17:22:46 -04:00
|
|
|
licensePath: '/api/:version/templates/licenses/:key',
|
|
|
|
gitignorePath: '/api/:version/templates/gitignores/:key',
|
|
|
|
gitlabCiYmlPath: '/api/:version/templates/gitlab_ci_ymls/:key',
|
|
|
|
dockerfilePath: '/api/:version/templates/dockerfiles/:key',
|
|
|
|
issuableTemplatePath: '/:namespace_path/:project_path/templates/:type/:key',
|
|
|
|
usersPath: '/api/:version/users.json',
|
2017-07-25 09:18:45 -04:00
|
|
|
commitPath: '/api/:version/projects/:id/repository/commits',
|
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',
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
group(groupId, callback) {
|
|
|
|
const url = Api.buildUrl(Api.groupPath)
|
|
|
|
.replace(':id', groupId);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url)
|
2018-01-29 05:12:32 -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 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-01-25 11:40:31 -05:00
|
|
|
return axios.get(url, {
|
|
|
|
params: Object.assign({
|
2017-03-11 02:30:44 -05:00
|
|
|
search: query,
|
2017-05-19 17:22:46 -04:00
|
|
|
per_page: 20,
|
2017-03-11 02:30:44 -05:00
|
|
|
}, options),
|
2017-05-19 17:22:46 -04:00
|
|
|
})
|
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-01-25 11:40:31 -05:00
|
|
|
return axios.get(url, {
|
|
|
|
params: {
|
2017-03-11 02:30:44 -05:00
|
|
|
search: query,
|
2017-05-19 17:22:46 -04:00
|
|
|
per_page: 20,
|
2017-03-11 02:30:44 -05: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-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-01-25 11:40:31 -05:00
|
|
|
return axios.get(url, {
|
|
|
|
params: Object.assign(defaults, options),
|
2017-05-19 17:22:46 -04:00
|
|
|
})
|
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) {
|
|
|
|
const url = Api.buildUrl(Api.projectPath)
|
|
|
|
.replace(':id', encodeURIComponent(projectPath));
|
|
|
|
|
|
|
|
return axios.get(url);
|
|
|
|
},
|
|
|
|
|
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 {
|
|
|
|
url = Api.buildUrl(Api.groupLabelsPath).replace(':namespace_path', namespacePath);
|
|
|
|
}
|
|
|
|
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.post(url, {
|
|
|
|
label: data,
|
2017-05-19 17:22:46 -04:00
|
|
|
})
|
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
|
2017-05-19 17:22:46 -04:00
|
|
|
groupProjects(groupId, query, callback) {
|
|
|
|
const url = Api.buildUrl(Api.groupProjectsPath)
|
|
|
|
.replace(':id', groupId);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url, {
|
|
|
|
params: {
|
2017-03-11 02:30:44 -05:00
|
|
|
search: query,
|
2017-05-19 17:22:46 -04:00
|
|
|
per_page: 20,
|
2017-03-11 02:30:44 -05:00
|
|
|
},
|
2017-05-19 17:22:46 -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
|
2017-07-25 09:18:45 -04:00
|
|
|
const url = Api.buildUrl(Api.commitPath)
|
2017-12-21 10:05:47 -05:00
|
|
|
.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
|
|
|
},
|
|
|
|
|
|
|
|
branchSingle(id, branch) {
|
|
|
|
const url = Api.buildUrl(Api.branchSinglePath)
|
2017-12-21 10:05:47 -05:00
|
|
|
.replace(':id', encodeURIComponent(id))
|
2017-10-12 17:04:17 -04:00
|
|
|
.replace(':branch', branch);
|
|
|
|
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url);
|
2017-07-25 09:18:45 -04:00
|
|
|
},
|
|
|
|
|
2017-03-11 02:30:44 -05:00
|
|
|
// Return text for a specific license
|
2017-05-19 17:22:46 -04:00
|
|
|
licenseText(key, data, callback) {
|
|
|
|
const url = Api.buildUrl(Api.licensePath)
|
2017-03-11 02:30:44 -05:00
|
|
|
.replace(':key', key);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url, {
|
|
|
|
params: data,
|
2017-05-19 17:22:46 -04:00
|
|
|
})
|
2018-01-25 11:40:31 -05:00
|
|
|
.then(res => callback(res.data));
|
2017-03-11 02:30:44 -05:00
|
|
|
},
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
gitignoreText(key, callback) {
|
|
|
|
const url = Api.buildUrl(Api.gitignorePath)
|
2017-03-11 02:30:44 -05:00
|
|
|
.replace(':key', key);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url)
|
|
|
|
.then(({ data }) => callback(data));
|
2017-03-11 02:30:44 -05:00
|
|
|
},
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
gitlabCiYml(key, callback) {
|
|
|
|
const url = Api.buildUrl(Api.gitlabCiYmlPath)
|
2017-03-11 02:30:44 -05:00
|
|
|
.replace(':key', key);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url)
|
|
|
|
.then(({ data }) => callback(data));
|
2017-03-11 02:30:44 -05:00
|
|
|
},
|
2017-05-19 17:22:46 -04:00
|
|
|
|
|
|
|
dockerfileYml(key, callback) {
|
|
|
|
const url = Api.buildUrl(Api.dockerfilePath).replace(':key', key);
|
2018-01-25 11:40:31 -05:00
|
|
|
return axios.get(url)
|
|
|
|
.then(({ data }) => callback(data));
|
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-01-25 11:40:31 -05:00
|
|
|
return axios.get(url)
|
|
|
|
.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, {
|
|
|
|
params: Object.assign({
|
2017-05-19 17:22:46 -04:00
|
|
|
search: query,
|
|
|
|
per_page: 20,
|
|
|
|
}, options),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|