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

Added getXxxxxStream() methods that return Java 8 Streams.

parent 87991488
......@@ -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.Form;
import javax.ws.rs.core.GenericType;
......@@ -20,22 +21,21 @@ public class DeployKeysApi extends AbstractApi {
/**
* Get a list of all deploy keys across all projects of the GitLab instance. This method requires admin access.
* Only returns the first page.
*
* GET /deploy_keys
* <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
*
* @return a list of DeployKey
* @throws GitLabApiException if any exception occurs
*/
public List<DeployKey> getDeployKeys() throws GitLabApiException {
return (getDeployKeys(1, getDefaultPerPage()));
return (getDeployKeys(getDefaultPerPage()).all());
}
/**
* Get a list of all deploy keys across all projects of the GitLab instance using the specified page and per page settings.
* This method requires admin access.
*
* GET /deploy_keys
* <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
*
* @param page the page to get
* @param perPage the number of deploy keys per page
......@@ -50,7 +50,7 @@ public class DeployKeysApi extends AbstractApi {
/**
* Get a Pager of all deploy keys across all projects of the GitLab instance. This method requires admin access.
*
* GET /deploy_keys
* <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
*
* @param itemsPerPage the number of DeployKey instances that will be fetched per page
* @return a Pager of DeployKey
......@@ -59,98 +59,111 @@ public class DeployKeysApi extends AbstractApi {
public Pager<DeployKey> getDeployKeys(int itemsPerPage) throws GitLabApiException {
return (new Pager<DeployKey>(this, DeployKey.class, itemsPerPage, null, "deploy_keys"));
}
/**
* Get a Stream of all deploy keys across all projects of the GitLab instance. This method requires admin access.
*
* <pre><code>GitLab Endpoint: GET /deploy_keys</code></pre>
*
* @return a list of DeployKey
* @throws GitLabApiException if any exception occurs
*/
public Stream<DeployKey> getDeployKeysStream() throws GitLabApiException {
return (getDeployKeys(getDefaultPerPage()).stream());
}
/**
* Get a list of the deploy keys for the specified project. This method requires admin access.
* Only returns the first page.
*
* GET /projects/:id/deploy_keys
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list of DeployKey
* @throws GitLabApiException if any exception occurs
*/
public List<DeployKey> getProjectDeployKeys(Integer projectId) throws GitLabApiException {
return (getProjectDeployKeys(projectId, 1, getDefaultPerPage()));
public List<DeployKey> getProjectDeployKeys(Object projectIdOrPath) throws GitLabApiException {
return (getProjectDeployKeys(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a list of the deploy keys for the specified project using the specified page and per page settings.
* This method requires admin access.
*
* GET /projects/:id/deploy_keys
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
*
* @param projectId the ID of the project
* @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 deploy keys per page
* @return the list of DeployKey in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<DeployKey> getProjectDeployKeys(Integer projectId, int page, int perPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "deploy_keys");
public List<DeployKey> getProjectDeployKeys(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys");
return (response.readEntity(new GenericType<List<DeployKey>>() {}));
}
/**
* Get a Pager of the deploy keys for the specified project. This method requires admin access.
*
* GET /projects/:id/deploy_keys
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance@param projectId the ID of the project
* @param itemsPerPage the number of DeployKey instances that will be fetched per page
* @return a Pager of DeployKey
* @throws GitLabApiException if any exception occurs
*/
public Pager<DeployKey> getProjectDeployKeys(Integer projectId, Integer itemsPerPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public Pager<DeployKey> getProjectDeployKeys(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<DeployKey>(this, DeployKey.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys"));
}
return (new Pager<DeployKey>(this, DeployKey.class, itemsPerPage, null, "projects", projectId, "deploy_keys"));
/**
* Get a list of the deploy keys for the specified project. This method requires admin access.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list of DeployKey
* @throws GitLabApiException if any exception occurs
*/
public Stream<DeployKey> getProjectDeployKeysStream(Object projectIdOrPath) throws GitLabApiException {
return (getProjectDeployKeys(projectIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get a single deploy key for the specified project.
*
* GET /projects/:id/deploy_keys/:key_id
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param keyId the ID of the deploy key to delete
* @return the DeployKey instance for the specified project ID and key ID
* @throws GitLabApiException if any exception occurs
*/
public DeployKey getDeployKey(Integer projectId, Integer keyId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public DeployKey getDeployKey(Object projectIdOrPath, Integer keyId) throws GitLabApiException {
if (keyId == null) {
throw new RuntimeException("keyId cannot be null");
}
Response response = get(Response.Status.OK, null, "projects", projectId, "deploy_keys", keyId);
Response response = get(Response.Status.OK, null,
"projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys", keyId);
return (response.readEntity(DeployKey.class));
}
/**
* Get a single deploy key for the specified project as an Optional instance.
*
* GET /projects/:id/deploy_keys/:key_id
* <pre><code>GitLab Endpoint: GET /projects/:id/deploy_keys/:key_id</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param keyId the ID of the deploy key to delete
* @return the DeployKey for the specified project ID and key ID as an Optional instance
*/
public Optional<DeployKey> getOptionalDeployKey(Integer projectId, Integer keyId) {
public Optional<DeployKey> getOptionalDeployKey(Object projectIdOrPath, Integer keyId) {
try {
return (Optional.ofNullable(getDeployKey(projectId, keyId)));
return (Optional.ofNullable(getDeployKey(projectIdOrPath, keyId)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
......@@ -159,72 +172,62 @@ public class DeployKeysApi extends AbstractApi {
/**
* Creates a new deploy key for a project.
*
* POST /projects/:id/deploy_keys
* <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys</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 new deploy key's title, required
* @param key the new deploy key, required
* @param canPush can deploy key push to the project's repository, optional
* @return an DeployKey instance with info on the added deploy key
* @throws GitLabApiException if any exception occurs
*/
public DeployKey addDeployKey(Integer projectId, String title, String key, Boolean canPush) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public DeployKey addDeployKey(Object projectIdOrPath, String title, String key, Boolean canPush) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("title", title, true)
.withParam("key", key, true)
.withParam("can_push", canPush);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "deploy_keys");
Response response = post(Response.Status.CREATED, formData,
"projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys");
return (response.readEntity(DeployKey.class));
}
/**
* Removes a deploy key from the project. If the deploy key is used only for this project,it will be deleted from the system.
*
* DELETE /projects/:id/deploy_keys/:key_id
* <pre><code>GitLab Endpoint: DELETE /projects/:id/deploy_keys/:key_id</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param keyId the ID of the deploy key to delete
* @throws GitLabApiException if any exception occurs
*/
public void deleteDeployKey(Integer projectId, Integer keyId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public void deleteDeployKey(Object projectIdOrPath, Integer keyId) throws GitLabApiException {
if (keyId == null) {
throw new RuntimeException("keyId cannot be null");
}
delete(Response.Status.OK, null, "projects", projectId, "deploy_keys", keyId);
delete(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys", keyId);
}
/**
* Enables a deploy key for a project so this can be used. Returns the enabled key when successful.
*
* POST /projects/:id/deploy_keys/:key_id/enable
* <pre><code>GitLab Endpoint: POST /projects/:id/deploy_keys/:key_id/enable</code></pre>
*
* @param projectId the ID of the project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param keyId the ID of the deploy key to enable
* @return an DeployKey instance with info on the enabled deploy key
* @throws GitLabApiException if any exception occurs
*/
public DeployKey enableDeployKey(Integer projectId, Integer keyId) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public DeployKey enableDeployKey(Object projectIdOrPath, Integer keyId) throws GitLabApiException {
if (keyId == null) {
throw new RuntimeException("keyId cannot be null");
}
Response response = post(Response.Status.CREATED, (Form)null, "projects", projectId, "deploy_keys", keyId, "enable");
Response response = post(Response.Status.CREATED, (Form)null,
"projects", getProjectIdOrPath(projectIdOrPath), "deploy_keys", keyId, "enable");
return (response.readEntity(DeployKey.class));
}
}
......@@ -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.GenericType;
import javax.ws.rs.core.Response;
......@@ -32,7 +33,7 @@ public class EventsApi extends AbstractApi {
*/
public List<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, 1, getDefaultPerPage()));
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).all());
}
/**
......@@ -80,7 +81,7 @@ public class EventsApi extends AbstractApi {
* @return a Pager of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
public Pager<Event> getAuthenticatedUserEvents(ActionType action, TargetType targetType, Date before, Date after,
SortOrder sortOrder, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
......@@ -93,12 +94,30 @@ public class EventsApi extends AbstractApi {
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "events"));
}
/**
* Get a Stream of events for the authenticated user.
*
* GET /events
*
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a Stream of events for the authenticated user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Stream<Event> getAuthenticatedUserEventsStream(ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getAuthenticatedUserEvents(action, targetType, before, after, sortOrder, getDefaultPerPage()).stream());
}
/**
* Get a list of events for the specified user.
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -107,9 +126,9 @@ public class EventsApi extends AbstractApi {
* @return a list of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType,
public List<Event> getUserEvents(Object userIdOrUsername, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getUserEvents(userId, action, targetType, before, after, sortOrder, 1, getDefaultPerPage()));
return (getUserEvents(userIdOrUsername, action, targetType, before, after, sortOrder, getDefaultPerPage()).all());
}
/**
......@@ -117,7 +136,7 @@ public class EventsApi extends AbstractApi {
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -128,12 +147,8 @@ public class EventsApi extends AbstractApi {
* @return a list of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType,
public List<Event> getUserEvents(Object userIdOrUsername, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException {
if (userId == null) {
throw new RuntimeException("user ID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action)
......@@ -144,7 +159,8 @@ public class EventsApi extends AbstractApi {
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "users", userId, "events");
Response response = get(Response.Status.OK, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "events");
return (response.readEntity(new GenericType<List<Event>>() {}));
}
......@@ -153,7 +169,7 @@ public class EventsApi extends AbstractApi {
*
* GET /users/:userId/events
*
* @param userId the user ID to get the events for, required
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -163,13 +179,9 @@ public class EventsApi extends AbstractApi {
* @return a Pager of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Pager<Event> getUserEvents(Integer userId, ActionType action, TargetType targetType, Date before, Date after,
public Pager<Event> getUserEvents(Object userIdOrUsername, ActionType action, TargetType targetType, Date before, Date after,
SortOrder sortOrder, int itemsPerPage) throws GitLabApiException {
if (userId == null) {
throw new RuntimeException("user ID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action)
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
......@@ -177,7 +189,27 @@ public class EventsApi extends AbstractApi {
.withParam("after", after)
.withParam("sort", sortOrder);
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "users", userId, "events"));
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(),
"users", getUserIdOrUsername(userIdOrUsername), "events"));
}
/**
* Get a Stream of events for the specified user.
*
* GET /users/:userId/events
*
* @param userIdOrUsername the user ID, username of the user, or a User instance holding the user ID or username
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a Stream of events for the specified user and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Stream<Event> getUserEventsStream(Object userIdOrUsername, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getUserEvents(userIdOrUsername, action, targetType, before, after, sortOrder, getDefaultPerPage()).stream());
}
/**
......@@ -185,7 +217,7 @@ public class EventsApi extends AbstractApi {
*
* GET /:projectId/events
*
* @param projectId the project ID to get the events for, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -194,9 +226,9 @@ public class EventsApi extends AbstractApi {
* @return a list of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType,
public List<Event> getProjectEvents(Object projectIdOrPath, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getProjectEvents(projectId, action, targetType, before, after, sortOrder, 1, getDefaultPerPage()));
return (getProjectEvents(projectIdOrPath, action, targetType, before, after, sortOrder, getDefaultPerPage()).all());
}
/**
......@@ -204,7 +236,7 @@ public class EventsApi extends AbstractApi {
*
* GET /projects/:projectId/events
*
* @param projectId the project ID to get the events for, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -215,13 +247,9 @@ public class EventsApi extends AbstractApi {
* @return a list of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public List<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType,
public List<Event> getProjectEvents(Integer projectIdOrPath, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder, int page, int perPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("project ID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action)
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
......@@ -231,7 +259,8 @@ public class EventsApi extends AbstractApi {
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "events");
Response response = get(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "events");
return (response.readEntity(new GenericType<List<Event>>() {}));
}
......@@ -240,7 +269,7 @@ public class EventsApi extends AbstractApi {
*
* GET /projects/:projectId/events
*
* @param projectId the project ID to get the events for, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
......@@ -250,13 +279,9 @@ public class EventsApi extends AbstractApi {
* @return a Pager of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Pager<Event> getProjectEvents(Integer projectId, ActionType action, TargetType targetType, Date before, Date after,
public Pager<Event> getProjectEvents(Object projectIdOrPath, ActionType action, TargetType targetType, Date before, Date after,
SortOrder sortOrder, int itemsPerPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("project ID cannot be null");
}
GitLabApiForm formData = new GitLabApiForm()
.withParam("action", action)
.withParam("target_type", targetType != null ? targetType.toValue().toLowerCase() : null)
......@@ -264,6 +289,26 @@ public class EventsApi extends AbstractApi {
.withParam("after", after)
.withParam("sort", sortOrder);
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(), "projects", projectId, "events"));
return (new Pager<Event>(this, Event.class, itemsPerPage, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "events"));
}
/**
* Get a Stream of events for the specified project.
*
* GET /:projectId/events
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param action include only events of a particular action type, optional
* @param targetType include only events of a particular target type, optional
* @param before include only events created before a particular date, optional
* @param after include only events created after a particular date, optional
* @param sortOrder sort events in ASC or DESC order by created_at. Default is DESC, optional
* @return a Stream of events for the specified project and matching the supplied parameters
* @throws GitLabApiException if any exception occurs
*/
public Stream<Event> getProjectEventsStream(Object projectIdOrPath, ActionType action, TargetType targetType,
Date before, Date after, SortOrder sortOrder) throws GitLabApiException {
return (getProjectEvents(projectIdOrPath, action, targetType, before, after, sortOrder, getDefaultPerPage()).stream());
}
}
......@@ -8,6 +8,7 @@ import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
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;
......@@ -30,23 +31,20 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get a list of jobs in a project.
*
* GET /projects/:id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a list containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Job> getJobs(Object projectIdOrPath) throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "jobs");
return (response.readEntity(new GenericType<List<Job>>() {
}));
return (getJobs(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* Get a list of jobs in a project in the specified page range.
*
* GET /projects/:id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the jobs for
* @param page the page to get
......@@ -56,14 +54,13 @@ public class JobApi extends AbstractApi implements Constants {
*/
public List<Job> getJobs(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "jobs");
return (response.readEntity(new GenericType<List<Job>>() {
}));
return (response.readEntity(new GenericType<List<Job>>() {}));
}
/**
* Get a Pager of jobs in a project.
*
* GET /projects/:id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the jobs for
* @param itemsPerPage the number of Job instances that will be fetched per page
......@@ -74,10 +71,23 @@ public class JobApi extends AbstractApi implements Constants {
return (new Pager<Job>(this, Job.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "jobs"));
}
/**
* Get a Stream of jobs in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @return a Stream containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Stream<Job> getJobsStream(Object projectIdOrPath) throws GitLabApiException {
return (getJobs(projectIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get a list of jobs in a project.
*
* GET /projects/:id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
......@@ -85,15 +95,44 @@ public class JobApi extends AbstractApi implements Constants {
* @throws GitLabApiException if any exception occurs during execution
*/
public List<Job> getJobs(Object projectIdOrPath, JobScope scope) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "jobs");
return (response.readEntity(new GenericType<List<Job>>() {}));
return (getJobs(projectIdOrPath, scope, getDefaultPerPage()).all());
}
/**
* Get a list of jobs in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @param itemsPerPage the number of Job instances that will be fetched per page
* @return a list containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Pager<Job> getJobs(Object projectIdOrPath, JobScope scope, int itemsPerPage) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("scope", scope);
return (new Pager<Job>(this, Job.class, itemsPerPage, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "jobs"));
}
/**
* Get a Stream of jobs in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the jobs for
* @param scope the scope of jobs, one of: CREATED, PENDING, RUNNING, FAILED, SUCCESS, CANCELED, SKIPPED, MANUAL
* @return a Stream containing the jobs for the specified project ID
* @throws GitLabApiException if any exception occurs during execution
*/
public Stream<Job> getJobsStream(Object projectIdOrPath, JobScope scope) throws GitLabApiException {
return (getJobs(projectIdOrPath, scope, getDefaultPerPage()).stream());
}
/**
* Get a list of jobs in a pipeline.
*
* GET /projects/:id/pipelines/:pipeline_id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the pipelines for
* @param pipelineId the pipeline ID to get the list of jobs for
......@@ -109,7 +148,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get a list of jobs in a pipeline.
*
* GET /projects/:id/pipelines/:pipeline_id/jobs
* <pre><code>GitLab Endpoint: GET /projects/:id/pipelines/:pipeline_id/jobs</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the pipelines for
* @param pipelineId the pipeline ID to get the list of jobs for
......@@ -126,7 +165,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get single job in a project.
*
* GET /projects/:id/jobs/:job_id
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the job for
* @param jobId the job ID to get
......@@ -141,7 +180,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get single job in a project as an Optional instance.
*
* GET /projects/:id/jobs/:job_id
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path to get the job for
* @param jobId the job ID to get
......@@ -160,7 +199,7 @@ public class JobApi extends AbstractApi implements Constants {
* The file will be saved to the specified directory. If the file already exists in the directory it will
* be overwritten.
*
* GET /projects/:id/jobs/artifacts/:ref_name/download?job=name
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/artifacts/:ref_name/download?job=name</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param ref the ref from a repository
......@@ -197,7 +236,7 @@ public class JobApi extends AbstractApi implements Constants {
* provided the job finished successfully. The file will be saved to the specified directory.
* If the file already exists in the directory it will be overwritten.
*
* GET /projects/:id/jobs/artifacts/:ref_name/download?job=name
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/artifacts/:ref_name/download?job=name</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param ref the ref from a repository
......@@ -217,7 +256,7 @@ public class JobApi extends AbstractApi implements Constants {
* specified directory with the following name pattern: job-{jobid}-artifacts.zip. If the file already
* exists in the directory it will be overwritten.
*
* GET /projects/:id/jobs/:job_id/artifacts
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the job ID to get the artifacts for
......@@ -249,7 +288,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get an InputStream pointing to the job artifacts file for the specified job ID.
*
* GET /projects/:id/jobs/:job_id/artifacts
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the job ID to get the artifacts for
......@@ -267,7 +306,7 @@ public class JobApi extends AbstractApi implements Constants {
*
* Only a single file is going to be extracted from the archive and streamed to a client.
*
* GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts/*artifact_path</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the unique job identifier
......@@ -302,7 +341,7 @@ public class JobApi extends AbstractApi implements Constants {
*
* Only a single file is going to be extracted from the archive and streamed to a client.
*
* GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts/*artifact_path</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the unique job identifier
......@@ -321,7 +360,7 @@ public class JobApi extends AbstractApi implements Constants {
*
* Only a single file is going to be extracted from the archive and streamed to a client.
*
* GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts/*artifact_path</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the unique job identifier
......@@ -357,7 +396,7 @@ public class JobApi extends AbstractApi implements Constants {
*
* Only a single file is going to be extracted from the archive and streamed to a client.
*
* GET /projects/:id/jobs/:job_id/artifacts/*artifact_path
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:job_id/artifacts/*artifact_path</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the unique job identifier
......@@ -375,7 +414,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Get a trace of a specific job of a project
*
* GET /projects/:id/jobs/:id/trace
* <pre><code>GitLab Endpoint: GET /projects/:id/jobs/:id/trace</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* to get the specified job's trace for
......@@ -392,7 +431,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Cancel specified job in a project.
*
* POST /projects/:id/jobs/:job_id/cancel
* <pre><code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/cancel</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to cancel job
......@@ -408,7 +447,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Retry specified job in a project.
*
* POST /projects/:id/jobs/:job_id/retry
* <pre><code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/retry</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to retry job
......@@ -424,7 +463,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Erase specified job in a project.
*
* POST /projects/:id/jobs/:job_id/erase
* <pre><code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/erase</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to erase job
......@@ -440,7 +479,7 @@ public class JobApi extends AbstractApi implements Constants {
/**
* Play specified job in a project.
*
* POST /projects/:id/jobs/:job_id/play
* <pre><code>GitLab Endpoint: POST /projects/:id/jobs/:job_id/play</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param jobId the ID to play job
......
......@@ -14,80 +14,89 @@ public class LabelsApi extends AbstractApi {
}
/**
* Get all labels of the specified project. Only returns the first page
* Get all labels of the specified project.
*
* @param projectId the project ID to get the labels for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list of project's labels
* @throws GitLabApiException if any exception occurs
*/
public List<Label> getLabels(Integer projectId) throws GitLabApiException {
return (getLabels(projectId, 1, getDefaultPerPage()));
public List<Label> getLabels(Object projectIdOrPath) throws GitLabApiException {
return (getLabels(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* Get all labels of the specified project to using the specified page and per page setting
*
* @param projectId the project ID to get the labels for
* @param page the page to get
* @param perPage the number of issues per page
* @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 items per page
* @return a list of project's labels in the specified range
* @throws GitLabApiException if any exception occurs
*/
public List<Label> getLabels(Integer projectId, int page, int perPage) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "labels");
public List<Label> getLabels(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(javax.ws.rs.core.Response.Status.OK, getPageQueryParams(page, perPage),
"projects", getProjectIdOrPath(projectIdOrPath), "labels");
return (response.readEntity(new GenericType<List<Label>>() {}));
}
/**
* Get a Pager of all labels of the specified project.
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of items per page
* @return a list of project's labels in the specified range
* @throws GitLabApiException if any exception occurs
*/
public Pager<Label> getLabels(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<Label>(this, Label.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "labels"));
}
/**
* Create a label
*
* @param projectId the project ID to create a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param color the color for the label
* @param description the description for the label
* @return the created Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label createLabel(Integer projectId, String name, String color, String description) throws GitLabApiException {
return (createLabel(projectId, name, color, description, null));
public Label createLabel(Object projectIdOrPath, String name, String color, String description) throws GitLabApiException {
return (createLabel(projectIdOrPath, name, color, description, null));
}
/**
* Create a label
*
* @param projectId the project ID to create a label for
* @param name the name for the label
* @param color the color for the label
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param color the color for the label
* @return the created Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label createLabel(Integer projectId, String name, String color) throws GitLabApiException {
return (createLabel(projectId, name, color, null, null));
public Label createLabel(Object projectIdOrPath, String name, String color) throws GitLabApiException {
return (createLabel(projectIdOrPath, name, color, null, null));
}
/**
* Create a label
*
* @param projectId the project ID to create a label for
* @param name the name for the label
* @param color the color for the label
* @param priority the priority for the label
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param color the color for the label
* @param priority the priority for the label
* @return the created Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label createLabel(Integer projectId, String name, String color, Integer priority) throws GitLabApiException {
return (createLabel(projectId, name, color, null, priority));
public Label createLabel(Object projectIdOrPath, String name, String color, Integer priority) throws GitLabApiException {
return (createLabel(projectIdOrPath, name, color, null, priority));
}
/**
* Create a label
*
* @param projectId the project ID to create a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param color the color for the label
* @param description the description for the label
......@@ -95,18 +104,14 @@ public class LabelsApi extends AbstractApi {
* @return the created Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label createLabel(Integer projectId, String name, String color, String description, Integer priority) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public Label createLabel(Object projectIdOrPath, String name, String color, String description, Integer priority) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true)
.withParam("color", color, true)
.withParam("description", description)
.withParam("priority", priority);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "labels");
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "labels");
return (response.readEntity(Label.class));
}
......@@ -114,7 +119,7 @@ public class LabelsApi extends AbstractApi {
/**
* Update the specified label
*
* @param projectId the project ID to update a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param newName the new name for the label
* @param description the description for the label
......@@ -122,15 +127,15 @@ public class LabelsApi extends AbstractApi {
* @return the modified Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label updateLabelName(Integer projectId, String name, String newName, String description, Integer priority) throws GitLabApiException {
return (updateLabel(projectId, name, newName, null, description, priority));
public Label updateLabelName(Object projectIdOrPath, String name, String newName, String description, Integer priority) throws GitLabApiException {
return (updateLabel(projectIdOrPath, name, newName, null, description, priority));
}
/**
* Update the specified label
*
* @param projectId the project ID to update a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param color the color for the label
* @param description the description for the label
......@@ -138,14 +143,14 @@ public class LabelsApi extends AbstractApi {
* @return the modified Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label updateLabelColor(Integer projectId, String name, String color, String description, Integer priority) throws GitLabApiException {
return (updateLabel(projectId, name, null, color, description, priority));
public Label updateLabelColor(Object projectIdOrPath, String name, String color, String description, Integer priority) throws GitLabApiException {
return (updateLabel(projectIdOrPath, name, null, color, description, priority));
}
/**
* Update the specified label
*
* @param projectId the project ID to update a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @param newName the new name for the label
* @param color the color for the label
......@@ -154,11 +159,7 @@ public class LabelsApi extends AbstractApi {
* @return the modified Label instance
* @throws GitLabApiException if any exception occurs
*/
public Label updateLabel(Integer projectId, String name, String newName, String color, String description, Integer priority) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public Label updateLabel(Object projectIdOrPath, String name, String newName, String color, String description, Integer priority) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true)
......@@ -166,53 +167,50 @@ public class LabelsApi extends AbstractApi {
.withParam("color", color)
.withParam("description", description)
.withParam("priority", priority);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "labels");
Response response = put(Response.Status.OK, formData.asMap(),
"projects", getProjectIdOrPath(projectIdOrPath), "labels");
return (response.readEntity(Label.class));
}
/**
* Delete the specified label
*
* @param projectId the project ID to delete a label for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param name the name for the label
* @throws GitLabApiException if any exception occurs
*/
public void deleteLabel(Integer projectId, String name) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public void deleteLabel(Object projectIdOrPath, String name) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm()
.withParam("name", name, true);
GitLabApiForm formData = new GitLabApiForm().withParam("name", name, true);
Response.Status expectedStatus = (isApiVersion(GitLabApi.ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, formData.asMap(), "projects", projectId, "labels");
delete(expectedStatus, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "labels");
}
/**
* Subscribe a specified label
*
* @param projectId the project ID to subscribe a label for
* @param labelId the lable ID
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param labelId the label ID
* @return HttpStatusCode 503
* @throws GitLabApiException if any exception occurs
*/
public Label subscribeLabel(Integer projectId, Integer labelId) throws GitLabApiException {
Response response = post(Response.Status.NOT_MODIFIED, getDefaultPerPageParam(), "projects", projectId, "labels", labelId, "subscribe");
public Label subscribeLabel(Object projectIdOrPath, Integer labelId) throws GitLabApiException {
Response response = post(Response.Status.NOT_MODIFIED, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "labels", labelId, "subscribe");
return (response.readEntity(Label.class));
}
/**
* Unsubscribe a specified label
*
* @param projectId the project ID to unsubscribe a label for
* @param labelId the lable ID
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param labelId the label ID
* @return HttpStatusCode 503
* @throws GitLabApiException if any exception occurs
*/
public Label unsubscribeLabel(Integer projectId, Integer labelId) throws GitLabApiException {
Response response = post(Response.Status.NOT_MODIFIED, getDefaultPerPageParam(), "projects", projectId, "labels", labelId, "unsubscribe");
public Label unsubscribeLabel(Object projectIdOrPath, Integer labelId) throws GitLabApiException {
Response response = post(Response.Status.NOT_MODIFIED, getDefaultPerPageParam(),
"projects", getProjectIdOrPath(projectIdOrPath), "labels", labelId, "unsubscribe");
return (response.readEntity(Label.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,21 +21,20 @@ public class NamespaceApi extends AbstractApi {
* Get a list of the namespaces of the authenticated user. If the user is an administrator,
* a list of all namespaces in the GitLab instance is created.
*
* GET /namespaces
* <pre><code>GitLab Endpoint: GET /namespaces</code></pre>
*
* @return a List of Namespace instances
* @throws GitLabApiException if any exception occurs
*/
public List<Namespace> getNamespaces() throws GitLabApiException {
Response response = get(Response.Status.OK, getDefaultPerPageParam(), "namespaces");
return (response.readEntity(new GenericType<List<Namespace>>() {}));
return (getNamespaces(getDefaultPerPage()).all());
}
/**
* Get a list of the namespaces of the authenticated user. If the user is an administrator,
* a list of all namespaces in the GitLab instance is created.
* a list of all namespaces in the GitLab instance is returned.
*
* GET /namespaces
* <pre><code>GitLab Endpoint: GET /namespaces</code></pre>
*
* @param page the page to get
* @param perPage the number of Namespace instances per page
......@@ -48,9 +48,9 @@ public class NamespaceApi extends AbstractApi {
/**
* Get a Pager of the namespaces of the authenticated user. If the user is an administrator,
* a Pager of all namespaces in the GitLab instance is created.
* a Pager of all namespaces in the GitLab instance is returned.
*
* GET /namespaces
* <pre><code>GitLab Endpoint: GET /namespaces</code></pre>
*
* @param itemsPerPage the number of Project instances that will be fetched per page
* @return a Pager of Namespace instances
......@@ -60,25 +60,36 @@ public class NamespaceApi extends AbstractApi {
return (new Pager<Namespace>(this, Namespace.class, itemsPerPage, null, "namespaces"));
}
/**
* Get a Stream of the namespaces of the authenticated user. If the user is an administrator,
* a Stream of all namespaces in the GitLab instance is returned.
*
* <pre><code>GitLab Endpoint: GET /namespaces</code></pre>
*
* @return a Stream of Namespace instances
* @throws GitLabApiException if any exception occurs
*/
public Stream<Namespace> getNamespacesStream() throws GitLabApiException {
return (getNamespaces(getDefaultPerPage()).stream());
}
/**
* Get all namespaces that match a string in their name or path.
*
* GET /namespaces?search=:query
* <pre><code>GitLab Endpoint: GET /namespaces?search=:query</code></pre>
*
* @param query the search string
* @return the Namespace List with the matching namespaces
* @throws GitLabApiException if any exception occurs
*/
public List<Namespace> findNamespaces(String query) throws GitLabApiException {
GitLabApiForm formData = new GitLabApiForm().withParam("search", query, true).withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "namespaces");
return (response.readEntity(new GenericType<List<Namespace>>() {}));
return (findNamespaces(query, getDefaultPerPage()).all());
}
/**
* Get all namespaces that match a string in their name or path in the specified page range.
*
* GET /namespaces?search=:query
* <pre><code>GitLab Endpoint: GET /namespaces?search=:query</code></pre>
*
* @param query the search string
* @param page the page to get
......@@ -95,7 +106,7 @@ public class NamespaceApi extends AbstractApi {
/**
* Get a Pager of all namespaces that match a string in their name or path.
*
* GET /namespaces?search=:query
* <pre><code>GitLab Endpoint: GET /namespaces?search=:query</code></pre>
*
* @param query the search string
* @param itemsPerPage the number of Project instances that will be fetched per page
......@@ -106,4 +117,17 @@ public class NamespaceApi extends AbstractApi {
GitLabApiForm formData = new GitLabApiForm().withParam("search", query, true);
return (new Pager<Namespace>(this, Namespace.class, itemsPerPage, formData.asMap(), "namespaces"));
}
/**
* Get all namespaces that match a string in their name or path as a Stream.
*
* <pre><code>GitLab Endpoint: GET /namespaces?search=:query</code></pre>
*
* @param query the search string
* @return a Stream with the matching namespaces
* @throws GitLabApiException if any exception occurs
*/
public Stream<Namespace> findNamespacesStream(String query) throws GitLabApiException {
return (findNamespaces(query, getDefaultPerPage()).stream());
}
}
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