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

Added getXxxxxStream() methods that return Java 8 Streams.

parent 87991488
......@@ -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;
......@@ -32,20 +33,20 @@ public class CommitsApi extends AbstractApi {
/**
* Get a list of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a list containing the commits for the specified project ID
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath) throws GitLabApiException {
return (getCommits(projectIdOrPath, null, null, null));
return (getCommits(projectIdOrPath, null, null, null, getDefaultPerPage()).all());
}
/**
* Get a list of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param page the page to get
......@@ -60,7 +61,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a Pager of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of Commit instances that will be fetched per page
......@@ -72,31 +73,22 @@ public class CommitsApi extends AbstractApi {
}
/**
* Get a list of repository commits in a project.
* Get a Stream of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
* @param since only commits after or on this date will be returned
* @param until only commits before or on this date will be returned
* @return a list containing the commits for the specified project ID
* @return a Stream containing the commits for the specified project ID
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath, String ref, Date since, Date until) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("ref_name", ref)
.withParam("since", ISO8601.toString(since, false))
.withParam("until", ISO8601.toString(until, false))
.withParam(PER_PAGE_PARAM, getDefaultPerPage());
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits");
return (response.readEntity(new GenericType<List<Commit>>() {}));
public Stream<Commit> getCommitStream(Object projectIdOrPath) throws GitLabApiException {
return (getCommits(projectIdOrPath, null, null, null, getDefaultPerPage()).stream());
}
/**
* Get a list of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -107,20 +99,13 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath, String ref, Date since, Date until, String path) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam(PER_PAGE_PARAM, getDefaultPerPage())
.withParam("ref_name", ref)
.withParam("since", ISO8601.toString(since, false))
.withParam("until", ISO8601.toString(until, false))
.withParam("path", (path == null ? null : urlEncode(path)));
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits");
return (response.readEntity(new GenericType<List<Commit>>() {}));
return (getCommits(projectIdOrPath, ref, since, until, path, getDefaultPerPage()).all());
}
/**
* Get a list of file commits in a project
*
* GET /projects/:id/repository/commits?path=:file_path
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits?path=:file_path</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -129,18 +114,29 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath, String ref, String path) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam(PER_PAGE_PARAM, getDefaultPerPage())
.withParam("ref_name", ref)
.withParam("path", (path == null ? null : urlEncode(path)));
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits");
return (response.readEntity(new GenericType<List<Commit>>() {}));
return (getCommits(projectIdOrPath, ref, null, null, path, getDefaultPerPage()).all());
}
/**
* Get a list of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
* @param since only commits after or on this date will be returned
* @param until only commits before or on this date will be returned
* @return a list containing the commits for the specified project ID
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath, String ref, Date since, Date until) throws GitLabApiException {
return (getCommits(projectIdOrPath, ref, since, until, null, getDefaultPerPage()).all());
}
/**
* Get a list of repository commits in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -152,13 +148,46 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(Object projectIdOrPath, String ref, Date since, Date until, int page, int perPage) throws GitLabApiException {
return getCommits(projectIdOrPath, ref, since, until, null, page, perPage);
return (getCommits(projectIdOrPath, ref, since, until, null, page, perPage));
}
/**
* Get a Stream of repository commits in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
* @param since only commits after or on this date will be returned
* @param until only commits before or on this date will be returned
* @return a Stream containing the commits for the specified project ID
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Stream<Commit> getCommitsStream(Object projectIdOrPath, String ref, Date since, Date until) throws GitLabApiException {
return (getCommits(projectIdOrPath, ref, since, until, null, getDefaultPerPage()).stream());
}
/**
* Get a Stream of repository commits in a project.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
* @param since only commits after or on this date will be returned
* @param until only commits before or on this date will be returned
* @param path the path to file of a project
* @return a Stream containing the commits for the specified project ID
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Stream<Commit> getCommitsStream(Object projectIdOrPath, String ref, Date since, Date until, String path) throws GitLabApiException {
return (getCommits(projectIdOrPath, ref, since, until, path, getDefaultPerPage()).stream());
}
/**
* Get a list of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -185,7 +214,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a Pager of repository commits in a project.
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -196,13 +225,13 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Pager<Commit> getCommits(Object projectIdOrPath, String ref, Date since, Date until, int itemsPerPage) throws GitLabApiException {
return getCommits(projectIdOrPath, ref, since,until, null, itemsPerPage);
return getCommits(projectIdOrPath, ref, since, until, null, itemsPerPage);
}
/**
* Get a Pager of repository commits in a project
*
* GET /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param ref the name of a repository branch or tag or if not given the default branch
......@@ -225,7 +254,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a specific commit identified by the commit hash or name of a branch or tag.
*
* GET /projects/:id/repository/commits/:sha
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -240,7 +269,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -257,7 +286,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha/refs
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/refs</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -266,13 +295,13 @@ public class CommitsApi extends AbstractApi {
* @since Gitlab 10.6
*/
public List<CommitRef> getCommitRefs(Object projectIdOrPath, String sha) throws GitLabApiException {
return getCommitRefs(projectIdOrPath, sha, RefType.ALL);
return (getCommitRefs(projectIdOrPath, sha, RefType.ALL));
}
/**
* Get a specific commit identified by the commit hash or name of a branch or tag as an Optional instance
*
* GET /projects/:id/repository/commits/:sha/refs?type=:refType
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/refs?type=:refType</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -292,7 +321,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a list of repository commit statuses that meet the provided filter.
*
* GET /projects/:id/repository/commits/:sha/statuses
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/statuses</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA
......@@ -301,13 +330,13 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<CommitStatus> getCommitStatuses(Object projectIdOrPath, String sha, CommitStatusFilter filter) throws GitLabApiException {
return (getCommitStatuses(projectIdOrPath, sha, filter, 1, getDefaultPerPage()));
return (getCommitStatuses(projectIdOrPath, sha, filter, getDefaultPerPage()).all());
}
/**
* Get a list of repository commit statuses that meet the provided filter.
*
* GET /projects/:id/repository/commits/:sha/statuses
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/statuses</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA
......@@ -338,7 +367,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get a Pager of repository commit statuses that meet the provided filter.
*
* GET /projects/:id/repository/commits/:sha/statuses
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/statuses</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA
......@@ -363,6 +392,21 @@ public class CommitsApi extends AbstractApi {
"projects", this.getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "statuses"));
}
/**
* Get a Stream of repository commit statuses that meet the provided filter.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/statuses</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha the commit SHA
* @param filter the commit statuses file, contains ref, stage, name, all
* @return a Stream containing the commit statuses for the specified project and sha that meet the provided filter
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Stream<CommitStatus> getCommitStatusesStream(Object projectIdOrPath, String sha, CommitStatusFilter filter) throws GitLabApiException {
return (getCommitStatuses(projectIdOrPath, sha, filter, getDefaultPerPage()).stream());
}
/**
* <p>Add or update the build status of a commit. The following fluent methods are available on the
* CommitStatus instance for setting up the status:</p>
......@@ -373,9 +417,8 @@ public class CommitsApi extends AbstractApi {
* withRef(String)
* withTargetUrl(String)
* </code></pre>
* <pre><code>
* POST /projects/:id/statuses/:sha
* </code></pre>
*
* <pre><code>GitLab Endpoint: POST /projects/:id/statuses/:sha</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance (required)
* @param sha a commit SHA (required)
......@@ -410,7 +453,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get the list of diffs of a commit in a project.
*
* GET /projects/:id/repository/commits/:sha/diff
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/diff</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -425,7 +468,7 @@ public class CommitsApi extends AbstractApi {
/**
* Get the comments of a commit in a project.
*
* GET /projects/:id/repository/commits/:sha/comments
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/comments</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -433,14 +476,13 @@ public class CommitsApi extends AbstractApi {
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Comment> getComments(Object projectIdOrPath, String sha) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "comments");
return (response.readEntity(new GenericType<List<Comment>>() {}));
return (getComments(projectIdOrPath, sha, getDefaultPerPage()).all());
}
/**
* Get a Pager of the comments of a commit in a project.
*
* GET /projects/:id/repository/commits/:sha/comments
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/comments</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -452,11 +494,25 @@ public class CommitsApi extends AbstractApi {
return new Pager<Comment>(this, Comment.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "repository", "commits", sha, "comments");
}
/**
* Get the comments of a commit in a project as a Stream.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/repository/commits/:sha/comments</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
* @return a Stream of Comment instances for the specified project ID/sha pair
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Stream<Comment> getCommentsStream(Object projectIdOrPath, String sha) throws GitLabApiException {
return (getComments(projectIdOrPath, sha, getDefaultPerPage()).stream());
}
/**
* Add a comment to a commit. In order to post a comment in a particular line of a particular file,
* you must specify the full commit SHA, the path, the line and lineType should be NEW.
*
* POST /projects/:id/repository/commits/:sha/comments
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/commits/:sha/comments</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -480,7 +536,7 @@ public class CommitsApi extends AbstractApi {
/**
* Add a comment to a commit.
*
* POST /projects/:id/repository/commits/:sha/comments
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/commits/:sha/comments</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sha a commit hash or name of a branch or tag
......@@ -495,7 +551,7 @@ public class CommitsApi extends AbstractApi {
/**
* Create a commit with multiple files and actions.
*
* POST /projects/:id/repository/commits
* <pre><code>GitLab Endpoint: POST /projects/:id/repository/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param branch tame of the branch to commit into. To create a new branch, also provide startBranch
......
......@@ -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));
}
}
......@@ -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;
......@@ -27,20 +28,20 @@ public class MergeRequestApi extends AbstractApi {
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
* <pre><code>GitLab Endpoint: GET /merge_requests</code></pre>
*
* @param filter a MergeRequestFilter instance with the filter settings
* @return all merge requests for the specified project matching the filter
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(MergeRequestFilter filter) throws GitLabApiException {
return (getMergeRequests(filter, 1, getDefaultPerPage()));
return (getMergeRequests(filter, getDefaultPerPage()).all());
}
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
* <pre><code>GitLab Endpoint: GET /merge_requests</code></pre>
*
* @param filter a MergeRequestFilter instance with the filter settings
* @param page the page to get
......@@ -71,7 +72,7 @@ public class MergeRequestApi extends AbstractApi {
/**
* Get all merge requests matching the filter.
*
* GET /merge_requests
* <pre><code>GitLab Endpoint: GET /merge_requests</code></pre>
*
* @param filter a MergeRequestFilter instance with the filter settings
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
......@@ -94,99 +95,139 @@ public class MergeRequestApi extends AbstractApi {
}
}
/**
* Get all merge requests matching the filter as a Stream.
*
* <pre><code>GitLab Endpoint: GET /merge_requests</code></pre>
*
* @param filter a MergeRequestFilter instance with the filter settings
* @return a Stream containing all the merge requests for the specified project matching the filter
* @throws GitLabApiException if any exception occurs
*/
public Stream<MergeRequest> getMergeRequestsStream(MergeRequestFilter filter) throws GitLabApiException {
return (getMergeRequests(filter, getDefaultPerPage()).stream());
}
/**
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId) throws GitLabApiException {
return (getMergeRequests(projectId, 1, getDefaultPerPage()));
public List<MergeRequest> getMergeRequests(Object projectIdOrPath) throws GitLabApiException {
return (getMergeRequests(projectIdOrPath, getDefaultPerPage()).all());
}
/**
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectId the project ID to get the merge requests 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 MergeRequest instances per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", projectId, "merge_requests");
public List<MergeRequest> getMergeRequests(Object projectIdOrPath, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
}
/**
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public Pager<MergeRequest> getMergeRequests(Integer projectId, int itemsPerPage) throws GitLabApiException {
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, null, "projects", projectId, "merge_requests"));
public Pager<MergeRequest> getMergeRequests(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException {
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests"));
}
/**
* Get all merge requests for the specified project as a Stream
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @return a Stream with all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public Stream<MergeRequest> getMergeRequestsStream(Object projectIdOrPath) throws GitLabApiException {
return (getMergeRequests(projectIdOrPath, getDefaultPerPage()).stream());
}
/**
* Get all merge requests with a specific state for the specified project.
*
* GET /projects/:id/merge_requests?state=:state
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests?state=:state</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all).
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state) throws GitLabApiException {
return (getMergeRequests(projectId, state, 1, getDefaultPerPage()));
public List<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestState state) throws GitLabApiException {
return (getMergeRequests(projectIdOrPath, state, getDefaultPerPage()).all());
}
/**
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all).
* @param page the page to get
* @param perPage the number of MergeRequest instances per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public List<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int page, int perPage) throws GitLabApiException {
public List<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestState state, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state)
.withParam(PAGE_PARAM, page)
.withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests");
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests");
return (response.readEntity(new GenericType<List<MergeRequest>>() {}));
}
/**
* Get all merge requests for the specified project.
*
* GET /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all).
* @param itemsPerPage the number of MergeRequest instances that will be fetched per page
* @return all merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public Pager<MergeRequest> getMergeRequests(Integer projectId, MergeRequestState state, int itemsPerPage) throws GitLabApiException {
public Pager<MergeRequest> getMergeRequests(Object projectIdOrPath, MergeRequestState state, int itemsPerPage) throws GitLabApiException {
Form formData = new GitLabApiForm()
.withParam("state", state);
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", projectId, "merge_requests"));
return (new Pager<MergeRequest>(this, MergeRequest.class, itemsPerPage, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests"));
}
/**
* Get all merge requests with a specific state for the specified project as a Stream.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests?state=:state</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param state the state parameter can be used to get only merge requests with a given state (opened, closed, or merged) or all of them (all).
* @return a Stream with all the merge requests for the specified project
* @throws GitLabApiException if any exception occurs
*/
public Stream<MergeRequest> getMergeRequestsStream(Object projectIdOrPath, MergeRequestState state) throws GitLabApiException {
return (getMergeRequests(projectIdOrPath, state, getDefaultPerPage()).stream());
}
/**
......@@ -194,15 +235,15 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_id
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_id</code></pre>
*
* @param projectId the project ID of the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return the specified MergeRequest instance
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest getMergeRequest(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestIid);
public MergeRequest getMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid);
return (response.readEntity(MergeRequest.class));
}
......@@ -211,15 +252,15 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_id
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_id</code></pre>
*
* @param projectId the project ID of the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return the specified MergeRequest as an Optional instance instance
*/
public Optional<MergeRequest> getOptionalMergeRequest(Integer projectId, Integer mergeRequestIid) {
public Optional<MergeRequest> getOptionalMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) {
try {
return (Optional.ofNullable(getMergeRequest(projectId, mergeRequestIid)));
return (Optional.ofNullable(getMergeRequest(projectIdOrPath, mergeRequestIid)));
} catch (GitLabApiException glae) {
return (GitLabApi.createOptionalFromException(glae));
}
......@@ -230,15 +271,15 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_iid/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/commits</code></pre>
*
* @param projectId the project ID for the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a list containing the commits for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(int projectId, int mergeRequestIid) throws GitLabApiException {
return (getCommits(projectId, mergeRequestIid, 1, getDefaultPerPage()));
public List<Commit> getCommits(Object projectIdOrPath, int mergeRequestIid) throws GitLabApiException {
return (getCommits(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}
/**
......@@ -246,18 +287,18 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_iid/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/commits</code></pre>
*
* @param projectId the project ID for the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param page the page to get
* @param perPage the number of commits per page
* @return a list containing the commits for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public List<Commit> getCommits(int projectId, int mergeRequestIid, int page, int perPage) throws GitLabApiException {
public List<Commit> getCommits(Object projectIdOrPath, int mergeRequestIid, int page, int perPage) throws GitLabApiException {
Form formData = new GitLabApiForm().withParam("owned", true).withParam(PAGE_PARAM, page).withParam(PER_PAGE_PARAM, perPage);
Response response = get(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "commits");
Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "commits");
return (response.readEntity(new GenericType<List<Commit>>() {}));
}
......@@ -266,25 +307,41 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* GET /projects/:id/merge_requests/:merge_request_iid/commits
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/commits</code></pre>
*
* @param projectId the project ID for the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param itemsPerPage the number of Commit instances that will be fetched per page
* @return a Pager containing the commits for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Pager<Commit> getCommits(int projectId, int mergeRequestIid, int itemsPerPage) throws GitLabApiException {
public Pager<Commit> getCommits(Object projectIdOrPath, int mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return (new Pager<Commit>(this, Commit.class, itemsPerPage, null,
"projects", projectId, "merge_requests", mergeRequestIid, "commits"));
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "commits"));
}
/**
* Get a Stream of merge request commits.
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/commits</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a Stream containing the commits for the specified merge request
* @throws GitLabApiException GitLabApiException if any exception occurs during execution
*/
public Stream<Commit> getCommitsStream(Object projectIdOrPath, int mergeRequestIid) throws GitLabApiException {
return (getCommits(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}
/**
* Creates a merge request and optionally assigns a reviewer to it.
*
* POST /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests</code></pre>
*
* @param projectId the ID of a project, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sourceBranch the source branch, required
* @param targetBranch the target branch, required
* @param title the title for the merge request, required
......@@ -299,12 +356,8 @@ public class MergeRequestApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
* @since GitLab Starter 8.17, GitLab CE 11.0.
*/
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch, Boolean squash)
throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public MergeRequest createMergeRequest(Object projectIdOrPath, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch, Boolean squash) throws GitLabApiException {
Form formData = new Form();
addFormParam(formData, "source_branch", sourceBranch, true);
......@@ -318,16 +371,16 @@ public class MergeRequestApi extends AbstractApi {
addFormParam(formData, "remove_source_branch", removeSourceBranch, false);
addFormParam(formData, "squash", squash, false);
Response response = post(Response.Status.CREATED, formData, "projects", projectId, "merge_requests");
Response response = post(Response.Status.CREATED, formData, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests");
return (response.readEntity(MergeRequest.class));
}
/**
* Creates a merge request and optionally assigns a reviewer to it.
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
*
* POST /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests</code></pre>
*
* @param projectId the ID of a project, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sourceBranch the source branch, required
* @param targetBranch the target branch, required
* @param title the title for the merge request, required
......@@ -340,18 +393,18 @@ public class MergeRequestApi extends AbstractApi {
* @return the created MergeRequest instance
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
public MergeRequest createMergeRequest(Object projectIdOrPath, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId,
Integer targetProjectId, String[] labels, Integer milestoneId, Boolean removeSourceBranch)
throws GitLabApiException {
return createMergeRequest(projectId, sourceBranch, targetBranch, title, description, assigneeId, targetProjectId, labels, milestoneId, removeSourceBranch, null);
return createMergeRequest(projectIdOrPath, sourceBranch, targetBranch, title, description, assigneeId, targetProjectId, labels, milestoneId, removeSourceBranch, null);
}
/**
* Creates a merge request and optionally assigns a reviewer to it.
*
* POST /projects/:id/merge_requests
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests</code></pre>
*
* @param projectId the ID of a project, required
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param sourceBranch the source branch, required
* @param targetBranch the target branch, required
* @param title the title for the merge request, required
......@@ -360,9 +413,9 @@ public class MergeRequestApi extends AbstractApi {
* @return the created MergeRequest instance
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest createMergeRequest(Integer projectId, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId)
public MergeRequest createMergeRequest(Object projectIdOrPath, String sourceBranch, String targetBranch, String title, String description, Integer assigneeId)
throws GitLabApiException {
return createMergeRequest(projectId, sourceBranch, targetBranch, title, description, assigneeId, null, null, null, null);
return createMergeRequest(projectIdOrPath, sourceBranch, targetBranch, title, description, assigneeId, null, null, null, null);
}
/**
......@@ -370,9 +423,9 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request to update
* @param targetBranch the target branch, optional
* @param title the title for the merge request
......@@ -390,7 +443,7 @@ public class MergeRequestApi extends AbstractApi {
* @return the updated merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIid,
public MergeRequest updateMergeRequest(Object projectIdOrPath, Integer mergeRequestIid,
String targetBranch, String title, Integer assigneeId, String description,
StateEvent stateEvent, String labels, Integer milestoneId, Boolean removeSourceBranch,
Boolean squash, Boolean discussionLocked, Boolean allowCollaboration)
......@@ -409,7 +462,7 @@ public class MergeRequestApi extends AbstractApi {
.withParam("discussion_locked", discussionLocked)
.withParam("allow_collaboration", allowCollaboration);
return updateMergeRequest(projectId, mergeRequestIid, formData);
return updateMergeRequest(projectIdOrPath, mergeRequestIid, formData);
}
/**
......@@ -417,9 +470,9 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request to update
* @param targetBranch the target branch, optional
* @param title the title for the merge request
......@@ -432,7 +485,7 @@ public class MergeRequestApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
@Deprecated
public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIid, String targetBranch,
public MergeRequest updateMergeRequest(Object projectIdOrPath, Integer mergeRequestIid, String targetBranch,
String title, Integer assigneeId, String description, StateEvent stateEvent, String labels,
Integer milestoneId) throws GitLabApiException {
......@@ -445,7 +498,7 @@ public class MergeRequestApi extends AbstractApi {
.withParam("labels", labels)
.withParam("milestone_id", milestoneId);
return updateMergeRequest(projectId, mergeRequestIid, formData);
return updateMergeRequest(projectIdOrPath, mergeRequestIid, formData);
}
/**
......@@ -453,9 +506,9 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request to update
* @param sourceBranch the source branch
* @param targetBranch the target branch
......@@ -467,7 +520,7 @@ public class MergeRequestApi extends AbstractApi {
* @deprecated as of release 4.4.3
*/
@Deprecated
public MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIid, String sourceBranch, String targetBranch, String title, String description,
public MergeRequest updateMergeRequest(Object projectIdOrPath, Integer mergeRequestIid, String sourceBranch, String targetBranch, String title, String description,
Integer assigneeId) throws GitLabApiException {
Form formData = new Form();
......@@ -477,21 +530,17 @@ public class MergeRequestApi extends AbstractApi {
addFormParam(formData, "description", description, false);
addFormParam(formData, "assignee_id", assigneeId, false);
return updateMergeRequest(projectId, mergeRequestIid, formData);
return updateMergeRequest(projectIdOrPath, mergeRequestIid, formData);
}
protected MergeRequest updateMergeRequest(Integer projectId, Integer mergeRequestIid,
protected MergeRequest updateMergeRequest(Object projectIdOrPath, Integer mergeRequestIid,
Form formData) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestId cannot be null");
}
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId,
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath),
"merge_requests", mergeRequestIid);
return (response.readEntity(MergeRequest.class));
}
......@@ -501,24 +550,20 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* DELETE /projects/:id/merge_requests/:merge_request_iid
* <pre><code>GitLab Endpoint: DELETE /projects/:id/merge_requests/:merge_request_iid</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @throws GitLabApiException if any exception occurs
*/
public void deleteMergeRequest(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public void deleteMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
Response.Status expectedStatus = (isApiVersion(ApiVersion.V3) ? Response.Status.OK : Response.Status.NO_CONTENT);
delete(expectedStatus, null, "projects", projectId, "merge_requests", mergeRequestIid);
delete(expectedStatus, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid);
}
/**
......@@ -531,15 +576,15 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid/merge
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/merge</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return the merged merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
return (acceptMergeRequest(projectId, mergeRequestIid, null, null, null, null));
public MergeRequest acceptMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (acceptMergeRequest(projectIdOrPath, mergeRequestIid, null, null, null, null));
}
/**
......@@ -553,9 +598,9 @@ public class MergeRequestApi extends AbstractApi {
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request. Additionally,
* mergeWhenPipelineSucceeds sets the merge_when_build_succeeds flag for GitLab API V3.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid/merge
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/merge</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param mergeCommitMessage, custom merge commit message, optional
* @param shouldRemoveSourceBranch, if true removes the source branch, optional
......@@ -563,10 +608,10 @@ public class MergeRequestApi extends AbstractApi {
* @return the merged merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
public MergeRequest acceptMergeRequest(Object projectIdOrPath, Integer mergeRequestIid,
String mergeCommitMessage, Boolean shouldRemoveSourceBranch, Boolean mergeWhenPipelineSucceeds)
throws GitLabApiException {
return (acceptMergeRequest(projectId, mergeRequestIid, mergeCommitMessage,
return (acceptMergeRequest(projectIdOrPath, mergeRequestIid, mergeCommitMessage,
shouldRemoveSourceBranch, mergeWhenPipelineSucceeds, null));
}
......@@ -581,9 +626,9 @@ public class MergeRequestApi extends AbstractApi {
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request. Additionally,
* mergeWhenPipelineSucceeds sets the merge_when_build_succeeds flag for GitLab API V3.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid/merge
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/merge</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param mergeCommitMessage, custom merge commit message, optional
* @param shouldRemoveSourceBranch, if true removes the source branch, optional
......@@ -592,14 +637,10 @@ public class MergeRequestApi extends AbstractApi {
* @return the merged merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest acceptMergeRequest(Integer projectId, Integer mergeRequestIid,
public MergeRequest acceptMergeRequest(Object projectIdOrPath, Integer mergeRequestIid,
String mergeCommitMessage, Boolean shouldRemoveSourceBranch, Boolean mergeWhenPipelineSucceeds, String sha)
throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
......@@ -612,7 +653,7 @@ public class MergeRequestApi extends AbstractApi {
mergeWhenPipelineSucceeds)
.withParam("sha", sha);
Response response = put(Response.Status.OK, formData.asMap(), "projects", projectId, "merge_requests", mergeRequestIid, "merge");
Response response = put(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "merge");
return (response.readEntity(MergeRequest.class));
}
......@@ -624,24 +665,20 @@ public class MergeRequestApi extends AbstractApi {
*
* <p>NOTE: GitLab API V4 uses IID (internal ID), V3 uses ID to identify the merge request.</p>
*
* PUT /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds
* <pre><code>GitLab Endpoint: PUT /projects/:id/merge_requests/:merge_request_iid/cancel_merge_when_pipeline_succeeds</code></pre>
*
* @param projectId the ID of a project
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return the updated merge request
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest cancelMergeRequest(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public MergeRequest cancelMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
Response response = put(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestIid, "cancel_merge_when_pipeline_succeeds");
Response response = put(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "cancel_merge_when_pipeline_succeeds");
return (response.readEntity(MergeRequest.class));
}
......@@ -650,24 +687,20 @@ public class MergeRequestApi extends AbstractApi {
*
* Note: This API endpoint is only available on 8.9 EE and above.
*
* GET /projects/:id/merge_requests/:merge_request_iid/approvals
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/approvals</code></pre>
*
* @param projectId the project ID of the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a MergeRequest instance with approval information included
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest getMergeRequestApprovals(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public MergeRequest getMergeRequestApprovals(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
Response response = get(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestIid, "approvals");
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approvals");
return (response.readEntity(MergeRequest.class));
}
......@@ -676,26 +709,22 @@ public class MergeRequestApi extends AbstractApi {
*
* Note: This API endpoint is only available on 8.9 EE and above.
*
* POST /projects/:id/merge_requests/:merge_request_iid/approve
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests/:merge_request_iid/approve</code></pre>
*
* @param projectId the project ID of the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @param sha the HEAD of the merge request, optional
* @return a MergeRequest instance with approval information included
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest approveMergeRequest(Integer projectId, Integer mergeRequestIid, String sha) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public MergeRequest approveMergeRequest(Object projectIdOrPath, Integer mergeRequestIid, String sha) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
Form formData = new GitLabApiForm().withParam("sha", sha);
Response response = post(Response.Status.OK, formData, "projects", projectId, "merge_requests", mergeRequestIid, "approve");
Response response = post(Response.Status.OK, formData, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "approve");
return (response.readEntity(MergeRequest.class));
}
......@@ -704,91 +733,102 @@ public class MergeRequestApi extends AbstractApi {
*
* Note: This API endpoint is only available on 8.9 EE and above.
*
* POST /projects/:id/merge_requests/:merge_request_iid/unapprove
* <pre><code>GitLab Endpoint: POST /projects/:id/merge_requests/:merge_request_iid/unapprove</code></pre>
*
* @param projectId the project ID of the merge request
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the internal ID of the merge request
* @return a MergeRequest instance with approval information included
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest unapproveMergeRequest(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
if (projectId == null) {
throw new RuntimeException("projectId cannot be null");
}
public MergeRequest unapproveMergeRequest(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
if (mergeRequestIid == null) {
throw new RuntimeException("mergeRequestIid cannot be null");
}
Response response = post(Response.Status.OK, (Form)null, "projects", projectId, "merge_requests", mergeRequestIid, "unapprove");
Response response = post(Response.Status.OK, (Form)null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "unapprove");
return (response.readEntity(MergeRequest.class));
}
/**
* Get merge request with changes information.
*
* GET /projects/:id/merge_requests/:merge_request_iid/changes
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/changes</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the IID of the merge request to get
* @return a merge request including its changes
* @throws GitLabApiException if any exception occurs
*/
public MergeRequest getMergeRequestChanges(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", projectId, "merge_requests", mergeRequestIid, "changes");
public MergeRequest getMergeRequestChanges(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
Response response = get(Response.Status.OK, null, "projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "changes");
return (response.readEntity(MergeRequest.class));
}
/**
* Get list of participants of merge request.
*
* GET /projects/:id/merge_requests/:merge_request_iid/participants
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/participants</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the IID of the merge request to get
* @return a List containing all participants for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public List<Participant> getParticipants(Integer projectId, Integer mergeRequestIid) throws GitLabApiException {
return (getParticipants(projectId, mergeRequestIid, 1, getDefaultPerPage()));
public List<Participant> getParticipants(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (getParticipants(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}
/**
* Get list of participants of merge request and in the specified page range.
*
* GET /projects/:id/merge_requests/:merge_request_iid/participants
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/participants</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the IID of the merge request to get
* @param page the page to get
* @param perPage the number of projects per page
* @return a List containing all participants for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public List<Participant> getParticipants(Integer projectId, Integer mergeRequestIid, int page, int perPage) throws GitLabApiException {
public List<Participant> getParticipants(Object projectIdOrPath, Integer mergeRequestIid, int page, int perPage) throws GitLabApiException {
Response response = get(Response.Status.OK, getPageQueryParams(page, perPage),
"projects", projectId, "merge_requests", mergeRequestIid, "participants");
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "participants");
return (response.readEntity(new GenericType<List<Participant>>() { }));
}
/**
* Get a Pager of the participants of merge request.
*
* GET /projects/:id/merge_requests/:merge_request_iid/participants
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/participants</code></pre>
*
* @param projectId the project ID to get the merge requests for
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the IID of the merge request to get
* @param itemsPerPage the number of Participant instances that will be fetched per page
* @return a Pager containing all participants for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Pager<Participant> getParticipants(Integer projectId, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return new Pager<Participant>(this, Participant.class, itemsPerPage, null, "projects", projectId, "merge_requests", mergeRequestIid, "participants");
public Pager<Participant> getParticipants(Object projectIdOrPath, Integer mergeRequestIid, int itemsPerPage) throws GitLabApiException {
return new Pager<Participant>(this, Participant.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "participants");
}
/**
* Get Stream of participants of merge request.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/participants</code></pre>
*
* @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance
* @param mergeRequestIid the IID of the merge request to get
* @return a Stream containing all participants for the specified merge request
* @throws GitLabApiException if any exception occurs
*/
public Stream<Participant> getParticipantsStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (getParticipants(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}
/**
* Get list containing all the issues that would be closed by merging the provided merge requestt.
* Get list containing all the issues that would be closed by merging the provided merge request.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/closes_issues</code></pre>
*
......@@ -798,7 +838,7 @@ public class MergeRequestApi extends AbstractApi {
* @throws GitLabApiException if any exception occurs
*/
public List<Issue> getClosesIssues(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (getClosesIssues(projectIdOrPath, mergeRequestIid, 1, getDefaultPerPage()));
return (getClosesIssues(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).all());
}
/**
......@@ -834,4 +874,18 @@ public class MergeRequestApi extends AbstractApi {
return new Pager<Issue>(this, Issue.class, itemsPerPage, null,
"projects", getProjectIdOrPath(projectIdOrPath), "merge_requests", mergeRequestIid, "closes_issues");
}
/**
* Get Stream containing all the issues that would be closed by merging the provided merge request.
*
* <pre><code>GitLab Endpoint: GET /projects/:id/merge_requests/:merge_request_iid/closes_issues</code></pre>
*
* @param projectIdOrPath id, path of the project, or a Project instance holding the project ID or path
* @param mergeRequestIid the IID of the merge request to get the closes issues for
* @return a Stream containing all the issues that would be closed by merging the provided merge request
* @throws GitLabApiException if any exception occurs
*/
public Stream<Issue> getClosesIssuesStream(Object projectIdOrPath, Integer mergeRequestIid) throws GitLabApiException {
return (getClosesIssues(projectIdOrPath, mergeRequestIid, getDefaultPerPage()).stream());
}
}
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