package org.gitlab4j.api; import java.util.Date; import java.util.List; import java.util.stream.Stream; import jakarta.ws.rs.core.Form; import jakarta.ws.rs.core.GenericType; import jakarta.ws.rs.core.Response; import org.gitlab4j.api.models.Issue; import org.gitlab4j.api.models.MergeRequest; import org.gitlab4j.api.models.Milestone; /** * This class implements the client side API for the GitLab milestones calls. * @see Project milestones API * @see Group milestones API */ public class MilestonesApi extends AbstractApi { public MilestonesApi(GitLabApi gitLabApi) { super(gitLabApi); } /** * Get a list of group milestones. * *
GitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
* @return the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(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 PagerGitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
* @return a Stream of the milestones associated with the specified group
* @throws GitLabApiException if any exception occurs
*/
public StreamGitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: GET /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: GET /groups/:id/milestones/:milestone_id
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: GET /groups/:id/milestones/:milestone_id
*
* @param groupIdOrPath the group in the form of an Long(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, Long 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.
*
* GitLab Endpoint: GET /groups/:id/milestones/:milestone_id/issues
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: GET /groups/:id/milestones/:milestone_id/issues
*
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
* @param milestoneId the milestone ID to get the issues for
* @param itemsPerPage The number of Milestone instances that will be fetched per page
* @return a Pager of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public PagerGitLab Endpoint: GET /groups/:id/milestones/:milestone_id/issues
*
* @param groupIdOrPath the group in the form of an Long(ID), String(path), or Group instance
* @param milestoneId the milestone ID to get the issues for
* @return a Stream of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public StreamGitLab Endpoint: GET /groups/:id/milestones/:milestone_id/merge_requests
*
* @param groupIdOrPath the group in the form of an Long(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 ListGitLab Endpoint: POST /groups/:id/milestones
*
* @param groupIdOrPath the group in the form of an Long(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.
*
* GitLab Endpoint: PUT /groups/:id/milestones/:milestone_id
*
* @param groupIdOrPath the group in the form of an Long(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, Long 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.
*
* GitLab Endpoint: PUT /groups/:id/milestones/:milestone_id
*
* @param groupIdOrPath the group in the form of an Long(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, Long 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.
*
* GitLab Endpoint: PUT /groups/:id/milestones/:milestone_id
*
* @param groupIdOrPath the group in the form of an Long(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, Long 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.
*
* GitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param page the page number to get
* @param perPage how many milestones per page
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param itemsPerPage The number of Milestone instances that will be fetched per page
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public PagerGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @return a Stream of the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public StreamGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param state the milestone state
* @return the milestones associated with the specified project and state
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param search the search string
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param state the milestone state
* @param search the search string
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public ListGitLab Endpoint: GET /projects/:id/milestones/:milestone_id
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project 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 getMilestone(Object projectIdOrPath, Long milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Get the list of issues associated with the specified milestone.
*
* GitLab Endpoint: GET /projects/:id/milestones/:milestone_id/issues
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project 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 ListGitLab Endpoint: GET /projects/:id/milestones/:milestone_id/issues
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param milestoneId the milestone ID to get the issues for
* @param itemsPerPage the number of Milestone instances that will be fetched per page
* @return a Pager of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public PagerGitLab Endpoint: GET /projects/:id/milestones/:milestone_id/issues
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param milestoneId the milestone ID to get the issues for
* @return a Stream of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public StreamGitLab Endpoint: GET /projects/:id/milestones/:milestone_id/merge_requests
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project 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 ListGitLab Endpoint: POST /projects/:id/milestones
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project 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 createMilestone(Object projectIdOrPath, 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,
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(Milestone.class));
}
/**
* Close a milestone.
*
* GitLab Endpoint: PUT /projects/:id/milestones/:milestone_id
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param milestoneId the milestone ID to close
* @return the closed Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone closeMilestone(Object projectIdOrPath, Long 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(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Activate a milestone.
*
* GitLab Endpoint: PUT /projects/:id/milestones/:milestone_id
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param milestoneId the milestone ID to activate
* @return the activated Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone activateMilestone(Object projectIdOrPath, Long 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(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Update the specified milestone.
*
* GitLab Endpoint: PUT /projects/:id/milestones/:milestone_id
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project 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 updateMilestone(Object projectIdOrPath, Long 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(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* Delete a project milestone.
*
* @param projectIdOrPath the project in the form of an Long(ID), String(path), or Project instance
* @param milestoneId the milestone ID to delete
* @throws GitLabApiException if any exception occurs
*/
public void deleteMilestone(Object projectIdOrPath, Long milestoneId) throws GitLabApiException {
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
}
}