Skip to content

Commit 5e7248d

Browse files
Stel000gmessner
authored andcommitted
Complete the javadoc of NoteApi and LabelApi (#105)
* Complete the javadoc of NoteApi and LabelApi * Fix createLabel and updateIssueNote
1 parent 425a77f commit 5e7248d

File tree

2 files changed

+173
-13
lines changed

2 files changed

+173
-13
lines changed

src/main/java/org/gitlab4j/api/LabelsApi.java

Lines changed: 122 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,158 @@
11
package org.gitlab4j.api;
22

3-
import java.util.List;
3+
import org.gitlab4j.api.models.Label;
44

55
import javax.ws.rs.core.GenericType;
66
import javax.ws.rs.core.Response;
7-
8-
import org.gitlab4j.api.models.Label;
7+
import java.util.List;
98

109
public 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));

src/main/java/org/gitlab4j/api/NotesApi.java

Lines changed: 51 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
package org.gitlab4j.api;
22

3-
import java.util.Date;
4-
import java.util.List;
3+
import org.gitlab4j.api.models.Note;
54

65
import javax.ws.rs.core.GenericType;
76
import javax.ws.rs.core.Response;
8-
9-
import org.gitlab4j.api.models.Note;
7+
import java.util.Date;
8+
import java.util.List;
109

1110
public class NotesApi extends AbstractApi {
1211

@@ -109,15 +108,43 @@ public Pager<Note> getIssueNotes(Integer projectId, Integer issueIid, int itemsP
109108
return (new Pager<Note>(this, Note.class, itemsPerPage, null, "projects", projectId, "issues", issueIid, "notes"));
110109
}
111110

111+
/**
112+
* Get the specified issues's note.
113+
*
114+
* @param projectId the project ID to get the issues for
115+
* @param issueIid the issue IID to get the notes for
116+
* @param noteId the ID of the Note to get
117+
* @return a Note instance for the specified IDs
118+
* @throws GitLabApiException if any exception occurs
119+
*/
112120
public Note getIssueNote(Integer projectId, Integer issueIid, Integer noteId) throws GitLabApiException {
113121
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "issues", issueIid, "notes", noteId);
114122
return (response.readEntity(Note.class));
115123
}
116124

125+
/**
126+
* Create a issues's note.
127+
*
128+
* @param projectId the project ID to create the issues for
129+
* @param issueIid the issue IID to create the notes for
130+
* @param body the content of note
131+
* @return the created Note instance
132+
* @throws GitLabApiException if any exception occurs
133+
*/
117134
public Note createIssueNote(Integer projectId, Integer issueIid, String body) throws GitLabApiException {
118135
return (createIssueNote(projectId, issueIid, body, null));
119136
}
120137

138+
/**
139+
* Create a issues's note.
140+
*
141+
* @param projectId the project ID to create the issues for
142+
* @param issueIid the issue IID to create the notes for
143+
* @param body the content of note
144+
* @param createdAt the created time of note
145+
* @return the created Note instance
146+
* @throws GitLabApiException if any exception occurs
147+
*/
121148
public Note createIssueNote(Integer projectId, Integer issueIid, String body, Date createdAt) throws GitLabApiException {
122149
if (projectId == null) {
123150
throw new RuntimeException("projectId cannot be null");
@@ -129,16 +156,34 @@ public Note createIssueNote(Integer projectId, Integer issueIid, String body, Da
129156
return (response.readEntity(Note.class));
130157
}
131158

132-
public Note updateIssueNote(Integer projectId, Integer issueIid, String body) throws GitLabApiException {
159+
/**
160+
* Update the specified issues's note.
161+
*
162+
* @param projectId the project ID to update the issues for
163+
* @param issueIid the issue IID to update the notes for
164+
* @param nodeId the ID of the node to update
165+
* @param body the update content for the Note
166+
* @return the modified Note instance
167+
* @throws GitLabApiException if any exception occurs
168+
*/
169+
public Note updateIssueNote(Integer projectId, Integer issueIid, Integer nodeId, String body) throws GitLabApiException {
133170
if (projectId == null) {
134171
throw new RuntimeException("projectId cannot be null");
135172
}
136173
GitLabApiForm formData = new GitLabApiForm()
137174
.withParam("body", body, true);
138-
Response response = put(Response.Status.CREATED, formData.asMap(), "projects", projectId, "issues", issueIid, "notes");
175+
Response response = put(Response.Status.CREATED, formData.asMap(), "projects", projectId, "issues", issueIid, "notes", nodeId);
139176
return (response.readEntity(Note.class));
140177
}
141178

179+
/**
180+
* Delete the specified issues's note.
181+
*
182+
* @param projectId the project ID to delete the issues for
183+
* @param issueIid the issue IID to delete the notes for
184+
* @param noteId the ID of the node to delete
185+
* @throws GitLabApiException if any exception occurs
186+
*/
142187
public void deleteIssueNote(Integer projectId, Integer issueIid, Integer noteId) throws GitLabApiException {
143188
if (projectId == null) {
144189
throw new RuntimeException("projectId cannot be null");

0 commit comments

Comments
 (0)