11package org .gitlab4j .api ;
22
3- import java . util . List ;
3+ import org . gitlab4j . api . models . Label ;
44
55import javax .ws .rs .core .GenericType ;
66import javax .ws .rs .core .Response ;
7-
8- import org .gitlab4j .api .models .Label ;
7+ import java .util .List ;
98
109public class LabelsApi extends AbstractApi {
1110
1211 public LabelsApi (GitLabApi gitLabApi ) {
1312 super (gitLabApi );
1413 }
1514
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+ */
1622 public List <Label > getLabels (Integer projectId ) throws GitLabApiException {
1723 return (getLabels (projectId , 1 , getDefaultPerPage ()));
1824 }
1925
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+ */
2035 public List <Label > getLabels (Integer projectId , int page , int perPage ) throws GitLabApiException {
2136
2237 if (projectId == null ) {
2338 throw new RuntimeException ("projectId cannot be null" );
2439 }
2540
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" );
2742 return (response .readEntity (new GenericType <List <Label >>() {}));
2843 }
2944
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+ */
3055 public Label createLabel (Integer projectId , String name , String color , String description ) throws GitLabApiException {
3156 return (createLabel (projectId , name , color , description , null ));
3257 }
3358
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+ */
3468 public Label createLabel (Integer projectId , String name , String color ) throws GitLabApiException {
3569 return (createLabel (projectId , name , color , null , null ));
3670 }
3771
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+ */
3882 public Label createLabel (Integer projectId , String name , String color , Integer priority ) throws GitLabApiException {
3983 return (createLabel (projectId , name , color , null , priority ));
4084 }
4185
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+ */
4297 public Label createLabel (Integer projectId , String name , String color , String description , Integer priority ) throws GitLabApiException {
4398
44- if (projectId == null ) {
99+ if (projectId == null ) {
45100 throw new RuntimeException ("projectId cannot be null" );
46101 }
47102
48- GitLabApiForm formData = new GitLabApiForm ()
103+ GitLabApiForm formData = new GitLabApiForm ()
49104 .withParam ("name" , name , true )
50105 .withParam ("color" , color , true )
51106 .withParam ("description" , description )
52107 .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" );
54109 return (response .readEntity (Label .class ));
55110 }
56111
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+ */
57124 public Label updateLabelName (Integer projectId , String name , String newName , String description , Integer priority ) throws GitLabApiException {
58125 return (updateLabel (projectId , name , newName , null , description , priority ));
59126 }
60127
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+ */
61140 public Label updateLabelColor (Integer projectId , String name , String color , String description , Integer priority ) throws GitLabApiException {
62141 return (updateLabel (projectId , name , null , color , description , priority ));
63142 }
64143
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+ */
65156 public Label updateLabel (Integer projectId , String name , String newName , String color , String description , Integer priority ) throws GitLabApiException {
66157
67158 if (projectId == null ) {
@@ -78,6 +169,13 @@ public Label updateLabel(Integer projectId, String name, String newName, String
78169 return (response .readEntity (Label .class ));
79170 }
80171
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+ */
81179 public void deleteLabel (Integer projectId , String name ) throws GitLabApiException {
82180
83181 if (projectId == null ) {
@@ -90,11 +188,28 @@ public void deleteLabel(Integer projectId, String name) throws GitLabApiExceptio
90188 delete (expectedStatus , formData .asMap (), "projects" , projectId , "labels" );
91189 }
92190
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+ */
93199 public Label subscribeLabel (Integer projectId , Integer labelId ) throws GitLabApiException {
94200 Response response = post (Response .Status .NOT_MODIFIED , getDefaultPerPageParam (), "projects" , projectId , "labels" , labelId , "subscribe" );
95201 return (response .readEntity (Label .class ));
96202 }
97203
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+ */
98213 public Label unsubscribeLabel (Integer projectId , Integer labelId ) throws GitLabApiException {
99214 Response response = post (Response .Status .NOT_MODIFIED , getDefaultPerPageParam (), "projects" , projectId , "labels" , labelId , "unsubscribe" );
100215 return (response .readEntity (Label .class ));
0 commit comments