Skip to content

Commit a852499

Browse files
filippobulettogmessner
authored andcommitted
Add Discussions model and api (#279)
* Add Discussions model and API calls.
1 parent 9ead319 commit a852499

File tree

3 files changed

+144
-0
lines changed

3 files changed

+144
-0
lines changed

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.gitlab4j.api.GitLabApi.ApiVersion;
1212
import org.gitlab4j.api.models.Commit;
13+
import org.gitlab4j.api.models.Discussion;
1314
import org.gitlab4j.api.models.Issue;
1415
import org.gitlab4j.api.models.MergeRequest;
1516
import org.gitlab4j.api.models.MergeRequestFilter;
@@ -279,6 +280,44 @@ public Pager<Commit> getCommits(int projectId, int mergeRequestIid, int itemsPer
279280
"projects", projectId, "merge_requests", mergeRequestIid, "commits"));
280281
}
281282

283+
/**
284+
* Get a list of merge request discussions.
285+
*
286+
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
287+
*
288+
* GET /projects/:id/merge_requests/:merge_request_iid/discussions
289+
*
290+
* @param projectId the project ID for the merge request
291+
* @param mergeRequestIid the internal ID of the merge request
292+
* @param page the page to get
293+
* @param perPage the number of commits per page
294+
* @return a list containing the discussions for the specified merge request
295+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
296+
*/
297+
public List<Discussion> getDiscussions(int projectId, int mergeRequestIid, int page, int perPage) throws GitLabApiException {
298+
Form formData = new GitLabApiForm().withParam("owned", false).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
299+
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "discussions");
300+
return (response.readEntity(new GenericType<List<Discussion>>() {}));
301+
}
302+
303+
/**
304+
* Get a Pager of merge request discussions.
305+
*
306+
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
307+
*
308+
* GET /projects/:id/merge_requests/:merge_request_iid/discussions
309+
*
310+
* @param projectId the project ID for the merge request
311+
* @param mergeRequestIid the internal ID of the merge request
312+
* @param itemsPerPage the number of Commit instances that will be fetched per page
313+
* @return a Pager containing the discussions for the specified merge request
314+
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
315+
*/
316+
public Pager<Discussion> getDiscussions(int projectId, int mergeRequestIid, int itemsPerPage) throws GitLabApiException {
317+
return (new Pager<Discussion>(this, Discussion.class, itemsPerPage, null,
318+
"projects", projectId, "merge_requests", mergeRequestIid, "discussions"));
319+
}
320+
282321
/**
283322
* Creates a merge request and optionally assigns a reviewer to it.
284323
*
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
package org.gitlab4j.api.models;
2+
3+
import java.util.List;
4+
5+
import javax.xml.bind.annotation.XmlAccessType;
6+
import javax.xml.bind.annotation.XmlAccessorType;
7+
import javax.xml.bind.annotation.XmlRootElement;
8+
9+
import org.gitlab4j.api.utils.JacksonJson;
10+
11+
@XmlRootElement
12+
@XmlAccessorType(XmlAccessType.FIELD)
13+
public class Discussion {
14+
15+
private String id;
16+
private Boolean individualNote;
17+
private List<Note> notes;
18+
19+
public String getId() {
20+
return id;
21+
}
22+
23+
public Boolean getIndividualNote() {
24+
return individualNote;
25+
}
26+
27+
public List<Note> getNotes() {
28+
return notes;
29+
}
30+
31+
public void setId(String id) {
32+
this.id = id;
33+
}
34+
35+
public void setIndividualNote(Boolean individualNote) {
36+
this.individualNote = individualNote;
37+
}
38+
39+
public void setNotes(List<Note> notes) {
40+
this.notes = notes;
41+
}
42+
43+
@Override
44+
public String toString() {
45+
return (JacksonJson.toJsonString(this));
46+
}
47+
48+
}

src/main/java/org/gitlab4j/api/models/Note.java

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,27 @@ public String toString() {
5959
}
6060
}
6161

62+
public static enum Type {
63+
64+
DISCUSSION_NOTE, DIFF_NOTE;
65+
private static JacksonJsonEnumHelper<Type> enumHelper = new JacksonJsonEnumHelper<>(Type.class, true, true);
66+
67+
@JsonCreator
68+
public static Type forValue(String value) {
69+
return enumHelper.forValue(value);
70+
}
71+
72+
@JsonValue
73+
public String toValue() {
74+
return (enumHelper.toString(this));
75+
}
76+
77+
@Override
78+
public String toString() {
79+
return (enumHelper.toString(this));
80+
}
81+
}
82+
6283
private String attachment;
6384
private Author author;
6485
private String body;
@@ -74,6 +95,10 @@ public String toString() {
7495
private String title;
7596
private String updatedAt;
7697
private Boolean upvote;
98+
private Boolean resolved;
99+
private Boolean resolvable;
100+
private Participant resolvedBy;
101+
private Type type;
77102

78103
public String getAttachment() {
79104
return attachment;
@@ -195,6 +220,38 @@ public void setUpvote(Boolean upvote) {
195220
this.upvote = upvote;
196221
}
197222

223+
public Boolean getResolved() {
224+
return resolved;
225+
}
226+
227+
public void setResolved(Boolean resolved) {
228+
this.resolved = resolved;
229+
}
230+
231+
public Boolean getResolvable() {
232+
return resolvable;
233+
}
234+
235+
public void setResolvable(Boolean resolvable) {
236+
this.resolvable = resolvable;
237+
}
238+
239+
public Participant getResolvedBy() {
240+
return resolvedBy;
241+
}
242+
243+
public void setResolvedBy(Participant resolvedBy) {
244+
this.resolvedBy = resolvedBy;
245+
}
246+
247+
public Type getType() {
248+
return type;
249+
}
250+
251+
public void setType(Type type) {
252+
this.type = type;
253+
}
254+
198255
@Override
199256
public String toString() {
200257
return (JacksonJson.toJsonString(this));

0 commit comments

Comments
 (0)