2013-03-20 15:55:25 -04:00
|
|
|
@Api =
|
2014-12-30 04:32:24 -05:00
|
|
|
groups_path: "/api/:version/groups.json"
|
|
|
|
group_path: "/api/:version/groups/:id.json"
|
2013-11-15 08:25:09 -05:00
|
|
|
namespaces_path: "/api/:version/namespaces.json"
|
2015-12-07 11:12:04 -05:00
|
|
|
group_projects_path: "/api/:version/groups/:id/projects.json"
|
|
|
|
projects_path: "/api/:version/projects.json"
|
2016-03-07 12:17:11 -05:00
|
|
|
labels_path: "/api/:version/projects/:id/labels"
|
2016-03-01 07:36:50 -05:00
|
|
|
license_path: "/api/:version/licenses/:key"
|
2016-05-06 11:13:16 -04:00
|
|
|
gitignoretext_path: "/api/:version/gitignores/:key"
|
2013-03-20 15:55:25 -04:00
|
|
|
|
2014-12-30 04:32:24 -05:00
|
|
|
group: (group_id, callback) ->
|
|
|
|
url = Api.buildUrl(Api.group_path)
|
|
|
|
url = url.replace(':id', group_id)
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
data:
|
|
|
|
private_token: gon.api_token
|
|
|
|
dataType: "json"
|
|
|
|
).done (group) ->
|
|
|
|
callback(group)
|
|
|
|
|
|
|
|
# Return groups list. Filtered by query
|
|
|
|
# Only active groups retrieved
|
|
|
|
groups: (query, skip_ldap, callback) ->
|
|
|
|
url = Api.buildUrl(Api.groups_path)
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
data:
|
|
|
|
private_token: gon.api_token
|
|
|
|
search: query
|
|
|
|
per_page: 20
|
|
|
|
dataType: "json"
|
|
|
|
).done (groups) ->
|
|
|
|
callback(groups)
|
|
|
|
|
2013-11-15 08:25:09 -05:00
|
|
|
# Return namespaces list. Filtered by query
|
|
|
|
namespaces: (query, callback) ->
|
|
|
|
url = Api.buildUrl(Api.namespaces_path)
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
data:
|
|
|
|
private_token: gon.api_token
|
|
|
|
search: query
|
|
|
|
per_page: 20
|
|
|
|
dataType: "json"
|
|
|
|
).done (namespaces) ->
|
|
|
|
callback(namespaces)
|
|
|
|
|
2015-12-07 11:12:04 -05:00
|
|
|
# Return projects list. Filtered by query
|
2016-02-03 17:27:00 -05:00
|
|
|
projects: (query, order, callback) ->
|
2015-12-07 11:12:04 -05:00
|
|
|
url = Api.buildUrl(Api.projects_path)
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
data:
|
|
|
|
private_token: gon.api_token
|
|
|
|
search: query
|
2016-02-03 17:27:00 -05:00
|
|
|
order_by: order
|
2015-12-07 11:12:04 -05:00
|
|
|
per_page: 20
|
|
|
|
dataType: "json"
|
|
|
|
).done (projects) ->
|
|
|
|
callback(projects)
|
|
|
|
|
2016-03-08 06:23:54 -05:00
|
|
|
newLabel: (project_id, data, callback) ->
|
|
|
|
url = Api.buildUrl(Api.labels_path)
|
|
|
|
url = url.replace(':id', project_id)
|
|
|
|
|
|
|
|
data.private_token = gon.api_token
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
type: "POST"
|
|
|
|
data: data
|
|
|
|
dataType: "json"
|
|
|
|
).done (label) ->
|
|
|
|
callback(label)
|
2016-03-22 10:56:00 -04:00
|
|
|
.error (message) ->
|
|
|
|
callback(message.responseJSON)
|
2016-03-08 06:23:54 -05:00
|
|
|
|
2015-12-07 11:12:04 -05:00
|
|
|
# Return group projects list. Filtered by query
|
|
|
|
groupProjects: (group_id, query, callback) ->
|
|
|
|
url = Api.buildUrl(Api.group_projects_path)
|
|
|
|
url = url.replace(':id', group_id)
|
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
|
|
|
data:
|
|
|
|
private_token: gon.api_token
|
|
|
|
search: query
|
|
|
|
per_page: 20
|
|
|
|
dataType: "json"
|
|
|
|
).done (projects) ->
|
|
|
|
callback(projects)
|
|
|
|
|
2016-04-11 09:49:25 -04:00
|
|
|
# Return text for a specific license
|
|
|
|
licenseText: (key, data, callback) ->
|
|
|
|
url = Api.buildUrl(Api.license_path).replace(':key', key)
|
2016-03-01 07:36:50 -05:00
|
|
|
|
|
|
|
$.ajax(
|
|
|
|
url: url
|
2016-04-11 09:49:25 -04:00
|
|
|
data: data
|
|
|
|
).done (license) ->
|
|
|
|
callback(license)
|
2016-03-01 07:36:50 -05:00
|
|
|
|
2016-05-06 11:13:16 -04:00
|
|
|
gitIgnoreText: (key, callback) ->
|
|
|
|
url = Api.buildUrl(Api.gitignoretext_path).replace(':key', key)
|
|
|
|
|
|
|
|
$.get url, (gitignore) ->
|
|
|
|
callback(gitignore)
|
|
|
|
|
2013-03-20 15:55:25 -04:00
|
|
|
buildUrl: (url) ->
|
2013-06-12 23:44:25 -04:00
|
|
|
url = gon.relative_url_root + url if gon.relative_url_root?
|
2013-03-20 15:55:25 -04:00
|
|
|
return url.replace(':version', gon.api_version)
|