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

145 lines
4.3 KiB
JavaScript
Raw Normal View History

2016-09-13 17:45:13 +05:30
(function() {
this.Api = {
groupsPath: "/api/:version/groups.json",
groupPath: "/api/:version/groups/:id.json",
namespacesPath: "/api/:version/namespaces.json",
groupProjectsPath: "/api/:version/groups/:id/projects.json",
projectsPath: "/api/:version/projects.json?simple=true",
2016-10-01 15:18:49 +05:30
labelsPath: "/:namespace_path/:project_path/labels",
2016-11-03 12:29:30 +05:30
licensePath: "/api/:version/templates/licenses/:key",
gitignorePath: "/api/:version/templates/gitignores/:key",
gitlabCiYmlPath: "/api/:version/templates/gitlab_ci_ymls/:key",
2016-09-13 17:45:13 +05:30
issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key",
group: function(group_id, callback) {
var url = Api.buildUrl(Api.groupPath)
.replace(':id', group_id);
return $.ajax({
url: url,
dataType: "json"
}).done(function(group) {
return callback(group);
});
},
2016-09-29 09:46:39 +05:30
// Return groups list. Filtered by query
// Only active groups retrieved
2016-11-03 12:29:30 +05:30
groups: function(query, skip_ldap, skip_groups, callback) {
2016-09-13 17:45:13 +05:30
var url = Api.buildUrl(Api.groupsPath);
return $.ajax({
url: url,
data: {
search: query,
2016-11-03 12:29:30 +05:30
skip_groups: skip_groups,
2016-09-13 17:45:13 +05:30
per_page: 20
},
dataType: "json"
}).done(function(groups) {
return callback(groups);
});
},
2016-09-29 09:46:39 +05:30
// Return namespaces list. Filtered by query
2016-09-13 17:45:13 +05:30
namespaces: function(query, callback) {
var url = Api.buildUrl(Api.namespacesPath);
return $.ajax({
url: url,
data: {
search: query,
per_page: 20
},
dataType: "json"
}).done(function(namespaces) {
return callback(namespaces);
});
},
2016-09-29 09:46:39 +05:30
// Return projects list. Filtered by query
2016-09-13 17:45:13 +05:30
projects: function(query, order, callback) {
var url = Api.buildUrl(Api.projectsPath);
return $.ajax({
url: url,
data: {
search: query,
order_by: order,
per_page: 20
},
dataType: "json"
}).done(function(projects) {
return callback(projects);
});
},
2016-10-01 15:18:49 +05:30
newLabel: function(namespace_path, project_path, data, callback) {
2016-09-13 17:45:13 +05:30
var url = Api.buildUrl(Api.labelsPath)
2016-10-01 15:18:49 +05:30
.replace(':namespace_path', namespace_path)
.replace(':project_path', project_path);
2016-09-13 17:45:13 +05:30
return $.ajax({
url: url,
type: "POST",
2016-10-01 15:18:49 +05:30
data: {'label': data},
2016-09-13 17:45:13 +05:30
dataType: "json"
}).done(function(label) {
return callback(label);
}).error(function(message) {
return callback(message.responseJSON);
});
},
2016-09-29 09:46:39 +05:30
// Return group projects list. Filtered by query
2016-09-13 17:45:13 +05:30
groupProjects: function(group_id, query, callback) {
var url = Api.buildUrl(Api.groupProjectsPath)
.replace(':id', group_id);
return $.ajax({
url: url,
data: {
search: query,
per_page: 20
},
dataType: "json"
}).done(function(projects) {
return callback(projects);
});
},
2016-09-29 09:46:39 +05:30
// Return text for a specific license
2016-09-13 17:45:13 +05:30
licenseText: function(key, data, callback) {
var url = Api.buildUrl(Api.licensePath)
.replace(':key', key);
return $.ajax({
url: url,
data: data
}).done(function(license) {
return callback(license);
});
},
gitignoreText: function(key, callback) {
var url = Api.buildUrl(Api.gitignorePath)
.replace(':key', key);
return $.get(url, function(gitignore) {
return callback(gitignore);
});
},
gitlabCiYml: function(key, callback) {
var url = Api.buildUrl(Api.gitlabCiYmlPath)
.replace(':key', key);
return $.get(url, function(file) {
return callback(file);
});
},
issueTemplate: function(namespacePath, projectPath, key, type, callback) {
var url = Api.buildUrl(Api.issuableTemplatePath)
.replace(':key', key)
.replace(':type', type)
.replace(':project_path', projectPath)
.replace(':namespace_path', namespacePath);
$.ajax({
url: url,
dataType: 'json'
}).done(function(file) {
callback(null, file);
}).error(callback);
},
buildUrl: function(url) {
if (gon.relative_url_root != null) {
url = gon.relative_url_root + url;
}
return url.replace(':version', gon.api_version);
}
};
}).call(this);