Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions src/main/java/org/gitlab4j/api/MergeRequestApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -279,6 +280,44 @@ public Pager<Commit> getCommits(int projectId, int mergeRequestIid, int itemsPer
"projects", projectId, "merge_requests", mergeRequestIid, "commits"));
}

/**
* Get a list of merge request discussions.
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* 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<Discussion> 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<List<Discussion>>() {}));
}

/**
* Get a Pager of merge request discussions.
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* 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<Discussion> getDiscussions(int projectId, int mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<Discussion>(this, Discussion.class, itemsPerPage, null,
"projects", projectId, "merge_requests", mergeRequestIid, "discussions"));
}

/**
* Creates a merge request and optionally assigns a reviewer to it.
*
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/org/gitlab4j/api/models/Discussion.java
Original file line number Diff line number Diff line change
@@ -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<Note> notes;

public String getId() {
return id;
}

public Boolean getIndividualNote() {
return individualNote;
}

public List<Note> getNotes() {
return notes;
}

public void setId(String id) {
this.id = id;
}

public void setIndividualNote(Boolean individualNote) {
this.individualNote = individualNote;
}

public void setNotes(List<Note> notes) {
this.notes = notes;
}

@Override
public String toString() {
return (JacksonJson.toJsonString(this));
}

}
57 changes: 57 additions & 0 deletions src/main/java/org/gitlab4j/api/models/Note.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,27 @@ public String toString() {
}
}

public static enum Type {

DISCUSSION_NOTE, DIFF_NOTE;
private static JacksonJsonEnumHelper<Type> 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;
Expand All @@ -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;
Expand Down Expand Up @@ -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));
Expand Down