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..34fa3dcec --- /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 Boolean individualNote; + private List notes; + + public String getId() { + return id; + } + + public Boolean getIndividualNote() { + return individualNote; + } + + public List getNotes() { + return notes; + } + + public void setId(String id) { + this.id = id; + } + + public void setIndividualNote(Boolean 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..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; @@ -74,6 +95,10 @@ public String toString() { private String title; private String updatedAt; private Boolean upvote; + private Boolean resolved; + private Boolean resolvable; + private Participant resolvedBy; + private Type type; public String getAttachment() { return attachment; @@ -195,6 +220,38 @@ 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; + } + + public Type getType() { + return type; + } + + public void setType(Type type) { + this.type = type; + } + @Override public String toString() { return (JacksonJson.toJsonString(this));