Commit a852499e authored by Filippo Buletto's avatar Filippo Buletto Committed by Greg Messner
Browse files

Add Discussions model and api (#279)

* Add Discussions model and API calls.
parent 9ead3199
......@@ -10,6 +10,7 @@ import javax.ws.rs.core.Response;
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 class MergeRequestApi extends AbstractApi {
"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.
*
......
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));
}
}
......@@ -59,6 +59,27 @@ public class Note {
}
}
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;
......@@ -74,6 +95,10 @@ public class Note {
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 class Note {
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));
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment