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;
import java.util.Date;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
......@@ -29,7 +30,7 @@ public class EpicsApi extends AbstractApi {
/**
* Gets all epics of the requested group and its subgroups.
*
*
* <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
......@@ -37,7 +38,7 @@ public class EpicsApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
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 {
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.
*
......@@ -87,7 +101,7 @@ public class EpicsApi extends AbstractApi {
*/
public List<Epic> getEpics(Object groupIdOrPath, Integer authorId, String labels, EpicOrderBy orderBy,
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 {
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.
*
......@@ -305,11 +339,10 @@ public class EpicsApi extends AbstractApi {
public void deleteEpic(Object groupIdOrPath, Integer epicIid) throws GitLabApiException {
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.
*
*
* <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
......@@ -318,13 +351,13 @@ public class EpicsApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
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
* using the specified page and per page setting.
*
*
* <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
......@@ -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.
*
*
* <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
......@@ -354,6 +387,20 @@ public class EpicsApi extends AbstractApi {
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
* it is unassigned from that epic.
......
......@@ -17,7 +17,7 @@ public class MarkdownApi extends AbstractApi {
/**
* 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
* @return a Markdown instance with transformed info
......@@ -26,7 +26,7 @@ public class MarkdownApi extends AbstractApi {
*/
public Markdown getMarkdown(String text) throws GitLabApiException {
if(!isApiVersion(ApiVersion.V4)){
if (!isApiVersion(ApiVersion.V4)) {
throw new GitLabApiException("Api version must be v4");
}
......
......@@ -2,6 +2,7 @@ package org.gitlab4j.api;
import java.util.Date;
import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
......@@ -23,159 +24,148 @@ public class MilestonesApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getMilestones(Integer projectId) throws GitLabApiException {
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>>() {}));
public List<Milestone> getMilestones(Object projectIdOrPath) throws GitLabApiException {
return (getMilestones(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* 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 perPage how many milestones per page
* @return the milestones associated with the specified project
* @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.
*
* @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
* @return the milestones associated with the specified project and state
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getMilestones(Integer projectId, MilestoneState state) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public List<Milestone> getMilestones(Object projectIdOrPath, MilestoneState state) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("state", state).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {
}));
Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<Milestone>>() {}));
}
/**
* 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
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getMilestones(Integer projectId, String search) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public List<Milestone> getMilestones(Object projectIdOrPath, String search) throws GitLabApiException {
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>>() {}));
}
/**
* 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 search the search string
* @return the milestones associated with the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<Milestone> getMilestones(Integer projectId, MilestoneState state, String search) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public List<Milestone> getMilestones(Object projectIdOrPath, MilestoneState state, String search) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state)
.withParam("search", search)
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones");
Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(new GenericType<List<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
* @return a Milestone instance for the specified IDs
* @throws GitLabApiException if any exception occurs
*/
public Milestone getMilestone(Integer projectId, int milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId);
public Milestone getMilestone(Object projectIdOrPath, int 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.
*
* @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
* @return a List of Issue for the milestone
* @throws GitLabApiException if any exception occurs
*/
public List<Issue> getIssues(Integer projectId, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "issues");
public List<Issue> getIssues(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId, "issues");
return (response.readEntity(new GenericType<List<Issue>>() {}));
}
/**
* 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
* @return a list of merge requests associated with the specified milestone
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequest(Integer projectId, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "milestones", milestoneId, "merge_requests");
public List<MergeRequest> getMergeRequest(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId, "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
}
/**
* 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 description the description for the milestone
* @param dueDate the due date for the milestone
......@@ -183,71 +173,61 @@ public class MilestonesApi extends AbstractApi {
* @return the created Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone createMilestone(Integer projectId, String title, String description, Date dueDate, Date startDate) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
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", projectId, "milestones");
Response response = post(Response.Status.CREATED, formData,
"projects", getProjectIdOrPath(projectIdOrPath), "milestones");
return (response.readEntity(Milestone.class));
}
/**
* 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
* @return the closed Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone closeMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public Milestone closeMilestone(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.CLOSE);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId);
Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* 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
* @return the activated Milestone instance
* @throws GitLabApiException if any exception occurs
*/
public Milestone activateMilestone(Integer projectId, Integer milestoneId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public Milestone activateMilestone(Object projectIdOrPath, Integer milestoneId) throws GitLabApiException {
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm().withParam("state_event", MilestoneState.ACTIVATE);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "milestones", milestoneId);
Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "milestones", milestoneId);
return (response.readEntity(Milestone.class));
}
/**
* 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 title the updated title for the milestone
* @param description the updated description for the milestone
......@@ -257,13 +237,9 @@ public class MilestonesApi extends AbstractApi {
* @return the updated Milestone instance
* @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 {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (milestoneId == null) {
throw new RuntimeException("milestoneId cannot be null");
}
......@@ -274,7 +250,8 @@ public class MilestonesApi extends AbstractApi {
.withParam("due_date", dueDate)
.withParam("start_date", startDate)
.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));
}
}
package org.gitlab4j.api;
import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
......@@ -20,53 +21,67 @@ public class PipelineApi extends AbstractApi implements Constants {
/**
* 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
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Pipeline> getPipelines(int projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects", projectId, "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {}));
public List<Pipeline> getPipelines(Object projectIdOrPath) throws GitLabApiException {
return (getPipelines(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* 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 perPage the number of Pipeline instances per page
* @return a list containing the pipelines for the specified project ID in the specified page range
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Pipeline> getPipelines(int projectId, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "pipelines");
public List<Pipeline> getPipelines(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "pipelines");
return (response.readEntity(new GenericType<List<Pipeline>>() {}));
}
/**
* 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
* @return a Pager containing the pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Pager<Pipeline> getPipelines(int projectId, int itemsPerPage) throws GitLabApiException {
return (new Pager<Pipeline>(this, Pipeline.class, itemsPerPage, null, "projects", projectId, "pipelines"));
public Pager<Pipeline> getPipelines(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
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 /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 status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
......@@ -78,29 +93,19 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID
* @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 {
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 (response.readEntity(new GenericType<List<Pipeline>>() {}));
return(getPipelines(projectIdOrPath, scope, status, ref, yamlErrors,
name, username, orderBy, sort, getDefaultPerPage()).all());
}
/**
* 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 status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
......@@ -114,7 +119,7 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID
* @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 {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
......@@ -128,16 +133,41 @@ public class PipelineApi extends AbstractApi implements Constants {
.withParam("page", page)
.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>>() {}));
}
/**
* 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 /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 status the status of pipelines, one of: RUNNING, PENDING, SUCCESS, FAILED, CANCELED, SKIPPED
* @param ref the ref of pipelines
......@@ -150,7 +180,7 @@ public class PipelineApi extends AbstractApi implements Constants {
* @return a list containing the pipelines for the specified project ID
* @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 {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope)
......@@ -162,69 +192,70 @@ public class PipelineApi extends AbstractApi implements Constants {
.withParam("order_by", orderBy)
.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 /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
* @return a single pipelines for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Pipeline getPipeline(int projectId, int pipelineId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "pipelines", pipelineId);
public Pipeline getPipeline(Object projectIdOrPath, int pipelineId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "pipelines", pipelineId);
return (response.readEntity(Pipeline.class));
}
/**
* 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
* @return a Pipeline instance with the newly created pipeline info
* @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);
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));
}
/**
* 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
* @return pipeline instance which just retried
* @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;
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));
}
/**
* 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
* @return pipeline instance which just canceled
* @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;
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));
}
}
package org.gitlab4j.api;
import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.ProtectedBranch;
import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
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 {
......@@ -17,64 +18,90 @@ public class ProtectedBranchesApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
*/
public List<ProtectedBranch> getProtectedBranches(Integer projectId) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "protected_branches");
return (response.readEntity(new GenericType<List<ProtectedBranch>>() {
}));
public List<ProtectedBranch> getProtectedBranches(Object projectIdOrPath) throws GitLabApiException {
return (getProtectedBranches(projectIdOrPath, this.getDefaultPerPage()).all());
}
/**
* 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.
*
* 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
* @throws GitLabApiException if any exception occurs
*/
public void unprotectBranch(Integer projectId, String branchName) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null, "projects", projectId, "protected_branches", urlEncode(branchName));
public void unprotectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException {
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.
*
* 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
* @return the branch info for the protected branch
* @throws GitLabApiException if any exception occurs
*/
public ProtectedBranch protectBranch(Integer projectId, String branchName) throws GitLabApiException {
return protectBranch(projectId, branchName, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER);
public ProtectedBranch protectBranch(Integer projectIdOrPath, String branchName) throws GitLabApiException {
return protectBranch(projectIdOrPath, branchName, AccessLevel.MAINTAINER, AccessLevel.MAINTAINER);
}
/**
* 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 branchName the name of the branch to protect
* @param pushAccessLevel Access levels allowed to push (defaults: 40, maintainer access level)
* @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 pushAccessLevel Access levels allowed to push (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
* @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()
.withParam("id", projectId, true)
.withParam("name", branchName, true)
.withParam("push_access_level", pushAccessLevel.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));
}
}
......@@ -8,6 +8,7 @@ import org.gitlab4j.api.models.RunnerDetail;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.stream.Stream;
/**
* This class provides an entry point to all the GitLab API repository files calls.
......@@ -21,32 +22,57 @@ public class RunnersApi extends AbstractApi {
/**
* Get a list of all available runners available to the user.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @return List of Runners
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getRunners() throws GitLabApiException {
return getRunners(null, null, null);
return (getRunners(null, getDefaultPerPage()).all());
}
/**
* Get a Stream of all available runners available to the user.
*
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @return Stream of Runners
* @throws GitLabApiException if any exception occurs
*/
public Stream<Runner> getRunnersStream() throws GitLabApiException {
return (getRunners(null, getDefaultPerPage()).stream());
}
/**
* Get a list of all available runners available to the user with pagination support.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @return List of Runners
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getRunners(Runner.RunnerStatus scope) throws GitLabApiException {
return getRunners(scope, null, null);
return (getRunners(scope, getDefaultPerPage()).all());
}
/**
* Get a Stream of all available runners available to the user with pagination support.
*
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @return Stream of Runners
* @throws GitLabApiException if any exception occurs
*/
public Stream<Runner> getRunnersStream(Runner.RunnerStatus scope) throws GitLabApiException {
return (getRunners(scope, getDefaultPerPage()).stream());
}
/**
* Get a list of all available runners available to the user with pagination support.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param page The page offset of runners
* @param perPage The number of runners to get after the page offset
......@@ -60,7 +86,7 @@ public class RunnersApi extends AbstractApi {
/**
* Get a list of specific runners available to the user.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param page The page offset of runners
......@@ -81,61 +107,85 @@ public class RunnersApi extends AbstractApi {
/**
* Get a list of all available runners available to the user.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param itemsPerPage the number of Runner instances that will be fetched per page
* @return a Pager containing the Runners for the user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Runner> getRunners(int itemsPerPage) throws GitLabApiException {
return getRunners(null, itemsPerPage);
return (getRunners(null, itemsPerPage));
}
/**
* Get a list of specific runners available to the user.
*
* GET /runners
* <pre><code>GitLab Endpoint: GET /runners</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param scope the scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param itemsPerPage The number of Runner instances that will be fetched per page
* @return a Pager containing the Runners for the user
* @throws GitLabApiException if any exception occurs
*/
public Pager<Runner> getRunners(Runner.RunnerStatus scope, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope, false);
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope, false);
return (new Pager<>(this, Runner.class, itemsPerPage, formData.asMap(), "runners"));
}
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @return List of Runners
* @return a List of Runners
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getAllRunners() throws GitLabApiException {
return getAllRunners(null, null, null);
return (getAllRunners(null, getDefaultPerPage()).all());
}
/**
* Get a Stream of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @return a Stream of Runners
* @throws GitLabApiException if any exception occurs
*/
public Stream<Runner> getAllRunnersStream() throws GitLabApiException {
return (getAllRunners(null, getDefaultPerPage()).stream());
}
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @return List of Runners
* @return a List of Runners
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getAllRunners(Runner.RunnerStatus scope) throws GitLabApiException {
return getAllRunners(scope, null, null);
return (getAllRunners(scope, getDefaultPerPage()).all());
}
/**
* Get a Stream of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @return a Stream of Runners
* @throws GitLabApiException if any exception occurs
*/
public Stream<Runner> getAllRunnersStream(Runner.RunnerStatus scope) throws GitLabApiException {
return (getAllRunners(scope, getDefaultPerPage()).stream());
}
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param page The page offset of runners
* @param perPage The number of runners to get after the page offset
......@@ -143,13 +193,13 @@ public class RunnersApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getAllRunners(int page, int perPage) throws GitLabApiException {
return getAllRunners(null, page, perPage);
return (getAllRunners(null, page, perPage));
}
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param page The page offset of runners
......@@ -163,14 +213,13 @@ public class RunnersApi extends AbstractApi {
.withParam("page", page, false)
.withParam("per_page", perPage, false);
Response response = get(Response.Status.OK, formData.asMap(), "runners", "all");
return (response.readEntity(new GenericType<List<Runner>>() {
}));
return (response.readEntity(new GenericType<List<Runner>>() {}));
}
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param itemsPerPage The number of Runner instances that will be fetched per page
* @return List of Runners
......@@ -183,33 +232,33 @@ public class RunnersApi extends AbstractApi {
/**
* Get a list of all runners in the GitLab instance (specific and shared). Access is restricted to users with admin privileges.
*
* GET /runners/all
* <pre><code>GitLab Endpoint: GET /runners/all</code></pre>
*
* @param scope The scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param scope the scope of specific runners to show, one of: active, paused, online; showing all runners null
* @param itemsPerPage The number of Runner instances that will be fetched per page
* @return a Pager containing the Runners
* @throws GitLabApiException if any exception occurs
*/
public Pager<Runner> getAllRunners(Runner.RunnerStatus scope, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("scope", scope, false);
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope, false);
return (new Pager<>(this, Runner.class, itemsPerPage, formData.asMap(), "runners"));
}
/**
* Get details of a runner.
*
* GET /runners/:id
* <pre><code>GitLab Endpoint: GET /runners/:id</code></pre>
*
* @param runnerId Runner id to get details for
* @return RunnerDetail instance.
* @throws GitLabApiException if any exception occurs
*/
public RunnerDetail getRunnerDetail(Integer runnerId) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
Response response = get(Response.Status.OK, null, "runners", runnerId);
return (response.readEntity(RunnerDetail.class));
}
......@@ -217,7 +266,7 @@ public class RunnersApi extends AbstractApi {
/**
* Update details of a runner.
*
* PUT /runners/:id
* <pre><code>GitLab Endpoint: PUT /runners/:id</code></pre>
*
* @param runnerId The ID of a runner
* @param description The description of a runner
......@@ -234,6 +283,7 @@ public class RunnersApi extends AbstractApi {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("description", description, false)
.withParam("active", active, false)
......@@ -248,12 +298,13 @@ public class RunnersApi extends AbstractApi {
/**
* Remove a runner.
*
* DELETE /runners/:id
* <pre><code>GitLab Endpoint: DELETE /runners/:id</code></pre>
*
* @param runnerId The ID of a runner
* @throws GitLabApiException if any exception occurs
*/
public void removeRunner(Integer runnerId) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
......@@ -264,23 +315,34 @@ public class RunnersApi extends AbstractApi {
/**
* List jobs that are being processed or were processed by specified Runner.
*
* GET /runners/:id/jobs
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @return List jobs that are being processed or were processed by specified Runner
* @throws GitLabApiException if any exception occurs
*/
public List<Job> getJobs(Integer runnerId) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
return getJobs(runnerId, null);
return (getJobs(runnerId, null, getDefaultPerPage()).all());
}
/**
* Get a Stream of jobs that are being processed or were processed by specified Runner.
*
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @return a Stream of jobs that are being processed or were processed by specified Runner
* @throws GitLabApiException if any exception occurs
*/
public Stream<Job> getJobsStream(Integer runnerId) throws GitLabApiException {
return (getJobs(runnerId, null, getDefaultPerPage()).stream());
}
/**
* List jobs that are being processed or were processed by specified Runner.
*
* GET /runners/:id/jobs
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @param status Status of the job; one of: running, success, failed, canceled
......@@ -288,20 +350,27 @@ public class RunnersApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public List<Job> getJobs(Integer runnerId, JobStatus status) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("status", status, false);
Response response = get(Response.Status.OK, formData.asMap(), "runners", runnerId, "jobs");
return (response.readEntity(new GenericType<List<Job>>() {
}));
return (getJobs(runnerId, status, getDefaultPerPage()).all());
}
/**
* Get a Stream of jobs that are being processed or were processed by specified Runner.
*
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @param status Status of the job; one of: running, success, failed, canceled
* @return a Stream of jobs that are being processed or were processed by specified Runner
* @throws GitLabApiException if any exception occurs
*/
public Stream<Job> getJobsStream(Integer runnerId, JobStatus status) throws GitLabApiException {
return (getJobs(runnerId, status, getDefaultPerPage()).stream());
}
/**
* List jobs that are being processed or were processed by specified Runner.
*
* GET /runners/:id/jobs
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @param itemsPerPage The number of Runner instances that will be fetched per page
......@@ -309,16 +378,13 @@ public class RunnersApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public Pager<Job> getJobs(Integer runnerId, int itemsPerPage) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
return getJobs(runnerId, null, itemsPerPage);
return (getJobs(runnerId, null, itemsPerPage));
}
/**
* List jobs that are being processed or were processed by specified Runner.
*
* GET /runners/:id/jobs
* <pre><code>GitLab Endpoint: GET /runners/:id/jobs</code></pre>
*
* @param runnerId The ID of a runner
* @param status Status of the job; one of: running, success, failed, canceled
......@@ -327,11 +393,12 @@ public class RunnersApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public Pager<Job> getJobs(Integer runnerId, JobStatus status, int itemsPerPage) throws GitLabApiException {
if (runnerId == null) {
throw new RuntimeException("runnerId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("status", status, false);
GitLabApiForm formData = new GitLabApiForm().withParam("status", status, false);
return (new Pager<>(this, Job.class, itemsPerPage, formData.asMap(), "runners", runnerId, "jobs"));
}
......@@ -339,56 +406,61 @@ public class RunnersApi extends AbstractApi {
* List all runners (specific and shared) available in the project. Shared runners are listed if at least one
* shared runner is defined and shared runners usage is enabled in the project's settings.
*
* GET /projects/:id/runners
* <pre><code>GitLab Endpoint: GET /projects/:id/runners</code></pre>
*
* @param projectId The ID of the project owned by the authenticated user
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return List of all Runner available in the project
* @throws GitLabApiException if any exception occurs
*/
public List<Runner> getProjectRunners(Integer projectId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, null, "projects", projectId, "runners");
return (response.readEntity(new GenericType<List<Runner>>() {
}));
public List<Runner> getProjectRunners(Object projectIdOrPath) throws GitLabApiException {
return (getProjectRunners(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a Stream all runners (specific and shared) available in the project. Shared runners are listed if at least one
* shared runner is defined and shared runners usage is enabled in the project's settings.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/runners</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream of all Runner available in the project
* @throws GitLabApiException if any exception occurs
*/
public Stream<Runner> getProjectRunnersStream(Object projectIdOrPath) throws GitLabApiException {
return (getProjectRunners(projectIdOrPath, getDefaultPerPage()).stream());
}
/**
* List all runners (specific and shared) available in the project. Shared runners are listed if at least one
* shared runner is defined and shared runners usage is enabled in the project's settings.
*
* GET /projects/:id/runners
* <pre><code>GitLab Endpoint: GET /projects/:id/runners</code></pre>
*
* @param projectId The ID of the project owned by the authenticated user
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return Pager of all Runner available in the project
* @throws GitLabApiException if any exception occurs
*/
public Pager<Runner> getProjectRunners(Integer projectId, int itemsPerPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
return (new Pager<>(this, Runner.class, itemsPerPage, null, "projects", projectId, "runners"));
public Pager<Runner> getProjectRunners(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<>(this, Runner.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "runners"));
}
/**
* Enable an available specific runner in the project.
*
* POST /projects/:id/runners
* <pre><code>GitLab Endpoint: POST /projects/:id/runners</code></pre>
*
* @param projectId The ID of the project owned by the authenticated user
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param runnerId The ID of a runner
* @return Runner instance of the Runner enabled
* @throws GitLabApiException if any exception occurs
*/
public Runner enableRunner(Integer projectId, Integer runnerId) throws GitLabApiException {
if (projectId == null || runnerId == null) {
throw new RuntimeException("projectId or runnerId cannot be null");
}
public Runner enableRunner(Object projectIdOrPath, Integer runnerId) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("runner_id", runnerId, true);
Response response = post(Response.Status.CREATED, formData.asMap(), "projects", projectId, "runners");
Response response = post(Response.Status.CREATED, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "runners");
return (response.readEntity(Runner.class));
}
......@@ -396,27 +468,24 @@ public class RunnersApi extends AbstractApi {
* Disable a specific runner from the project. It works only if the project isn't the only project associated with
* the specified runner. If so, an error is returned. Use the {@link #removeRunner(Integer)} instead.
*
* DELETE /projects/:id/runners/:runner_id
* <pre><code>GitLab Endpoint: DELETE /projects/:id/runners/:runner_id</code></pre>
*
* @param projectId The ID of the project owned by the authenticated user
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param runnerId The ID of a runner
* @return Runner instance of the Runner disabled
* @throws GitLabApiException if any exception occurs
*/
public Runner disableRunner(Integer projectId, Integer runnerId) throws GitLabApiException {
if (projectId == null || runnerId == null) {
throw new RuntimeException("projectId or runnerId cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("runner_id", runnerId, true);
Response response = delete(Response.Status.OK, formData.asMap(), "projects", projectId, "runners");
public Runner disableRunner(Object projectIdOrPath, Integer runnerId) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("runner_id", runnerId, true);
Response response = delete(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "runners");
return (response.readEntity(Runner.class));
}
/**
* Register a new runner for the gitlab instance.
*
* POST /runners/
* <pre><code>GitLab Endpoint: POST /runners/</code></pre>
*
* @param token the token of the project (for project specific runners) or the token from the admin page
* @param description The description of a runner
......@@ -446,15 +515,13 @@ public class RunnersApi extends AbstractApi {
/**
* Deletes a registered Runner.
*
* DELETE /runners/
* <pre><code>GitLab Endpoint: DELETE /runners/</code></pre>
*
* @param token the runners authentication token
* @throws GitLabApiException if any exception occurs
*/
public void deleteRunner(String token) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("token", token, true);
GitLabApiForm formData = new GitLabApiForm().withParam("token", token, true);
delete(Response.Status.NO_CONTENT, formData.asMap(), "runners");
}
}
......@@ -2,6 +2,7 @@ package org.gitlab4j.api;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
......@@ -18,23 +19,10 @@ public class SnippetsApi extends AbstractApi {
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 /snippets
* <pre><code>GitLab Endpoint: GET /snippets</code></pre>
*
* @param downloadContent indicating whether to download the snippet content
* @return a list of authenticated user's snippets
......@@ -57,19 +45,44 @@ public class SnippetsApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
*/
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 /snippets/:id/raw
* <pre><code>GitLab Endpoint: GET /snippets/:id/raw</code></pre>
*
* @param snippetId the snippet ID to remove
* @return the content of snippet
......@@ -118,19 +131,19 @@ public class SnippetsApi extends AbstractApi {
/**
* 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
* @return the specified Snippet as an Optional instance
*/
public Optional<Snippet> getOptionalSnippet( Integer snippetId) {
public Optional<Snippet> getOptionalSnippet(Integer snippetId) {
return (getOptionalSnippet(snippetId, false));
}
/**
* 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 downloadContent indicating whether to download the snippet content
......@@ -187,7 +200,7 @@ public class SnippetsApi extends AbstractApi {
/**
* Removes Snippet.
*
* DELETE /snippets/:id
* <pre><code>GitLab Endpoint: DELETE /snippets/:id</code></pre>
*
* @param snippetId the snippet ID to remove
* @throws GitLabApiException if any exception occurs
......
package org.gitlab4j.api;
import java.util.List;
import java.util.stream.Stream;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
......@@ -19,22 +20,21 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
*/
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.
* This method requires admin access.
*
* <code>GET /hooks</code>
* <pre><code>GitLab Endpoint: GET /hooks</code></pre>
*
* @param page the page to get
* @param perPage the number of deploy keys per page
......@@ -49,7 +49,7 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @return a Pager of SystemHookEvent
......@@ -59,10 +59,22 @@ public class SystemHooksApi extends AbstractApi {
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.
*
* <code>POST /hooks</code>
* <pre><code>GitLab Endpoint: POST /hooks</code></pre>
*
* @param url the hook URL, required
* @param token secret token to validate received payloads, optional
......@@ -92,7 +104,7 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
......@@ -109,7 +121,7 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
......@@ -127,7 +139,7 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
......@@ -144,7 +156,7 @@ public class SystemHooksApi extends AbstractApi {
/**
* 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
* @throws GitLabApiException if any exception occurs
......
......@@ -29,10 +29,11 @@ import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import java.util.List;
import java.util.Optional;
import java.util.stream.Stream;
/**
* @author shuklaalok7 (alok@clay.fish)
* @since v4.8.21 2018-06-5 1:26 AM IST
* This class implements the client side API for the GitLab Wikis API.
* See <a href="https://docs.gitlab.com/ce/api/wikis.html">Wikis API at GitLab</a> for more information.
*/
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
* @throws GitLabApiException if any exception occurs
*/
public List<WikiPage> getPages(Integer projectId) throws GitLabApiException {
return getPages(projectId, 1, this.getDefaultPerPage());
public List<WikiPage> getPages(Object projectIdOrPath) throws GitLabApiException {
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 perPage the number of wiki-pages per page
* @return a list of pages in project's wiki for the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<WikiPage> getPages(Integer projectId, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "wikis");
public List<WikiPage> getPages(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "wikis");
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 /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
* @return the specified project Snippet
* @throws GitLabApiException if any exception occurs
*/
public WikiPage getPage(Integer projectId, String slug) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "wikis", slug);
public WikiPage getPage(Object projectIdOrPath, String slug) throws GitLabApiException {
Response response = get(Response.Status.OK, null,
"projects", getProjectIdOrPath(projectIdOrPath), "wikis", slug);
return (response.readEntity(WikiPage.class));
}
/**
* 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
* @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 {
return (Optional.ofNullable(getPage(projectId, slug)));
return (Optional.ofNullable(getPage(projectIdOrPath, slug)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
......@@ -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.
*
* 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 content the content of a wiki page, required
* @return a WikiPage instance with info on the created page
* @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
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title)
.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));
}
/**
* 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 title the title of a snippet, optional
* @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
* @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()
.withParam("title", title)
.withParam("slug", slug, true)
.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));
}
......@@ -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
* 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
* @throws GitLabApiException if any exception occurs
*/
public void deletePage(Integer projectId, String slug) throws GitLabApiException {
delete(Response.Status.NO_CONTENT, null, "projects", projectId, "wikis", slug);
public void deletePage(Object projectIdOrPath, String slug) throws GitLabApiException {
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