IssuesApi.java 32.77 KiB
/*
 * The MIT License (MIT)
 * Copyright (c) 2017 Greg Messner <greg@messners.com>
 * Permission is hereby granted, free of charge, to any person obtaining a copy of
 * this software and associated documentation files (the "Software"), to deal in
 * the Software without restriction, including without limitation the rights to
 * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
 * the Software, and to permit persons to whom the Software is furnished to do so,
 * subject to the following conditions:
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
 * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
 * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
 * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.Duration;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.IssueFilter;
import org.gitlab4j.api.models.MergeRequest;
import org.gitlab4j.api.models.TimeStats;
import org.gitlab4j.api.utils.DurationUtils;
/**
 * This class provides an entry point to all the GitLab API Issue calls.
public class IssuesApi extends AbstractApi implements Constants {
    public IssuesApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    /**
     * Get all issues the authenticated user has access to. Only returns issues created by the current user.
     * <pre><code>GitLab Endpoint: GET /issues</code></pre>
     * @return a list of user's issues
     * @throws GitLabApiException if any exception occurs
    public List<Issue> getIssues() throws GitLabApiException {
        return (getIssues(getDefaultPerPage()).all());
    /**
     * Get all issues the authenticated user has access to using the specified page and per page setting. Only returns issues created by the current user.
     * <pre><code>GitLab Endpoint: GET /issues</code></pre>
     * @param page the page to get
     * @param perPage the number of issues per page
     * @return the list of issues in the specified range
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
* @throws GitLabApiException if any exception occurs */ public List<Issue> getIssues(int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "issues"); return (response.readEntity(new GenericType<List<Issue>>() {})); } /** * Get a Pager of all issues the authenticated user has access to. Only returns issues created by the current user. * * <pre><code>GitLab Endpoint: GET /issues</code></pre> *r * @param itemsPerPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs */ public Pager<Issue> getIssues(int itemsPerPage) throws GitLabApiException { return (new Pager<Issue>(this, Issue.class, itemsPerPage, null, "issues")); } /** * Get all issues the authenticated user has access to as a Stream. Only returns issues created by the current user. * * <pre><code>GitLab Endpoint: GET /issues</code></pre> * * @return a Stream of user's issues * @throws GitLabApiException if any exception occurs */ public Stream<Issue> getIssuesStream() throws GitLabApiException { return (getIssues(getDefaultPerPage()).stream()); } /** * Get a list of project's issues. Only returns the first page * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @return a list of project's issues * @throws GitLabApiException if any exception occurs */ public List<Issue> getIssues(Object projectIdOrPath) throws GitLabApiException { return (getIssues(projectIdOrPath, getDefaultPerPage()).all()); } /** * Get a list of project's issues using the specified page and per page settings. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @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 issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs */ public List<Issue> getIssues(Object projectIdOrPath, int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects", getProjectIdOrPath(projectIdOrPath), "issues"); return (response.readEntity(new GenericType<List<Issue>>() {})); } /** * Get a Pager of project's issues. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param itemsPerPage the number of issues per page * @return the list of issues in the specified range * @throws GitLabApiException if any exception occurs
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
*/ public Pager<Issue> getIssues(Object projectIdOrPath, int itemsPerPage) throws GitLabApiException { return (new Pager<Issue>(this, Issue.class, itemsPerPage, null, "projects", getProjectIdOrPath(projectIdOrPath), "issues")); } /** * Get a Stream of project's issues. Only returns the first page * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @return a Stream of project's issues * @throws GitLabApiException if any exception occurs */ public Stream<Issue> getIssuesStream(Object projectIdOrPath) throws GitLabApiException { return (getIssues(projectIdOrPath, getDefaultPerPage()).stream()); } /** * Get a list of project's issues. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public List<Issue> getIssues(Object projectIdOrPath, IssueFilter filter) throws GitLabApiException { return (getIssues(projectIdOrPath, filter, getDefaultPerPage()).all()); } /** * Get a list of project's issues. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param page the page to get. * @param perPage the number of projects per page. * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public List<Issue> getIssues(Object projectIdOrPath, IssueFilter filter, int page, int perPage) throws GitLabApiException { GitLabApiForm formData = filter.getQueryParams(page, perPage); Response response = get(Response.Status.OK, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues"); return (response.readEntity(new GenericType<List<Issue>>() {})); } /** * Get a list of project's issues. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre> * * @param projectIdOrPath the project in the form of an Integer(ID), String(path), or Project instance * @param filter {@link IssueFilter} a IssueFilter instance with the filter settings. * @param itemsPerPage the number of Project instances that will be fetched per page. * @return the list of issues in the specified range. * @throws GitLabApiException if any exception occurs */ public Pager<Issue> getIssues(Object projectIdOrPath, IssueFilter filter, int itemsPerPage) throws GitLabApiException { GitLabApiForm formData = filter.getQueryParams(); return (new Pager<Issue>(this, Issue.class, itemsPerPage, formData.asMap(), "projects", getProjectIdOrPath(projectIdOrPath), "issues")); } /** * Get a Stream of project's issues. * * <pre><code>GitLab Endpoint: GET /projects/:id/issues</code></pre>