1
1
package org .gitlab4j .api ;
2
2
3
- import java . util . List ;
3
+ import org . gitlab4j . api . models . Label ;
4
4
5
5
import javax .ws .rs .core .GenericType ;
6
6
import javax .ws .rs .core .Response ;
7
-
8
- import org .gitlab4j .api .models .Label ;
7
+ import java .util .List ;
9
8
10
9
public class LabelsApi extends AbstractApi {
11
10
12
11
public LabelsApi (GitLabApi gitLabApi ) {
13
12
super (gitLabApi );
14
13
}
15
14
15
+ /**
16
+ * Get all labels of the specified project. Only returns the first page
17
+ *
18
+ * @param projectId the project ID to get the labels for
19
+ * @return a list of project's labels
20
+ * @throws GitLabApiException if any exception occurs
21
+ */
16
22
public List <Label > getLabels (Integer projectId ) throws GitLabApiException {
17
23
return (getLabels (projectId , 1 , getDefaultPerPage ()));
18
24
}
19
25
26
+ /**
27
+ * Get all labels of the specified project to using the specified page and per page setting
28
+ *
29
+ * @param projectId the project ID to get the labels for
30
+ * @param page the page to get
31
+ * @param perPage the number of issues per page
32
+ * @return a list of project's labels in the specified range
33
+ * @throws GitLabApiException if any exception occurs
34
+ */
20
35
public List <Label > getLabels (Integer projectId , int page , int perPage ) throws GitLabApiException {
21
36
22
37
if (projectId == null ) {
23
38
throw new RuntimeException ("projectId cannot be null" );
24
39
}
25
40
26
- Response response = get (javax .ws .rs .core .Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , projectId , "labels" );
41
+ Response response = get (javax .ws .rs .core .Response .Status .OK , getPageQueryParams (page , perPage ), "projects" , projectId , "labels" );
27
42
return (response .readEntity (new GenericType <List <Label >>() {}));
28
43
}
29
44
45
+ /**
46
+ * Create a label
47
+ *
48
+ * @param projectId the project ID to create a label for
49
+ * @param name the name for the label
50
+ * @param color the color for the label
51
+ * @param description the description for the label
52
+ * @return the created Label instance
53
+ * @throws GitLabApiException if any exception occurs
54
+ */
30
55
public Label createLabel (Integer projectId , String name , String color , String description ) throws GitLabApiException {
31
56
return (createLabel (projectId , name , color , description , null ));
32
57
}
33
58
59
+ /**
60
+ * Create a label
61
+ *
62
+ * @param projectId the project ID to create a label for
63
+ * @param name the name for the label
64
+ * @param color the color for the label
65
+ * @return the created Label instance
66
+ * @throws GitLabApiException if any exception occurs
67
+ */
34
68
public Label createLabel (Integer projectId , String name , String color ) throws GitLabApiException {
35
69
return (createLabel (projectId , name , color , null , null ));
36
70
}
37
71
72
+ /**
73
+ * Create a label
74
+ *
75
+ * @param projectId the project ID to create a label for
76
+ * @param name the name for the label
77
+ * @param color the color for the label
78
+ * @param priority the priority for the label
79
+ * @return the created Label instance
80
+ * @throws GitLabApiException if any exception occurs
81
+ */
38
82
public Label createLabel (Integer projectId , String name , String color , Integer priority ) throws GitLabApiException {
39
83
return (createLabel (projectId , name , color , null , priority ));
40
84
}
41
85
86
+ /**
87
+ * Create a label
88
+ *
89
+ * @param projectId the project ID to create a label for
90
+ * @param name the name for the label
91
+ * @param color the color for the label
92
+ * @param description the description for the label
93
+ * @param priority the priority for the label
94
+ * @return the created Label instance
95
+ * @throws GitLabApiException if any exception occurs
96
+ */
42
97
public Label createLabel (Integer projectId , String name , String color , String description , Integer priority ) throws GitLabApiException {
43
98
44
- if (projectId == null ) {
99
+ if (projectId == null ) {
45
100
throw new RuntimeException ("projectId cannot be null" );
46
101
}
47
102
48
- GitLabApiForm formData = new GitLabApiForm ()
103
+ GitLabApiForm formData = new GitLabApiForm ()
49
104
.withParam ("name" , name , true )
50
105
.withParam ("color" , color , true )
51
106
.withParam ("description" , description )
52
107
.withParam ("priority" , priority );
53
- Response response = post (Response .Status .OK , formData , "projects" , projectId , "labels" );
108
+ Response response = post (Response .Status .CREATED , formData , "projects" , projectId , "labels" );
54
109
return (response .readEntity (Label .class ));
55
110
}
56
111
112
+
113
+ /**
114
+ * Update the specified label
115
+ *
116
+ * @param projectId the project ID to update a label for
117
+ * @param name the name for the label
118
+ * @param newName the new name for the label
119
+ * @param description the description for the label
120
+ * @param priority the priority for the label
121
+ * @return the modified Label instance
122
+ * @throws GitLabApiException if any exception occurs
123
+ */
57
124
public Label updateLabelName (Integer projectId , String name , String newName , String description , Integer priority ) throws GitLabApiException {
58
125
return (updateLabel (projectId , name , newName , null , description , priority ));
59
126
}
60
127
128
+
129
+ /**
130
+ * Update the specified label
131
+ *
132
+ * @param projectId the project ID to update a label for
133
+ * @param name the name for the label
134
+ * @param color the color for the label
135
+ * @param description the description for the label
136
+ * @param priority the priority for the label
137
+ * @return the modified Label instance
138
+ * @throws GitLabApiException if any exception occurs
139
+ */
61
140
public Label updateLabelColor (Integer projectId , String name , String color , String description , Integer priority ) throws GitLabApiException {
62
141
return (updateLabel (projectId , name , null , color , description , priority ));
63
142
}
64
143
144
+ /**
145
+ * Update the specified label
146
+ *
147
+ * @param projectId the project ID to update a label for
148
+ * @param name the name for the label
149
+ * @param newName the new name for the label
150
+ * @param color the color for the label
151
+ * @param description the description for the label
152
+ * @param priority the priority for the label
153
+ * @return the modified Label instance
154
+ * @throws GitLabApiException if any exception occurs
155
+ */
65
156
public Label updateLabel (Integer projectId , String name , String newName , String color , String description , Integer priority ) throws GitLabApiException {
66
157
67
158
if (projectId == null ) {
@@ -78,6 +169,13 @@ public Label updateLabel(Integer projectId, String name, String newName, String
78
169
return (response .readEntity (Label .class ));
79
170
}
80
171
172
+ /**
173
+ * Delete the specified label
174
+ *
175
+ * @param projectId the project ID to delete a label for
176
+ * @param name the name for the label
177
+ * @throws GitLabApiException if any exception occurs
178
+ */
81
179
public void deleteLabel (Integer projectId , String name ) throws GitLabApiException {
82
180
83
181
if (projectId == null ) {
@@ -90,11 +188,28 @@ public void deleteLabel(Integer projectId, String name) throws GitLabApiExceptio
90
188
delete (expectedStatus , formData .asMap (), "projects" , projectId , "labels" );
91
189
}
92
190
191
+ /**
192
+ * Subscribe a specified label
193
+ *
194
+ * @param projectId the project ID to subscribe a label for
195
+ * @param labelId the lable ID
196
+ * @return HttpStatusCode 503
197
+ * @throws GitLabApiException if any exception occurs
198
+ */
93
199
public Label subscribeLabel (Integer projectId , Integer labelId ) throws GitLabApiException {
94
200
Response response = post (Response .Status .NOT_MODIFIED , getDefaultPerPageParam (), "projects" , projectId , "labels" , labelId , "subscribe" );
95
201
return (response .readEntity (Label .class ));
96
202
}
97
203
204
+
205
+ /**
206
+ * Unsubscribe a specified label
207
+ *
208
+ * @param projectId the project ID to unsubscribe a label for
209
+ * @param labelId the lable ID
210
+ * @return HttpStatusCode 503
211
+ * @throws GitLabApiException if any exception occurs
212
+ */
98
213
public Label unsubscribeLabel (Integer projectId , Integer labelId ) throws GitLabApiException {
99
214
Response response = post (Response .Status .NOT_MODIFIED , getDefaultPerPageParam (), "projects" , projectId , "labels" , labelId , "unsubscribe" );
100
215
return (response .readEntity (Label .class ));
0 commit comments