Commit be5072a8 authored by Greg Messner's avatar Greg Messner
Browse files

Added getXxxxxStream() methods that return Java 8 Streams.

parent b38252fd
...@@ -3,6 +3,7 @@ package org.gitlab4j.api; ...@@ -3,6 +3,7 @@ package org.gitlab4j.api;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
...@@ -29,7 +30,7 @@ public class EpicsApi extends AbstractApi { ...@@ -29,7 +30,7 @@ public class EpicsApi extends AbstractApi {
/** /**
* Gets all epics of the requested group and its subgroups. * Gets all epics of the requested group and its subgroups.
* *
* <pre><code>GitLab Endpoint: GET /groups/:id/epics</code></pre> * <pre><code>GitLab Endpoint: GET /groups/:id/epics</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
...@@ -37,7 +38,7 @@ public class EpicsApi extends AbstractApi { ...@@ -37,7 +38,7 @@ public class EpicsApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Epic> getEpics(Object groupIdOrPath) throws GitLabApiException { public List<Epic> getEpics(Object groupIdOrPath) throws GitLabApiException {
return (getEpics(groupIdOrPath, 1, getDefaultPerPage())); return (getEpics(groupIdOrPath, getDefaultPerPage()).all());
} }
/** /**
...@@ -70,6 +71,19 @@ public class EpicsApi extends AbstractApi { ...@@ -70,6 +71,19 @@ public class EpicsApi extends AbstractApi {
return (new Pager<Epic>(this, Epic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics")); return (new Pager<Epic>(this, Epic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics"));
} }
/**
* Gets all epics of the requested group and its subgroups as a Stream.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @return a Stream of all epics of the requested group and its subgroups
* @throws GitLabApiException if any exception occurs
*/
public Stream<Epic> getEpicsStream(Object groupIdOrPath) throws GitLabApiException {
return (getEpics(groupIdOrPath, getDefaultPerPage()).stream());
}
/** /**
* Gets all epics of the requested group and its subgroups. * Gets all epics of the requested group and its subgroups.
* *
...@@ -87,7 +101,7 @@ public class EpicsApi extends AbstractApi { ...@@ -87,7 +101,7 @@ public class EpicsApi extends AbstractApi {
*/ */
public List<Epic> getEpics(Object groupIdOrPath, Integer authorId, String labels, EpicOrderBy orderBy, public List<Epic> getEpics(Object groupIdOrPath, Integer authorId, String labels, EpicOrderBy orderBy,
SortOrder sortOrder, String search) throws GitLabApiException { SortOrder sortOrder, String search) throws GitLabApiException {
return (getEpics(groupIdOrPath, authorId, labels, orderBy, sortOrder, search, 1, getDefaultPerPage())); return (getEpics(groupIdOrPath, authorId, labels, orderBy, sortOrder, search, getDefaultPerPage()).all());
} }
/** /**
...@@ -146,6 +160,26 @@ public class EpicsApi extends AbstractApi { ...@@ -146,6 +160,26 @@ public class EpicsApi extends AbstractApi {
return (new Pager<Epic>(this, Epic.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "epics")); return (new Pager<Epic>(this, Epic.class, itemsPerPage, formData.asMap(), "groups", getGroupIdOrPath(groupIdOrPath), "epics"));
} }
/**
* Gets all epics of the requested group and its subgroups as a Stream.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param authorId returns epics created by the given user id
* @param labels return epics matching a comma separated list of labels names.
* Label names from the epic group or a parent group can be used
* @param orderBy return epics ordered by CREATED_AT or UPDATED_AT. Default is CREATED_AT
* @param sortOrder return epics sorted in ASC or DESC order. Default is DESC
* @param search search epics against their title and description
* @return a Stream of matching epics of the requested group and its subgroups
* @throws GitLabApiException if any exception occurs
*/
public Stream<Epic> getEpicsStream(Object groupIdOrPath, Integer authorId, String labels, EpicOrderBy orderBy,
SortOrder sortOrder, String search) throws GitLabApiException {
return (getEpics(groupIdOrPath, authorId, labels, orderBy, sortOrder, search, getDefaultPerPage()).stream());
}
/** /**
* Get a single epic for the specified group. * Get a single epic for the specified group.
* *
...@@ -305,11 +339,10 @@ public class EpicsApi extends AbstractApi { ...@@ -305,11 +339,10 @@ public class EpicsApi extends AbstractApi {
public void deleteEpic(Object groupIdOrPath, Integer epicIid) throws GitLabApiException { public void deleteEpic(Object groupIdOrPath, Integer epicIid) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid); delete(Response.Status.NO_CONTENT, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid);
} }
/** /**
* Gets all issues that are assigned to an epic and the authenticated user has access to. * Gets all issues that are assigned to an epic and the authenticated user has access to.
* *
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre> * <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
...@@ -318,13 +351,13 @@ public class EpicsApi extends AbstractApi { ...@@ -318,13 +351,13 @@ public class EpicsApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Epic> getEpicIssues(Object groupIdOrPath, Integer epicIid) throws GitLabApiException { public List<Epic> getEpicIssues(Object groupIdOrPath, Integer epicIid) throws GitLabApiException {
return (getEpicIssues(groupIdOrPath, epicIid, 1, getDefaultPerPage())); return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).all());
} }
/** /**
* Gets all issues that are assigned to an epic and the authenticated user has access to * Gets all issues that are assigned to an epic and the authenticated user has access to
* using the specified page and per page setting. * using the specified page and per page setting.
* *
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre> * <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
...@@ -341,7 +374,7 @@ public class EpicsApi extends AbstractApi { ...@@ -341,7 +374,7 @@ public class EpicsApi extends AbstractApi {
/** /**
* Get a Pager of all issues that are assigned to an epic and the authenticated user has access to. * Get a Pager of all issues that are assigned to an epic and the authenticated user has access to.
* *
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre> * <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre>
* *
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path * @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
...@@ -354,6 +387,20 @@ public class EpicsApi extends AbstractApi { ...@@ -354,6 +387,20 @@ public class EpicsApi extends AbstractApi {
return (new Pager<Epic>(this, Epic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues")); return (new Pager<Epic>(this, Epic.class, itemsPerPage, null, "groups", getGroupIdOrPath(groupIdOrPath), "epics", epicIid, "issues"));
} }
/**
* Gets all issues that are assigned to an epic and the authenticated user has access to as a Stream.
*
* <pre><code>GitLab Endpoint: GET /groups/:id/epics/:epic_iid/issues</code></pre>
*
* @param groupIdOrPath the group ID, path of the group, or a Group instance holding the group ID or path
* @param epicIid the IID of the epic to get issues for
* @return a Stream of all epic issues belonging to the specified epic
* @throws GitLabApiException if any exception occurs
*/
public Stream<Epic> getEpicIssuesStream(Object groupIdOrPath, Integer epicIid) throws GitLabApiException {
return (getEpicIssues(groupIdOrPath, epicIid, getDefaultPerPage()).stream());
}
/** /**
* Creates an epic - issue association. If the issue in question belongs to another epic * Creates an epic - issue association. If the issue in question belongs to another epic
* it is unassigned from that epic. * it is unassigned from that epic.
......
...@@ -17,7 +17,7 @@ public class MarkdownApi extends AbstractApi { ...@@ -17,7 +17,7 @@ public class MarkdownApi extends AbstractApi {
/** /**
* Render an arbitrary Markdown document. * Render an arbitrary Markdown document.
* *
* POST /api/v4/markdown * <pre><code>GitLab Endpoint: POST /api/v4/markdown</code></pre>
* *
* @param text text to be transformed * @param text text to be transformed
* @return a Markdown instance with transformed info * @return a Markdown instance with transformed info
...@@ -26,7 +26,7 @@ public class MarkdownApi extends AbstractApi { ...@@ -26,7 +26,7 @@ public class MarkdownApi extends AbstractApi {
*/ */
public Markdown getMarkdown(String text) throws GitLabApiException { public Markdown getMarkdown(String text) throws GitLabApiException {
if(!isApiVersion(ApiVersion.V4)){ if (!isApiVersion(ApiVersion.V4)) {
throw new GitLabApiException("Api version must be v4"); throw new GitLabApiException("Api version must be v4");
} }
......
...@@ -2,6 +2,7 @@ package org.gitlab4j.api; ...@@ -2,6 +2,7 @@ package org.gitlab4j.api;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
...@@ -23,159 +24,148 @@ public class MilestonesApi extends AbstractApi { ...@@ -23,159 +24,148 @@ public class MilestonesApi extends AbstractApi {
/** /**
* Get a list of project milestones. * Get a list of project milestones.
* *
* @param projectId the project ID to get the milestones for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return the milestones associated with the specified project * @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Milestone> getMilestones(Integer projectId) throws GitLabApiException { public List<Milestone> getMilestones(Object projectIdOrPath) throws GitLabApiException {
return (getMilestones(projectIdOrPath, getDefaultPerPage()).all());
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
} }
/** /**
* Get a list of project milestones. * Get a list of project milestones.
* *
* @param projectId the project ID to get the milestones for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param page the page number to get * @param page the page number to get
* @param perPage how many milestones per page * @param perPage how many milestones per page
* @return the milestones associated with the specified project * @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Milestone> getMilestones(Integer projectId, int page, int perPage) throws GitLabApiException { public List<Milestone> getMilestones(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
if (projectId == null) { /**
throw new RuntimeException("projectId cannot be null"); * Get a Page of project milestones.
} *
* @param projectIdOrPath the project in the form of an Integer(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 Pager<Milestone> getMilestones(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Milestone>(this, Milestone.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "milestones"));
}
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "milestones"); /**
return (response.readEntity(new GenericType<List<Milestone>>() {})); * Get a Stream of project milestones.
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream of the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public Stream<Milestone> getMilestonesStream(Object projectIdOrPath) throws GitLabApiException {
return (getMilestones(projectIdOrPath, getDefaultPerPage()).stream());
} }
/** /**
* Get a list of project milestones that have the specified state. * Get a list of project milestones that have the specified state.
* *
* @param projectId the project ID to get the milestones for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the milestone state * @param state the milestone state
* @return the milestones associated with the specified project and state * @return the milestones associated with the specified project and state
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Milestone> getMilestones(Integer projectId, MilestoneState state) throws GitLabApiException { public List<Milestone> getMilestones(Object projectIdOrPath, MilestoneState state) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Form formData = new GitLabApiForm().withParam("state", state).withParam(PER_PAGE_PARAM, getDefaultPerPage()); Form formData = new GitLabApiForm().withParam("state", state).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); Response response = get(Response.Status.OK, formData.asMap(),
return (response.readEntity(new GenericType<List<Milestone>>() { "projects", getProjectIdOrPath(projectIdOrPath), "milestones");
})); return (response.readEntity(new GenericType<List<Milestone>>() {}));
} }
/** /**
* Get a list of project milestones that have match the search string. * Get a list of project milestones that have match the search string.
* *
* @param projectId the project ID to get the milestones for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param search the search string * @param search the search string
* @return the milestones associated with the specified project * @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Milestone> getMilestones(Integer projectId, String search) throws GitLabApiException { public List<Milestone> getMilestones(Object projectIdOrPath, String search) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Form formData = new GitLabApiForm().withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage()); Form formData = new GitLabApiForm().withParam("search", search).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {})); return (response.readEntity(new GenericType<List<Milestone>>() {}));
} }
/** /**
* Get a list of project milestones that have the specified state and match the search string. * Get a list of project milestones that have the specified state and match the search string.
* *
* @param projectId the project ID to get the milestones for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the milestone state * @param state the milestone state
* @param search the search string * @param search the search string
* @return the milestones associated with the specified project * @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Milestone> getMilestones(Integer projectId, MilestoneState state, String search) throws GitLabApiException { public List<Milestone> getMilestones(Object projectIdOrPath, MilestoneState state, String search) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Form formData = new GitLabApiForm() Form formData = new GitLabApiForm()
.withParam("state", state) .withParam("state", state)
.withParam("search", search) .withParam("search", search)
.withParam(PER_PAGE_PARAM, getDefaultPerPage()); .withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones"); Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {})); return (response.readEntity(new GenericType<List<Milestone>>() {}));
} }
/** /**
* Get the specified milestone. * Get the specified milestone.
* *
* @param projectId the project ID to get the milestone for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the ID of the milestone tp get * @param milestoneId the ID of the milestone tp get
* @return a Milestone instance for the specified IDs * @return a Milestone instance for the specified IDs
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Milestone getMilestone(Integer projectId, int milestoneId) throws GitLabApiException { public Milestone getMilestone(Object projectIdOrPath, int milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
if (projectId == null) { "projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId);
return (response.readEntity(Milestone.class)); return (response.readEntity(Milestone.class));
} }
/** /**
* Get the list of issues associated with the specified milestone. * Get the list of issues associated with the specified milestone.
* *
* @param projectId the project ID to get the milestone issues for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the milestone ID to get the issues for * @param milestoneId the milestone ID to get the issues for
* @return a List of Issue for the milestone * @return a List of Issue for the milestone
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Issue> getIssues(Integer projectId, Integer milestoneId) throws GitLabApiException { public List<Issue> getIssues(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
if (projectId == null) { "projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId, "issues");
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "issues");
return (response.readEntity(new GenericType<List<Issue>>() {})); return (response.readEntity(new GenericType<List<Issue>>() {}));
} }
/** /**
* Get the list of merge requests associated with the specified milestone. * Get the list of merge requests associated with the specified milestone.
* *
* @param projectId the project ID to get the milestone merge requests for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the milestone ID to get the merge requests for * @param milestoneId the milestone ID to get the merge requests for
* @return a list of merge requests associated with the specified milestone * @return a list of merge requests associated with the specified milestone
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<MergeRequest> getMergeRequest(Integer projectId, Integer milestoneId) throws GitLabApiException { public List<MergeRequest> getMergeRequest(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
if (projectId == null) { "projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId, "merge_requests");
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {})); return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
} }
/** /**
* Create a milestone. * Create a milestone.
* *
* @param projectId the project ID to create a milestone for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param title the title for the milestone * @param title the title for the milestone
* @param description the description for the milestone * @param description the description for the milestone
* @param dueDate the due date for the milestone * @param dueDate the due date for the milestone
...@@ -183,71 +173,61 @@ public class MilestonesApi extends AbstractApi { ...@@ -183,71 +173,61 @@ public class MilestonesApi extends AbstractApi {
* @return the created Milestone instance * @return the created Milestone instance
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Milestone createMilestone(Integer projectId, String title, String description, Date dueDate, Date startDate) throws GitLabApiException { public Milestone createMilestone(Object projectIdOrPath, String title, String description, Date dueDate, Date startDate) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true) .withParam("title", title, true)
.withParam("description", description) .withParam("description", description)
.withParam("due_date", dueDate) .withParam("due_date", dueDate)
.withParam("start_date", startDate); .withParam("start_date", startDate);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "milestones"); Response response = post(Response.Status.CREATED, formData,
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(Milestone.class)); return (response.readEntity(Milestone.class));
} }
/** /**
* Close a milestone. * Close a milestone.
* *
* @param projectId the project ID of the milestone * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the milestone ID to close * @param milestoneId the milestone ID to close
* @return the closed Milestone instance * @return the closed Milestone instance
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Milestone closeMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException { public Milestone closeMilestone(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (milestoneId == null) { if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null"); throw new RuntimeException("milestoneId cannot be null");
} }
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.CLOSE); GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.CLOSE);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class)); return (response.readEntity(Milestone.class));
} }
/** /**
* Activate a milestone. * Activate a milestone.
* *
* @param projectId the project ID of the milestone * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the milestone ID to activate * @param milestoneId the milestone ID to activate
* @return the activated Milestone instance * @return the activated Milestone instance
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Milestone activateMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException { public Milestone activateMilestone(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (milestoneId == null) { if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null"); throw new RuntimeException("milestoneId cannot be null");
} }
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.ACTIVATE); GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.ACTIVATE);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class)); return (response.readEntity(Milestone.class));
} }
/** /**
* Update the specified milestone. * Update the specified milestone.
* *
* @param projectId the project ID of the milestone * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param milestoneId the milestone ID to update * @param milestoneId the milestone ID to update
* @param title the updated title for the milestone * @param title the updated title for the milestone
* @param description the updated description for the milestone * @param description the updated description for the milestone
...@@ -257,13 +237,9 @@ public class MilestonesApi extends AbstractApi { ...@@ -257,13 +237,9 @@ public class MilestonesApi extends AbstractApi {
* @return the updated Milestone instance * @return the updated Milestone instance
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public Milestone updateMilestone(Integer projectId, Integer milestoneId, String title, String description, public Milestone updateMilestone(Object projectIdOrPath, Integer milestoneId, String title, String description,
Date dueDate, Date startDate, MilestoneState milestoneState) throws GitLabApiException { Date dueDate, Date startDate, MilestoneState milestoneState) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (milestoneId == null) { if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null"); throw new RuntimeException("milestoneId cannot be null");
} }
...@@ -274,7 +250,8 @@ public class MilestonesApi extends AbstractApi { ...@@ -274,7 +250,8 @@ public class MilestonesApi extends AbstractApi {
.withParam("due_date", dueDate) .withParam("due_date", dueDate)
.withParam("start_date", startDate) .withParam("start_date", startDate)
.withParam("state_event", milestoneState); .withParam("state_event", milestoneState);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId); Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class)); return (response.readEntity(Milestone.class));
} }
} }
package org.gitlab4j.api; package org.gitlab4j.api;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
...@@ -20,53 +21,67 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -20,53 +21,67 @@ public class PipelineApi extends AbstractApi implements Constants {
/** /**
* Get a list of pipelines in a project. * Get a list of pipelines in a project.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list containing the pipelines for the specified project ID * @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public List<Pipeline> getPipelines(int projectId) throws GitLabApiException { public List<Pipeline> getPipelines(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "pipelines"); return (getPipelines(projectIdOrPath, getDefaultPerPage()).all());
return (response.readEntity(new GenericType<List<Pipeline>>() {}));
} }
/** /**
* Get a list of pipelines in a project in the specified page range. * Get a list of pipelines in a project in the specified page range.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param page the page to get * @param page the page to get
* @param perPage the number of Pipeline instances per page * @param perPage the number of Pipeline instances per page
* @return a list containing the pipelines for the specified project ID in the specified page range * @return a list containing the pipelines for the specified project ID in the specified page range
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public List<Pipeline> getPipelines(int projectId, int page, int perPage) throws GitLabApiException { public List<Pipeline> getPipelines(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "pipelines"); Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {})); return (response.readEntity(new GenericType<List<Pipeline>>() {}));
} }
/** /**
* Get a Pager of pipelines in a project. * Get a Pager of pipelines in a project.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of Pipeline instances that will be fetched per page * @param itemsPerPage the number of Pipeline instances that will be fetched per page
* @return a Pager containing the pipelines for the specified project ID * @return a Pager containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pager<Pipeline> getPipelines(int projectId, int itemsPerPage) throws GitLabApiException { public Pager<Pipeline> getPipelines(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Pipeline>(this, Pipeline.class, itemsPerPage, null, "projects", projectId, "pipelines")); return (new Pager<Pipeline>(this, Pipeline.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines"));
}
/**
* Get a Stream of pipelines in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Stream<Pipeline> getPipelinesStream(Object projectIdOrPath) throws GitLabApiException {
return (getPipelines(projectIdOrPath, getDefaultPerPage()).stream());
} }
/** /**
* Get a list of pipelines in a project. * Get a list of pipelines in a project.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS * @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED * @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines * @param ref the ref of pipelines
...@@ -78,29 +93,19 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -78,29 +93,19 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID * @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public List<Pipeline> getPipelines(int projectId, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors, public List<Pipeline> getPipelines(Object projectIdOrPath, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, PipelineOrderBy orderBy, SortOrder sort) throws GitLabApiException { String name, String username, PipelineOrderBy orderBy, SortOrder sort) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
.withParam("status", status)
.withParam("ref", ref)
.withParam("yaml_errors", yamlErrors)
.withParam("name", name)
.withParam("username", username)
.withParam("order_by", orderBy)
.withParam("sort", sort)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines"); return(getPipelines(projectIdOrPath, scope, status, ref, yamlErrors,
return (response.readEntity(new GenericType<List<Pipeline>>() {})); name, username, orderBy, sort, getDefaultPerPage()).all());
} }
/** /**
* Get a list of pipelines in a project in the specified page range. * Get a list of pipelines in a project in the specified page range.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS * @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED * @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines * @param ref the ref of pipelines
...@@ -114,7 +119,7 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -114,7 +119,7 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID * @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public List<Pipeline> getPipelines(int projectId, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors, public List<Pipeline> getPipelines(Object projectIdOrPath, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, PipelineOrderBy orderBy, SortOrder sort, int page, int perPage) throws GitLabApiException { String name, String username, PipelineOrderBy orderBy, SortOrder sort, int page, int perPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope) .withParam("scope", scope)
...@@ -128,16 +133,41 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -128,16 +133,41 @@ public class PipelineApi extends AbstractApi implements Constants {
.withParam("page", page) .withParam("page", page)
.withParam(PER_PAGE_PARAM, perPage); .withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "pipelines"); Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {})); return (response.readEntity(new GenericType<List<Pipeline>>() {}));
} }
/**
* Get a Stream of pipelines in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
* @param yamlErrors returns pipelines with invalid configurations
* @param name the name of the user who triggered pipelines
* @param username the username of the user who triggered pipelines
* @param orderBy order pipelines by ID, STATUS, REF, USER_ID (default: ID)
* @param sort sort pipelines in ASC or DESC order (default: DESC)
* @return a Stream containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Stream<Pipeline> getPipelinesStream(Object projectIdOrPath, PipelineScope scope, PipelineStatus status,
String ref, boolean yamlErrors, String name, String username, PipelineOrderBy orderBy, SortOrder sort) throws GitLabApiException {
return(getPipelines(projectIdOrPath, scope, status, ref, yamlErrors,
name, username, orderBy, sort, getDefaultPerPage()).stream());
}
/** /**
* Get a Pager of pipelines in a project. * Get a Pager of pipelines in a project.
* *
* GET /projects/:id/pipelines * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines</code></pre>
* *
* @param projectId the project ID to get the list of pipelines for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS * @param scope the scope of pipelines, one of: RUNNING, PENDING, FINISHED, BRANCHES, TAGS
* @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED * @param status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines * @param ref the ref of pipelines
...@@ -150,7 +180,7 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -150,7 +180,7 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID * @return a list containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pager<Pipeline> getPipelines(int projectId, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors, public Pager<Pipeline> getPipelines(Object projectIdOrPath, PipelineScope scope, PipelineStatus status, String ref, boolean yamlErrors,
String name, String username, PipelineOrderBy orderBy, SortOrder sort, int itemsPerPage) throws GitLabApiException { String name, String username, PipelineOrderBy orderBy, SortOrder sort, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope) .withParam("scope", scope)
...@@ -162,69 +192,70 @@ public class PipelineApi extends AbstractApi implements Constants { ...@@ -162,69 +192,70 @@ public class PipelineApi extends AbstractApi implements Constants {
.withParam("order_by", orderBy) .withParam("order_by", orderBy)
.withParam("sort", sort); .withParam("sort", sort);
return (new Pager<Pipeline>(this, Pipeline.class, itemsPerPage, formData.asMap(), "projects", projectId, "pipelines")); return (new Pager<Pipeline>(this, Pipeline.class, itemsPerPage, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines"));
} }
/** /**
* Get single pipelines in a project. * Get single pipelines in a project.
* *
* GET /projects/:id/pipelines/:pipeline_id * <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id</code></pre>
* *
* @param projectId the project ID to get the specified pipeline for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param pipelineId the pipeline ID to get * @param pipelineId the pipeline ID to get
* @return a single pipelines for the specified project ID * @return a single pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pipeline getPipeline(int projectId, int pipelineId) throws GitLabApiException { public Pipeline getPipeline(Object projectIdOrPath, int pipelineId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "pipelines", pipelineId); Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId);
return (response.readEntity(Pipeline.class)); return (response.readEntity(Pipeline.class));
} }
/** /**
* Create a pipelines in a project. * Create a pipelines in a project.
* *
* POST /projects/:id/pipeline * <pre><code>GitLab Endpoint: POST /projects/:id/pipeline</code></pre>
* *
* @param projectId the project ID to create a pipeline in * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref reference to commit * @param ref reference to commit
* @return a Pipeline instance with the newly created pipeline info * @return a Pipeline instance with the newly created pipeline info
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pipeline createPipeline(int projectId, String ref) throws GitLabApiException { public Pipeline createPipeline(Object projectIdOrPath, String ref) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("ref", ref); GitLabApiForm formData = new GitLabApiForm().withParam("ref", ref);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "pipeline"); Response response = post(Response.Status.CREATED, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "pipeline");
return (response.readEntity(Pipeline.class)); return (response.readEntity(Pipeline.class));
} }
/** /**
* Retry a job in specified pipelines in a project. * Retry a job in specified pipelines in a project.
* *
* POST /projects/:id/pipelines/:pipeline_id/retry * <pre><code>GitLab Endpoint: POST /projects/:id/pipelines/:pipeline_id/retry</code></pre>
* *
* @param projectId the project ID to retry a job for speficied pipeline * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param pipelineId the pipeline ID to retry a job from * @param pipelineId the pipeline ID to retry a job from
* @return pipeline instance which just retried * @return pipeline instance which just retried
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pipeline retryPipelineJob(int projectId, int pipelineId) throws GitLabApiException { public Pipeline retryPipelineJob(Object projectIdOrPath, int pipelineId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Response.Status.OK, formData, "projects", projectId, "pipelines", pipelineId, "retry"); Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "retry");
return (response.readEntity(Pipeline.class)); return (response.readEntity(Pipeline.class));
} }
/** /**
* Cancel jobs of specified pipelines in a project. * Cancel jobs of specified pipelines in a project.
* *
* POST /projects/:id/pipelines/:pipeline_id/cancel * <pre><code>GitLab Endpoint: POST /projects/:id/pipelines/:pipeline_id/cancel</code></pre>
* *
* @param projectId the project ID to cancel jobs for speficied pipeline * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param pipelineId the pipeline ID to cancel jobs * @param pipelineId the pipeline ID to cancel jobs
* @return pipeline instance which just canceled * @return pipeline instance which just canceled
* @throws GitLabApiException if any exception occurs during execution * @throws GitLabApiException if any exception occurs during execution
*/ */
public Pipeline cancelPipelineJobs(int projectId, int pipelineId) throws GitLabApiException { public Pipeline cancelPipelineJobs(Object projectIdOrPath, int pipelineId) throws GitLabApiException {
GitLabApiForm formData = null; GitLabApiForm formData = null;
Response response = post(Response.Status.OK, formData, "projects", projectId, "pipelines", pipelineId, "cancel"); Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId, "cancel");
return (response.readEntity(Pipeline.class)); return (response.readEntity(Pipeline.class));
} }
} }
package org.gitlab4j.api; package org.gitlab4j.api;
import org.gitlab4j.api.models.AccessLevel; import java.util.List;
import org.gitlab4j.api.models.ProtectedBranch; import java.util.stream.Stream;
import javax.ws.rs.core.Form; import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List;
import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.ProtectedBranch;
public class ProtectedBranchesApi extends AbstractApi { public class ProtectedBranchesApi extends AbstractApi {
...@@ -17,64 +18,90 @@ public class ProtectedBranchesApi extends AbstractApi { ...@@ -17,64 +18,90 @@ public class ProtectedBranchesApi extends AbstractApi {
/** /**
* Gets a list of protected branches from a project. * Gets a list of protected branches from a project.
* *
* GET /projects/:id/protected_branches * <pre><code>GitLab Endpoint: GET /projects/:id/protected_branches</code></pre>
* *
* @param projectId the ID of the project to protect * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return the list of protected branches for the project * @return the list of protected branches for the project
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<ProtectedBranch> getProtectedBranches(Integer projectId) throws GitLabApiException { public List<ProtectedBranch> getProtectedBranches(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "protected_branches"); return (getProtectedBranches(projectIdOrPath, this.getDefaultPerPage()).all());
return (response.readEntity(new GenericType<List<ProtectedBranch>>() { }
}));
/**
* Gets a Pager of protected branches from a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/protected_branches</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of instances that will be fetched per page
* @return the Pager of protected branches for the project
* @throws GitLabApiException if any exception occurs
*/
public Pager<ProtectedBranch> getProtectedBranches(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<ProtectedBranch>(this, ProtectedBranch.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "protected_branches"));
}
/**
* Gets a Stream of protected branches from a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/protected_branches</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return the Stream of protected branches for the project
* @throws GitLabApiException if any exception occurs
*/
public Stream<ProtectedBranch> getProtectedBranchesStream(Object projectIdOrPath) throws GitLabApiException {
return (getProtectedBranches(projectIdOrPath, this.getDefaultPerPage()).stream());
} }
/** /**
* Unprotects the given protected branch or wildcard protected branch. * Unprotects the given protected branch or wildcard protected branch.
* *
* DELETE /projects/:id/protected_branches/:name * <pre><code>GitLab Endpoint: DELETE /projects/:id/protected_branches/:name</code></pre>
* *
* @param projectId the ID of the project to un-protect * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param branchName the name of the branch to un-protect * @param branchName the name of the branch to un-protect
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void unprotectBranch(Integer projectId, String branchName) throws GitLabApiException { public void unprotectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null, "projects", projectId, "protected_branches", urlEncode(branchName)); delete(Response.Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "protected_branches", urlEncode(branchName));
} }
/** /**
* Protects a single repository branch or several project repository branches using a wildcard protected branch. * Protects a single repository branch or several project repository branches using a wildcard protected branch.
* *
* POST /projects/:id/protected_branches * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
* *
* @param projectId the ID of the project to protect * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param branchName the name of the branch to protect * @param branchName the name of the branch to protect
* @return the branch info for the protected branch * @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public ProtectedBranch protectBranch(Integer projectId, String branchName) throws GitLabApiException { public ProtectedBranch protectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException {
return protectBranch(projectId, branchName, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER); return protectBranch(projectIdOrPath, branchName, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER);
} }
/** /**
* Protects a single repository branch or several project repository branches using a wildcard protected branch. * Protects a single repository branch or several project repository branches using a wildcard protected branch.
* *
* POST /projects/:id/protected_branches * <pre><code>GitLab Endpoint: POST /projects/:id/protected_branches</code></pre>
* *
* @param projectId the ID of the project to protect * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param branchName the name of the branch to protect * @param branchName the name of the branch to protect
* @param pushAccessLevel Access levels allowed to push (defaults: 40, maintainer access level) * @param pushAccessLevel Access levels allowed to push (defaults: 40, maintainer access level)
* @param mergeAccessLevel Access levels allowed to merge (defaults: 40, maintainer access level) * @param mergeAccessLevel Access levels allowed to merge (defaults: 40, maintainer access level)
* @return the branch info for the protected branch * @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public ProtectedBranch protectBranch(Integer projectId, String branchName, AccessLevel pushAccessLevel, AccessLevel mergeAccessLevel) throws GitLabApiException { public ProtectedBranch protectBranch(Integer projectIdOrPath, String branchName, AccessLevel pushAccessLevel, AccessLevel mergeAccessLevel) throws GitLabApiException {
Form formData = new GitLabApiForm() Form formData = new GitLabApiForm()
.withParam("id", projectId, true)
.withParam("name", branchName, true) .withParam("name", branchName, true)
.withParam("push_access_level", pushAccessLevel.toValue(), false) .withParam("push_access_level", pushAccessLevel.toValue(), false)
.withParam("merge_access_level", mergeAccessLevel.toValue(), false); .withParam("merge_access_level", mergeAccessLevel.toValue(), false);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "protected_branches"); Response response = post(Response.Status.CREATED, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "protected_branches");
return (response.readEntity(ProtectedBranch.class)); return (response.readEntity(ProtectedBranch.class));
} }
} }
...@@ -2,6 +2,7 @@ package org.gitlab4j.api; ...@@ -2,6 +2,7 @@ package org.gitlab4j.api;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
...@@ -18,23 +19,10 @@ public class SnippetsApi extends AbstractApi { ...@@ -18,23 +19,10 @@ public class SnippetsApi extends AbstractApi {
super(gitLabApi); super(gitLabApi);
} }
/**
* Get a Pager of the authenticated user's snippets.
*
* GET /snippets
*
* @param itemsPerPage the number of snippets per page
* @return the Pager of snippets
* @throws GitLabApiException if any exception occurs
*/
public Pager<Snippet> getSnippets(int itemsPerPage) throws GitLabApiException {
return (new Pager<Snippet>(this, Snippet.class, itemsPerPage, null, "snippets"));
}
/** /**
* Get a list of the authenticated user's snippets. * Get a list of the authenticated user's snippets.
* *
* GET /snippets * <pre><code>GitLab Endpoint: GET /snippets</code></pre>
* *
* @param downloadContent indicating whether to download the snippet content * @param downloadContent indicating whether to download the snippet content
* @return a list of authenticated user's snippets * @return a list of authenticated user's snippets
...@@ -57,19 +45,44 @@ public class SnippetsApi extends AbstractApi { ...@@ -57,19 +45,44 @@ public class SnippetsApi extends AbstractApi {
/** /**
* Get a list of the authenticated user's snippets. * Get a list of the authenticated user's snippets.
* *
* GET /snippets * <pre><code>GitLab Endpoint: GET /snippets</code></pre>
* *
* @return a list of authenticated user's snippets * @return a list of authenticated user's snippets
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<Snippet> getSnippets() throws GitLabApiException { public List<Snippet> getSnippets() throws GitLabApiException {
return getSnippets(false); return (getSnippets(getDefaultPerPage()).all());
}
/**
* Get a Pager of the authenticated user's snippets.
*
* <pre><code>GitLab Endpoint: GET /snippets</code></pre>
*
* @param itemsPerPage the number of snippets per page
* @return the Pager of snippets
* @throws GitLabApiException if any exception occurs
*/
public Pager<Snippet> getSnippets(int itemsPerPage) throws GitLabApiException {
return (new Pager<Snippet>(this, Snippet.class, itemsPerPage, null, "snippets"));
}
/**
* Get a Stream of the authenticated user's snippets.
*
* <pre><code>GitLab Endpoint: GET /snippets</code></pre>
*
* @return a Stream of authenticated user's snippets
* @throws GitLabApiException if any exception occurs
*/
public Stream<Snippet> getSnippetsStream() throws GitLabApiException {
return (getSnippets(getDefaultPerPage()).stream());
} }
/** /**
* Get the content of a Snippet. * Get the content of a Snippet.
* *
* GET /snippets/:id/raw * <pre><code>GitLab Endpoint: GET /snippets/:id/raw</code></pre>
* *
* @param snippetId the snippet ID to remove * @param snippetId the snippet ID to remove
* @return the content of snippet * @return the content of snippet
...@@ -118,19 +131,19 @@ public class SnippetsApi extends AbstractApi { ...@@ -118,19 +131,19 @@ public class SnippetsApi extends AbstractApi {
/** /**
* Get a specific snippet as an Optional instance. * Get a specific snippet as an Optional instance.
* *
* GET /snippets/:snippet_id * <pre><code>GitLab Endpoint: GET /snippets/:snippet_id</code></pre>
* *
* @param snippetId the ID of the snippet to get the Optional instance for * @param snippetId the ID of the snippet to get the Optional instance for
* @return the specified Snippet as an Optional instance * @return the specified Snippet as an Optional instance
*/ */
public Optional<Snippet> getOptionalSnippet( Integer snippetId) { public Optional<Snippet> getOptionalSnippet(Integer snippetId) {
return (getOptionalSnippet(snippetId, false)); return (getOptionalSnippet(snippetId, false));
} }
/** /**
* Get a specific snippet as an Optional instance. * Get a specific snippet as an Optional instance.
* *
* GET /snippets/:snippet_id * <pre><code>GitLab Endpoint: GET /snippets/:snippet_id</code></pre>
* *
* @param snippetId the ID of the snippet to get the Optional instance for * @param snippetId the ID of the snippet to get the Optional instance for
* @param downloadContent indicating whether to download the snippet content * @param downloadContent indicating whether to download the snippet content
...@@ -187,7 +200,7 @@ public class SnippetsApi extends AbstractApi { ...@@ -187,7 +200,7 @@ public class SnippetsApi extends AbstractApi {
/** /**
* Removes Snippet. * Removes Snippet.
* *
* DELETE /snippets/:id * <pre><code>GitLab Endpoint: DELETE /snippets/:id</code></pre>
* *
* @param snippetId the snippet ID to remove * @param snippetId the snippet ID to remove
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
......
package org.gitlab4j.api; package org.gitlab4j.api;
import java.util.List; import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType; import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
...@@ -19,22 +20,21 @@ public class SystemHooksApi extends AbstractApi { ...@@ -19,22 +20,21 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Get a list of all system hooks. This method requires admin access. * Get a list of all system hooks. This method requires admin access.
* Only returns the first page. This method requires admin access.
* *
* <code>GET /hooks</code> * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
* *
* @return a list of SystemHookEvent * @return a list of SystemHookEvent
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<SystemHook> getSystemHooks() throws GitLabApiException { public List<SystemHook> getSystemHooks() throws GitLabApiException {
return (getSystemHooks(1, getDefaultPerPage())); return (getSystemHooks(getDefaultPerPage()).all());
} }
/** /**
* Get a list of all system hooks using the specified page and per page settings. * Get a list of all system hooks using the specified page and per page settings.
* This method requires admin access. * This method requires admin access.
* *
* <code>GET /hooks</code> * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
* *
* @param page the page to get * @param page the page to get
* @param perPage the number of deploy keys per page * @param perPage the number of deploy keys per page
...@@ -49,7 +49,7 @@ public class SystemHooksApi extends AbstractApi { ...@@ -49,7 +49,7 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Get a Pager of all system hooks. This method requires admin access. * Get a Pager of all system hooks. This method requires admin access.
* *
* <code>GET /hooks</code> * <pre><code>GitLab Endpoint: GET /hooks</code></pre>
* *
* @param itemsPerPage the number of SystemHookEvent instances that will be fetched per page * @param itemsPerPage the number of SystemHookEvent instances that will be fetched per page
* @return a Pager of SystemHookEvent * @return a Pager of SystemHookEvent
...@@ -59,10 +59,22 @@ public class SystemHooksApi extends AbstractApi { ...@@ -59,10 +59,22 @@ public class SystemHooksApi extends AbstractApi {
return (new Pager<SystemHook>(this, SystemHook.class, itemsPerPage, null, "hooks")); return (new Pager<SystemHook>(this, SystemHook.class, itemsPerPage, null, "hooks"));
} }
/**
* Get a Stream of all system hooks. This method requires admin access.
*
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
*
* @return a Stream of SystemHookEvent
* @throws GitLabApiException if any exception occurs
*/
public Stream<SystemHook> getSystemHookStream() throws GitLabApiException {
return (getSystemHooks(getDefaultPerPage()).stream());
}
/** /**
* Add a new system hook. This method requires admin access. * Add a new system hook. This method requires admin access.
* *
* <code>POST /hooks</code> * <pre><code>GitLab Endpoint: POST /hooks</code></pre>
* *
* @param url the hook URL, required * @param url the hook URL, required
* @param token secret token to validate received payloads, optional * @param token secret token to validate received payloads, optional
...@@ -92,7 +104,7 @@ public class SystemHooksApi extends AbstractApi { ...@@ -92,7 +104,7 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Deletes a system hook. This method requires admin access. * Deletes a system hook. This method requires admin access.
* *
* <code>DELETE /hooks/:hook_id</code> * <pre><code>GitLab Endpoint: DELETE /hooks/:hook_id</code></pre>
* *
* @param hook the SystemHook instance to delete * @param hook the SystemHook instance to delete
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
...@@ -109,7 +121,7 @@ public class SystemHooksApi extends AbstractApi { ...@@ -109,7 +121,7 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Deletes a system hook. This method requires admin access. * Deletes a system hook. This method requires admin access.
* *
* <code>DELETE /hooks/:hook_id</code> * <pre><code>GitLab Endpoint: DELETE /hooks/:hook_id</code></pre>
* *
* @param hookId the ID of the system hook to delete * @param hookId the ID of the system hook to delete
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
...@@ -127,7 +139,7 @@ public class SystemHooksApi extends AbstractApi { ...@@ -127,7 +139,7 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Test a system hook. This method requires admin access. * Test a system hook. This method requires admin access.
* *
* <code>GET /hooks/:hook_id</code> * <pre><code>GitLab Endpoint: GET /hooks/:hook_id</code></pre>
* *
* @param hook the SystemHookEvent instance to test * @param hook the SystemHookEvent instance to test
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
...@@ -144,7 +156,7 @@ public class SystemHooksApi extends AbstractApi { ...@@ -144,7 +156,7 @@ public class SystemHooksApi extends AbstractApi {
/** /**
* Test a system hook. This method requires admin access. * Test a system hook. This method requires admin access.
* *
* <code>GET /hooks/:hook_id</code> * <pre><code>GitLab Endpoint: GET /hooks/:hook_id</code></pre>
* *
* @param hookId the ID of the system hook to test * @param hookId the ID of the system hook to test
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
......
...@@ -29,10 +29,11 @@ import javax.ws.rs.core.GenericType; ...@@ -29,10 +29,11 @@ import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response; import javax.ws.rs.core.Response;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
import java.util.stream.Stream;
/** /**
* @author shuklaalok7 (alok@clay.fish) * This class implements the client side API for the GitLab Wikis API.
* @since v4.8.21 2018-06-5 1:26 AM IST * See <a href="https://docs.gitlab.com/ce/api/wikis.html">Wikis API at GitLab</a> for more information.
*/ */
public class WikisApi extends AbstractApi { public class WikisApi extends AbstractApi {
...@@ -42,75 +43,63 @@ public class WikisApi extends AbstractApi { ...@@ -42,75 +43,63 @@ public class WikisApi extends AbstractApi {
} }
/** /**
* Get a list of pages in project wiki. This only returns the first page of wiki-pages. * Get a list of pages in project wiki.
* *
* GET /projects/:id/wikis * <pre><code>GitLab Endpoint: GET /projects/:id/wikis</code></pre>
* *
* @param projectId the project ID to get the wiki-pages for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list of pages in the project's wiki * @return a list of pages in the project's wiki
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<WikiPage> getPages(Integer projectId) throws GitLabApiException { public List<WikiPage> getPages(Object projectIdOrPath) throws GitLabApiException {
return getPages(projectId, 1, this.getDefaultPerPage()); return (getPages(projectIdOrPath, 1, getDefaultPerPage()));
} }
/** /**
* Get a list of project snippets. This only returns the first page of snippets. * Get a list of pages in project wiki for the specified page.
* *
* GET /projects/:id/wikis * <pre><code>GitLab Endpoint: GET /projects/:id/wikis</code></pre>
* *
* @param projectId the project ID to get the wiki pages for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param page the page to get * @param page the page to get
* @param perPage the number of wiki-pages per page * @param perPage the number of wiki-pages per page
* @return a list of pages in project's wiki for the specified range * @return a list of pages in project's wiki for the specified range
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public List<WikiPage> getPages(Integer projectId, int page, int perPage) throws GitLabApiException { public List<WikiPage> getPages(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis"); Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "wikis");
return response.readEntity(new GenericType<List<WikiPage>>() {}); return response.readEntity(new GenericType<List<WikiPage>>() {});
} }
/**
* Get a Pager of project's wiki pages.
*
* GET /projects/:id/wikis
*
* @param projectId the project ID to get the wiki-pages for
* @param itemsPerPage the number of wiki-pages per page
* @return the Pager of wiki-pages
* @throws GitLabApiException if any exception occurs
*/
public Pager<WikiPage> getPages(Integer projectId, int itemsPerPage) throws GitLabApiException {
return (new Pager<>(this, WikiPage.class, itemsPerPage, null, "projects", projectId, "wikis"));
}
/** /**
* Get a single page of project wiki. * Get a single page of project wiki.
* *
* GET /projects/:id/wikis/:slug * <pre><code>GitLab Endpoint: GET /projects/:id/wikis/:slug</code></pre>
* *
* @param projectId the project ID to get the wiki page for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param slug the slug of the project's wiki page * @param slug the slug of the project's wiki page
* @return the specified project Snippet * @return the specified project Snippet
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public WikiPage getPage(Integer projectId, String slug) throws GitLabApiException { public WikiPage getPage(Object projectIdOrPath, String slug) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug); Response response = get(Response.Status.OK, null,
"projects", getProjectIdOrPath(projectIdOrPath), "wikis", slug);
return (response.readEntity(WikiPage.class)); return (response.readEntity(WikiPage.class));
} }
/** /**
* Get a single page of project wiki as an Optional instance. * Get a single page of project wiki as an Optional instance.
* *
* GET /projects/:id/wikis/:slug * <pre><code>GitLab Endpoint: GET /projects/:id/wikis/:slug</code></pre>
* *
* @param projectId the project ID to get the snippet for * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param slug the slug of the project's wiki page * @param slug the slug of the project's wiki page
* @return the specified project Snippet as an Optional instance * @return the specified project Snippet as an Optional instance
*/ */
public Optional<WikiPage> getOptionalPage(Integer projectId, String slug) { public Optional<WikiPage> getOptionalPage(Object projectIdOrPath, String slug) {
try { try {
return (Optional.ofNullable(getPage(projectId, slug))); return (Optional.ofNullable(getPage(projectIdOrPath, slug)));
} catch (GitLabApiException glae) { } catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae)); return (GitLabApi.createOptionalFromException(glae));
} }
...@@ -119,44 +108,45 @@ public class WikisApi extends AbstractApi { ...@@ -119,44 +108,45 @@ public class WikisApi extends AbstractApi {
/** /**
* Creates a new project wiki page. The user must have permission to create new wiki page. * Creates a new project wiki page. The user must have permission to create new wiki page.
* *
* POST /projects/:id/wikis * <pre><code>GitLab Endpoint: POST /projects/:id/wikis</code></pre>
* *
* @param projectId the ID of the project owned by the authenticated user, required * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param title the title of a snippet, required * @param title the title of a snippet, required
* @param content the content of a wiki page, required * @param content the content of a wiki page, required
* @return a WikiPage instance with info on the created page * @return a WikiPage instance with info on the created page
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public WikiPage createPage(Integer projectId, String title, String content) throws GitLabApiException { public WikiPage createPage(Object projectIdOrPath, String title, String content) throws GitLabApiException {
// one of title or content is required // one of title or content is required
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title) .withParam("title", title)
.withParam("content", content); .withParam("content", content);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "wikis"); Response response = post(Response.Status.CREATED, formData,
"projects", getProjectIdOrPath(projectIdOrPath), "wikis");
return (response.readEntity(WikiPage.class)); return (response.readEntity(WikiPage.class));
} }
/** /**
* Updates an existing project wiki page. The user must have permission to change an existing wiki page. * Updates an existing project wiki page. The user must have permission to change an existing wiki page.
* *
* PUT /projects/:id/wikis/:slug * <pre><code>GitLab Endpoint: PUT /projects/:id/wikis/:slug</code></pre>
* *
* @param projectId the ID of the project owned by the authenticated user, required * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param slug the slug of the project's wiki page, required * @param slug the slug of the project's wiki page, required
* @param title the title of a snippet, optional * @param title the title of a snippet, optional
* @param content the content of a page, optional. Either title or content must be supplied. * @param content the content of a page, optional. Either title or content must be supplied.
* @return a WikiPage instance with info on the updated page * @return a WikiPage instance with info on the updated page
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public WikiPage updatePage(Integer projectId, String slug, String title, String content) throws GitLabApiException { public WikiPage updatePage(Object projectIdOrPath, String slug, String title, String content) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm() GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title) .withParam("title", title)
.withParam("slug", slug, true) .withParam("slug", slug, true)
.withParam("content", content); .withParam("content", content);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "wikis", slug); Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "wikis", slug);
return (response.readEntity(WikiPage.class)); return (response.readEntity(WikiPage.class));
} }
...@@ -164,14 +154,13 @@ public class WikisApi extends AbstractApi { ...@@ -164,14 +154,13 @@ public class WikisApi extends AbstractApi {
* Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does * Deletes an existing project wiki page. This is an idempotent function and deleting a non-existent page does
* not cause an error. * not cause an error.
* *
* DELETE /projects/:id/wikis/:slug * <pre><code>GitLab Endpoint: DELETE /projects/:id/wikis/:slug</code></pre>
* *
* @param projectId the project ID * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param slug the slug of the project's wiki page * @param slug the slug of the project's wiki page
* @throws GitLabApiException if any exception occurs * @throws GitLabApiException if any exception occurs
*/ */
public void deletePage(Integer projectId, String slug) throws GitLabApiException { public void deletePage(Object projectIdOrPath, String slug) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug); delete(Response.Status.NO_CONTENT, null, "projects", getProjectIdOrPath(projectIdOrPath), "wikis", slug);
} }
} }
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