ProjectApi.java 100.24 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.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.ws.rs.core.Form;
import javax.ws.rs.core.GenericType;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.GitLabApi.ApiVersion;
import org.gitlab4j.api.models.AccessLevel;
import org.gitlab4j.api.models.Event;
import org.gitlab4j.api.models.FileUpload;
import org.gitlab4j.api.models.Issue;
import org.gitlab4j.api.models.Member;
import org.gitlab4j.api.models.Project;
import org.gitlab4j.api.models.ProjectHook;
import org.gitlab4j.api.models.ProjectUser;
import org.gitlab4j.api.models.PushRules;
import org.gitlab4j.api.models.Snippet;
import org.gitlab4j.api.models.Visibility;
/**
 * This class provides an entry point to all the GitLab API project calls.
public class ProjectApi extends AbstractApi implements Constants {
    public ProjectApi(GitLabApi gitLabApi) {
        super(gitLabApi);
    /**
     * Get a list of projects accessible by the authenticated user.
     * GET /projects
     * @return a list of projects accessible by the authenticated user
     * @throws GitLabApiException if any exception occurs
    public List<Project> getProjects() throws GitLabApiException {
        Response response = get(Response.Status.OK, getDefaultPerPageParam(), "projects");
        return (response.readEntity(new GenericType<List<Project>>() {}));
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
} /** * Get a list of projects accessible by the authenticated user and in the specified page range. * * GET /projects * * @param page the page to get * @param perPage the number of projects per page * @return a list of projects accessible by the authenticated user * @throws GitLabApiException if any exception occurs */ public List<Project> getProjects(int page, int perPage) throws GitLabApiException { Response response = get(Response.Status.OK, getPageQueryParams(page, perPage), "projects"); return (response.readEntity(new GenericType<List<Project>>() { })); } /** * Get a Pager instance of projects accessible by the authenticated user. * * GET /projects * * @param itemsPerPage the number of Project instances that will be fetched per page * @return a Pager instance of projects accessible by the authenticated user * @throws GitLabApiException if any exception occurs */ public Pager<Project> getProjects(int itemsPerPage) throws GitLabApiException { return (new Pager<Project>(this, Project.class, itemsPerPage, null, "projects")); } /** * Get a list of projects accessible by the authenticated user and matching the supplied filter parameters. * All filter parameters are optional. * * GET /projects * * @param archived limit by archived status * @param visibility limit by visibility public, internal, or private * @param orderBy return projects ordered by id, name, path, created_at, updated_at, or last_activity_at fields, default is created_at * @param sort return projects sorted in asc or desc order. Default is desc * @param search return list of projects matching the search criteria * @param simple return only the ID, URL, name, and path of each project * @param owned limit by projects owned by the current user * @param membership limit by projects that the current user is a member of * @param starred limit by projects starred by the current user * @param statistics include project statistics * @return a list of projects accessible by the authenticated user and matching the supplied parameters * @throws GitLabApiException if any exception occurs * @deprecated Will be removed in version 5.0, replaced by {@link #getProjects(Boolean, Visibility, * Constants.ProjectOrderBy, Constants.SortOrder, String, Boolean, Boolean, Boolean, Boolean, Boolean)} */ public List<Project> getProjects(Boolean archived, Visibility visibility, String orderBy, String sort, String search, Boolean simple, Boolean owned, Boolean membership, Boolean starred, Boolean statistics) throws GitLabApiException { GitLabApiForm formData = new GitLabApiForm() .withParam("archived", archived) .withParam("visibility", visibility) .withParam("order_by", orderBy) .withParam("sort", sort) .withParam("search", search) .withParam("simple", simple) .withParam("owned", owned) .withParam("membership", membership) .withParam("starred", starred) .withParam("statistics", statistics) .withParam(PER_PAGE_PARAM, getDefaultPerPage()); Response response = get(Response.Status.OK, formData.asMap(), "projects"); return (response.readEntity(new GenericType<List<Project>>() {}));