Commit f24acfae authored by Pierre Smeyers's avatar Pierre Smeyers Committed by Greg Messner
Browse files

Added Group Milestones API (#304)

* Added missing start_date Milestone attribute
* Added Group Milestones API
parent 57f29725
This diff is collapsed.
......@@ -21,6 +21,240 @@ public class MilestonesApi extends AbstractApi {
super(gitLabApi);
}
/**
* Get a list of group milestones.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getGroupMilestones(Object groupIdOrPath) throws GitLabApiException {
return (getGroupMilestones(groupIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a list of group milestones.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param page the page number to get
* @param perPage how many milestones per page
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getGroupMilestones(Object groupIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
/**
* Get a Page of group milestones.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param itemsPerPage The number of Milestone instances that will be fetched per page
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public Pager<Milestone> getGroupMilestones(Object groupIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Milestone>(this, Milestone.class, itemsPerPage, null,
"groups", getGroupIdOrPath(groupIdOrPath), "milestones"));
}
/**
* Get a Stream of group milestones.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @return a Stream of the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public Stream<Milestone> getGroupMilestonesStream(Object groupIdOrPath) throws GitLabApiException {
return (getGroupMilestones(groupIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get a list of group milestones that have the specified state.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param state the milestone state
* @return the milestones associated with the specified group and state
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getGroupMilestones(Object groupIdOrPath, MilestoneState state) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("state", state).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
/**
* Get a list of group milestones that have match the search string.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param search the search string
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getGroupMilestones(Object groupIdOrPath, String search) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
/**
* Get a list of group milestones that have the specified state and match the search string.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param state the milestone state
* @param search the search string
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getGroupMilestones(Object groupIdOrPath, MilestoneState state, String search) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state)
.withParam("search", search)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
/**
* Get the specified group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the ID of the milestone tp get
* @return a Milestone instance for the specified IDs
* @throws GitLabApiException if any exception occurs
*/
public Milestone getGroupMilestone(Object groupIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Get the list of issues associated with the specified group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the milestone ID to get the issues for
* @return a List of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public List<Issue> getGroupIssues(Object groupIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId, "issues");
return (response.readEntity(new GenericType<List<Issue>>() {}));
}
/**
* Get the list of merge requests associated with the specified group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the milestone ID to get the merge requests for
* @return a list of merge requests associated with the specified milestone
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getGroupMergeRequest(Object groupIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId, "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
}
/**
* Create a group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param title the title for the milestone
* @param description the description for the milestone
* @param dueDate the due date for the milestone
* @param startDate the start date for the milestone
* @return the created Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone createGroupMilestone(Object groupIdOrPath, String title, String description, Date dueDate, Date startDate) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true)
.withParam("description", description)
.withParam("due_date", dueDate)
.withParam("start_date", startDate);
Response response = post(Response.Status.CREATED, formData,
"groups", getGroupIdOrPath(groupIdOrPath), "milestones");
return (response.readEntity(Milestone.class));
}
/**
* Close a group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the milestone ID to close
* @return the closed Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone closeGroupMilestone(Object groupIdOrPath, Integer milestoneId) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.CLOSE);
Response response = put(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Activate a group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the milestone ID to activate
* @return the activated Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone activateGroupMilestone(Object groupIdOrPath, Integer milestoneId) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.ACTIVATE);
Response response = put(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Update the specified group milestone.
*
* @param groupIdOrPath the group in the form of an Integer(ID), String(path), or Group instance
* @param milestoneId the milestone ID to update
* @param title the updated title for the milestone
* @param description the updated description for the milestone
* @param dueDate the updated due date for the milestone
* @param startDate the updated start date for the milestone
* @param milestoneState the updated milestone state
* @return the updated Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone updateGroupMilestone(Object groupIdOrPath, Integer milestoneId, String title, String description,
Date dueDate, Date startDate, MilestoneState milestoneState) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true)
.withParam("description", description)
.withParam("due_date", dueDate)
.withParam("start_date", startDate)
.withParam("state_event", milestoneState);
Response response = put(Response.Status.OK, formData.asMap(),
"groups", getGroupIdOrPath(groupIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Get a list of project milestones.
*
......@@ -128,7 +362,7 @@ public class MilestonesApi extends AbstractApi {
* @return a Milestone instance for the specified IDs
* @throws GitLabApiException if any exception occurs
*/
public Milestone getMilestone(Object projectIdOrPath, int milestoneId) throws GitLabApiException {
public Milestone getMilestone(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
......
......@@ -14,10 +14,12 @@ public class Milestone {
private Date createdAt;
private String description;
private Date startDate;
private Date dueDate;
private Integer id;
private Integer iid;
private Integer projectId;
private Integer groupId;
private String state;
private String title;
private Date updatedAt;
......@@ -38,6 +40,14 @@ public class Milestone {
this.description = description;
}
public Date getStartDate() {
return startDate;
}
public void setStartDate(Date startDate) {
this.startDate = startDate;
}
public Date getDueDate() {
return this.dueDate;
}
......@@ -70,6 +80,14 @@ public class Milestone {
this.projectId = projectId;
}
public Integer getGroupId() {
return groupId;
}
public void setGroupId(Integer groupId) {
this.groupId = groupId;
}
public String getState() {
return this.state;
}
......
......@@ -317,6 +317,12 @@ public class TestGitLabApiBeans {
assertTrue(compareJson(milestone, "milestone.json"));
}
@Test
public void testGroupMilestone() throws Exception {
Milestone milestone = unmarshalResource(Milestone.class, "milestone-group.json");
assertTrue(compareJson(milestone, "milestone-group.json"));
}
@Test
public void testNote() throws Exception {
Note note = unmarshalResource(Note.class, "note.json");
......
{
"id":12,
"iid":3,
"group_id":14,
"title":"10.0",
"description":"Version",
"start_date":"2013-11-01T00:00:00Z",
"due_date":"2013-11-29T00:00:00Z",
"state":"active",
"updated_at":"2013-10-02T09:24:18Z",
"created_at":"2013-10-02T09:24:18Z"
}
......@@ -4,6 +4,7 @@
"project_id":16,
"title":"10.0",
"description":"Version",
"start_date":"2013-11-01T00:00:00Z",
"due_date":"2013-11-29T00:00:00Z",
"state":"active",
"updated_at":"2013-10-02T09:24:18Z",
......
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