2016-07-24 16:45:11 -04:00
|
|
|
(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",
|
|
|
|
labelsPath: "/api/:version/projects/:id/labels",
|
|
|
|
licensePath: "/api/:version/licenses/:key",
|
|
|
|
gitignorePath: "/api/:version/gitignores/:key",
|
|
|
|
gitlabCiYmlPath: "/api/:version/gitlab_ci_ymls/:key",
|
2016-06-24 15:43:46 -04:00
|
|
|
issuableTemplatePath: "/:namespace_path/:project_path/templates/:type/:key",
|
|
|
|
|
2016-07-24 16:45:11 -04:00
|
|
|
group: function(group_id, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.groupPath)
|
|
|
|
.replace(':id', group_id);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(group) {
|
|
|
|
return callback(group);
|
|
|
|
});
|
|
|
|
},
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return groups list. Filtered by query
|
|
|
|
// Only active groups retrieved
|
2016-07-24 16:45:11 -04:00
|
|
|
groups: function(query, skip_ldap, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.groupsPath);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(groups) {
|
|
|
|
return callback(groups);
|
|
|
|
});
|
|
|
|
},
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return namespaces list. Filtered by query
|
2016-07-24 16:45:11 -04:00
|
|
|
namespaces: function(query, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.namespacesPath);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(namespaces) {
|
|
|
|
return callback(namespaces);
|
|
|
|
});
|
|
|
|
},
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return projects list. Filtered by query
|
2016-07-24 16:45:11 -04:00
|
|
|
projects: function(query, order, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.projectsPath);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
search: query,
|
|
|
|
order_by: order,
|
|
|
|
per_page: 20
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(projects) {
|
|
|
|
return callback(projects);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
newLabel: function(project_id, data, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.labelsPath)
|
|
|
|
.replace(':id', project_id);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
type: "POST",
|
|
|
|
data: data,
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(label) {
|
|
|
|
return callback(label);
|
|
|
|
}).error(function(message) {
|
|
|
|
return callback(message.responseJSON);
|
|
|
|
});
|
|
|
|
},
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return group projects list. Filtered by query
|
2016-07-24 16:45:11 -04:00
|
|
|
groupProjects: function(group_id, query, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.groupProjectsPath)
|
|
|
|
.replace(':id', group_id);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: {
|
|
|
|
search: query,
|
|
|
|
per_page: 20
|
|
|
|
},
|
|
|
|
dataType: "json"
|
|
|
|
}).done(function(projects) {
|
|
|
|
return callback(projects);
|
|
|
|
});
|
|
|
|
},
|
2016-07-26 23:32:10 -04:00
|
|
|
// Return text for a specific license
|
2016-07-24 16:45:11 -04:00
|
|
|
licenseText: function(key, data, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.licensePath)
|
|
|
|
.replace(':key', key);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.ajax({
|
|
|
|
url: url,
|
|
|
|
data: data
|
|
|
|
}).done(function(license) {
|
|
|
|
return callback(license);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
gitignoreText: function(key, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.gitignorePath)
|
|
|
|
.replace(':key', key);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.get(url, function(gitignore) {
|
|
|
|
return callback(gitignore);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
gitlabCiYml: function(key, callback) {
|
2016-06-24 15:43:46 -04:00
|
|
|
var url = Api.buildUrl(Api.gitlabCiYmlPath)
|
|
|
|
.replace(':key', key);
|
2016-07-24 16:45:11 -04:00
|
|
|
return $.get(url, function(file) {
|
|
|
|
return callback(file);
|
|
|
|
});
|
|
|
|
},
|
2016-06-24 15:43:46 -04:00
|
|
|
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);
|
|
|
|
},
|
2016-07-24 16:45:11 -04:00
|
|
|
buildUrl: function(url) {
|
|
|
|
if (gon.relative_url_root != null) {
|
|
|
|
url = gon.relative_url_root + url;
|
|
|
|
}
|
|
|
|
return url.replace(':version', gon.api_version);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}).call(this);
|