1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
|
(() => {
var 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',
issuePath: '/api/:version/project/:id/issue_templates/:key?private_token=:token',
group: function group(groupId, callback) {
return $.ajax({
url: Api.buildUrl(Api.groupPath).replace(':id', groupId),
dataType: 'json',
data: {
private_token: gon.api_token
}
}).done((group) => {
return callback(group);
});
},
groups: function groups(query, skip_ldap, callback) {
return $.ajax({
url: Api.buildUrl(Api.groupsPath),
dataType: 'json',
data: {
private_token: gon.api_token,
search: query,
per_page: 20
}
}).done((groups) => {
return callback(groups);
});
},
namespaces: function namespaces(query, callback) {
return $.ajax({
url: Api.buildUrl(Api.namespacesPath),
dataType: 'json',
data: {
private_token: gon.api_token,
search: query,
per_page: 20
}
}).done((namespaces) => {
return callback(namespaces);
});
},
projects: function projects(query, order, callback) {
return $.ajax({
url: Api.buildUrl(Api.projectsPath),
dataType: 'json',
data: {
private_token: gon.api_token,
search: query,
order_by: order,
per_page: 20
}
}).done((projects) => {
return callback(projects);
});
},
newLabel: function newLabel(projectId, data, callback) {
return $.ajax({
url: Api.buildUrl(Api.labelsPath).replace(':id', projectId),
type: 'POST',
dataType: 'json',
data: {
private_token: gon.api_token
}
}).done((label) => {
return callback(label);
}).error((message) => {
return callback(message.responseJSON);
});
},
groupProjects: function groupProjects(groupId, query, callback) {
return $.ajax({
url: Api.buildUrl(Api.groupProjectsPath).replace(':id', groupId),
dataType: 'json',
data: {
private_token: gon.api_token,
search: query,
per_page: 20
}
}).done((projects) => {
return callback(projects);
});
},
licenseText: function licenseText(key, data, callback) {
return $.ajax({
url: Api.buildUrl(Api.licensePath).replace(':key', key),
data: data
}).done((license) => {
return callback(license);
});
},
gitignoreText: function gitignoreText(key, callback) {
let url = Api.buildUrl(Api.gitignorePath).replace(':key', key);
return $.get(url, (gitignore) => {
return callback(gitignore);
});
},
gitlabCiYml: function gitlabCiYml(key, callback) {
let url = Api.buildUrl(Api.gitlabCiYmlPath).replace(':key', key);
return $.get(url, (file) => {
return callback(file);
});
},
buildUrl: function buildUrl(url) {
if (gon.relative_url_root) url = gon.relative_url_root + url;
return url.replace(':version', gon.api_version);
}
};
})();
|