Commit 33b7b6d3 authored by Tim Olshansky's avatar Tim Olshansky

Merge pull request #94 from mpatkisson/milestones_post_put_support

Adds create / edit support for milestones
parents 1ae3f82a 53795e65
...@@ -12,7 +12,9 @@ import java.io.Serializable; ...@@ -12,7 +12,9 @@ import java.io.Serializable;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URL; import java.net.URL;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
...@@ -1067,6 +1069,126 @@ public class GitlabAPI { ...@@ -1067,6 +1069,126 @@ public class GitlabAPI {
return Arrays.asList(retrieve().to(tailUrl, GitlabMilestone[].class)); return Arrays.asList(retrieve().to(tailUrl, GitlabMilestone[].class));
} }
/**
* Cretaes a new project milestone.
* @param projectId The ID of the project.
* @param title The title of the milestone.
* @param description The description of the milestone. (Optional)
* @param dueDate The date the milestone is due. (Optional)
* @return The newly created, de-serialized milestone.
* @throws IOException
*/
public GitlabMilestone createMilestone(
Serializable projectId,
String title,
String description,
Date dueDate) throws IOException {
String tailUrl = GitlabProject.URL + "/" + projectId + GitlabMilestone.URL;
GitlabHTTPRequestor requestor = dispatch().with("title", title);
if (description != null) {
requestor = requestor.with("description", description);
}
if (dueDate != null) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formatted = formatter.format(dueDate);
requestor = requestor.with("due_date", formatted);
}
return requestor.to(tailUrl, GitlabMilestone.class);
}
/**
* Creates a new project milestone.
* @param projectId The ID of the project.
* @param milestone The milestone to create.
* @return The newly created, de-serialized milestone.
* @throws IOException
*/
public GitlabMilestone createMilestone(
Serializable projectId,
GitlabMilestone milestone) throws IOException {
String title = milestone.getTitle();
String description = milestone.getDescription();
Date dateDue = milestone.getDueDate();
return createMilestone(projectId, title, description, dateDue);
}
/**
* Updates an existing project milestone.
* @param projectId The ID of the project.
* @param milestoneId The ID of the milestone.
* @param title The title of the milestone. (Optional)
* @param description The description of the milestone. (Optional)
* @param dueDate The date the milestone is due. (Optional)
* @param stateEvent A value used to update the state of the milestone.
* (Optional) (activate | close)
* @return The updated, de-serialized milestone.
* @throws IOException
*/
public GitlabMilestone updateMilestone(
Serializable projectId,
int milestoneId,
String title,
String description,
Date dueDate,
String stateEvent) throws IOException {
String tailUrl = GitlabProject.URL + "/" +
projectId +
GitlabMilestone.URL + "/" +
milestoneId;
GitlabHTTPRequestor requestor = retrieve().method("PUT");
if (title != null) {
requestor.with("title", title);
}
if (description != null) {
requestor = requestor.with("description", description);
}
if (dueDate != null) {
SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
String formatted = formatter.format(dueDate);
requestor = requestor.with("due_date", formatted);
}
if (stateEvent != null) {
requestor.with("state_event", stateEvent);
}
return requestor.to(tailUrl, GitlabMilestone.class);
}
/**
* Updates an existing project milestone.
* @param projectId The ID of the project.
* @param edited The already edited milestone.
* @param stateEvent A value used to update the state of the milestone.
* (Optional) (activate | close)
* @return The updated, de-serialized milestone.
* @throws IOException
*/
public GitlabMilestone updateMilestone(
Serializable projectId,
GitlabMilestone edited,
String stateEvent) throws IOException {
return updateMilestone(projectId,
edited.getId(),
edited.getTitle(),
edited.getDescription(),
edited.getDueDate(),
stateEvent);
}
/**
* Updates an existing project milestone.
* @param edited The already edited milestone.
* @return The updated, de-serialized milestone.
* @param stateEvent A value used to update the state of the milestone.
* (Optional) (activate | close)
* @throws IOException
*/
public GitlabMilestone updateMilestone(
GitlabMilestone edited,
String stateEvent)
throws IOException {
return updateMilestone(edited.getProjectId(), edited, stateEvent);
}
/** /**
* Add a project member. * Add a project member.
* *
......
...@@ -9,9 +9,14 @@ public class GitlabMilestone { ...@@ -9,9 +9,14 @@ public class GitlabMilestone {
public static final String URL = "/milestones"; public static final String URL = "/milestones";
private int id; private int id;
private int iid; private int iid;
@JsonProperty("project_id")
private int projectId; private int projectId;
private String title; private String title;
private String description; private String description;
@JsonProperty("due_date") @JsonProperty("due_date")
......
Markdown is supported
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