From 6ca864f9fd69f46aea4ca2c5637050421011c521 Mon Sep 17 00:00:00 2001 From: Buletto Filippo Date: Mon, 10 Dec 2018 10:06:19 +0100 Subject: [PATCH 1/2] Add Discussions model and api Discussions are set of related notes on snippets, issues, epics, merge requests or commits. This commit only include merge requests one. --- .../org/gitlab4j/api/MergeRequestApi.java | 39 +++++++++++++++ .../org/gitlab4j/api/models/Discussion.java | 48 +++++++++++++++++++ .../java/org/gitlab4j/api/models/Note.java | 27 +++++++++++ 3 files changed, 114 insertions(+) create mode 100644 src/main/java/org/gitlab4j/api/models/Discussion.java diff --git a/src/main/java/org/gitlab4j/api/MergeRequestApi.java b/src/main/java/org/gitlab4j/api/MergeRequestApi.java index cd15cf3c5..a83286460 100644 --- a/src/main/java/org/gitlab4j/api/MergeRequestApi.java +++ b/src/main/java/org/gitlab4j/api/MergeRequestApi.java @@ -10,6 +10,7 @@ import org.gitlab4j.api.GitLabApi.ApiVersion; import org.gitlab4j.api.models.Commit; +import org.gitlab4j.api.models.Discussion; import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.MergeRequestFilter; @@ -279,6 +280,44 @@ public Pager getCommits(int projectId, int mergeRequestIid, int itemsPer "projects", projectId, "merge_requests", mergeRequestIid, "commits")); } + /** + * Get a list of merge request discussions. + * + *

NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.

+ * + * GET /projects/:id/merge_requests/:merge_request_iid/discussions + * + * @param projectId the project ID for the merge request + * @param mergeRequestIid the internal ID of the merge request + * @param page the page to get + * @param perPage the number of commits per page + * @return a list containing the discussions for the specified merge request + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public List getDiscussions(int projectId, int mergeRequestIid, int page, int perPage) throws GitLabApiException { + Form formData = new GitLabApiForm().withParam("owned", false).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage); + Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "discussions"); + return (response.readEntity(new GenericType>() {})); + } + + /** + * Get a Pager of merge request discussions. + * + *

NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.

+ * + * GET /projects/:id/merge_requests/:merge_request_iid/discussions + * + * @param projectId the project ID for the merge request + * @param mergeRequestIid the internal ID of the merge request + * @param itemsPerPage the number of Commit instances that will be fetched per page + * @return a Pager containing the discussions for the specified merge request + * @throws GitLabApiException GitLabApiException if any exception occurs during execution + */ + public Pager getDiscussions(int projectId, int mergeRequestIid, int itemsPerPage) throws GitLabApiException { + return (new Pager(this, Discussion.class, itemsPerPage, null, + "projects", projectId, "merge_requests", mergeRequestIid, "discussions")); + } + /** * Creates a merge request and optionally assigns a reviewer to it. * diff --git a/src/main/java/org/gitlab4j/api/models/Discussion.java b/src/main/java/org/gitlab4j/api/models/Discussion.java new file mode 100644 index 000000000..070479b56 --- /dev/null +++ b/src/main/java/org/gitlab4j/api/models/Discussion.java @@ -0,0 +1,48 @@ +package org.gitlab4j.api.models; + +import java.util.List; + +import javax.xml.bind.annotation.XmlAccessType; +import javax.xml.bind.annotation.XmlAccessorType; +import javax.xml.bind.annotation.XmlRootElement; + +import org.gitlab4j.api.utils.JacksonJson; + +@XmlRootElement +@XmlAccessorType(XmlAccessType.FIELD) +public class Discussion { + + private String id; + private String individualNote; + private List notes; + + public String getId() { + return id; + } + + public String getIndividualNote() { + return individualNote; + } + + public List getNotes() { + return notes; + } + + public void setId(String id) { + this.id = id; + } + + public void setIndividualNote(String individualNote) { + this.individualNote = individualNote; + } + + public void setNotes(List notes) { + this.notes = notes; + } + + @Override + public String toString() { + return (JacksonJson.toJsonString(this)); + } + +} diff --git a/src/main/java/org/gitlab4j/api/models/Note.java b/src/main/java/org/gitlab4j/api/models/Note.java index 77976b556..45e09e09a 100644 --- a/src/main/java/org/gitlab4j/api/models/Note.java +++ b/src/main/java/org/gitlab4j/api/models/Note.java @@ -74,6 +74,9 @@ public String toString() { private String title; private String updatedAt; private Boolean upvote; + private Boolean resolved; + private Boolean resolvable; + private Participant resolvedBy; public String getAttachment() { return attachment; @@ -195,6 +198,30 @@ public void setUpvote(Boolean upvote) { this.upvote = upvote; } + public Boolean getResolved() { + return resolved; + } + + public void setResolved(Boolean resolved) { + this.resolved = resolved; + } + + public Boolean getResolvable() { + return resolvable; + } + + public void setResolvable(Boolean resolvable) { + this.resolvable = resolvable; + } + + public Participant getResolvedBy() { + return resolvedBy; + } + + public void setResolvedBy(Participant resolvedBy) { + this.resolvedBy = resolvedBy; + } + @Override public String toString() { return (JacksonJson.toJsonString(this)); From 2e01504faffe26426a666359b6c2aad64b85e3eb Mon Sep 17 00:00:00 2001 From: Buletto Filippo Date: Wed, 12 Dec 2018 10:45:50 +0100 Subject: [PATCH 2/2] Fix discussion and note models --- .../org/gitlab4j/api/models/Discussion.java | 6 ++-- .../java/org/gitlab4j/api/models/Note.java | 30 +++++++++++++++++++ 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/src/main/java/org/gitlab4j/api/models/Discussion.java b/src/main/java/org/gitlab4j/api/models/Discussion.java index 070479b56..34fa3dcec 100644 --- a/src/main/java/org/gitlab4j/api/models/Discussion.java +++ b/src/main/java/org/gitlab4j/api/models/Discussion.java @@ -13,14 +13,14 @@ public class Discussion { private String id; - private String individualNote; + private Boolean individualNote; private List notes; public String getId() { return id; } - public String getIndividualNote() { + public Boolean getIndividualNote() { return individualNote; } @@ -32,7 +32,7 @@ public void setId(String id) { this.id = id; } - public void setIndividualNote(String individualNote) { + public void setIndividualNote(Boolean individualNote) { this.individualNote = individualNote; } diff --git a/src/main/java/org/gitlab4j/api/models/Note.java b/src/main/java/org/gitlab4j/api/models/Note.java index 45e09e09a..721922dda 100644 --- a/src/main/java/org/gitlab4j/api/models/Note.java +++ b/src/main/java/org/gitlab4j/api/models/Note.java @@ -59,6 +59,27 @@ public String toString() { } } + public static enum Type { + + DISCUSSION_NOTE, DIFF_NOTE; + private static JacksonJsonEnumHelper enumHelper = new JacksonJsonEnumHelper<>(Type.class, true, true); + + @JsonCreator + public static Type forValue(String value) { + return enumHelper.forValue(value); + } + + @JsonValue + public String toValue() { + return (enumHelper.toString(this)); + } + + @Override + public String toString() { + return (enumHelper.toString(this)); + } + } + private String attachment; private Author author; private String body; @@ -77,6 +98,7 @@ public String toString() { private Boolean resolved; private Boolean resolvable; private Participant resolvedBy; + private Type type; public String getAttachment() { return attachment; @@ -222,6 +244,14 @@ public void setResolvedBy(Participant resolvedBy) { this.resolvedBy = resolvedBy; } + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + @Override public String toString() { return (JacksonJson.toJsonString(this));