GitLabApi.java 36.70 KiB
package org.gitlab4j.api;
import java.util.Map;
import javax.ws.rs.core.Response;
import org.gitlab4j.api.Constants.TokenType;
import org.gitlab4j.api.models.OauthTokenResponse;
import org.gitlab4j.api.models.Session;
import org.gitlab4j.api.models.User;
import org.gitlab4j.api.models.Version;
/**
 * This class is provides a simplified interface to a GitLab API server, and divides the API up into
 * a separate API class for each concern.
public class GitLabApi {
    /** GitLab4J default per page.  GitLab will ignore anything over 100. */
    public static final int DEFAULT_PER_PAGE = 100;
    /** Specifies the version of the GitLab API to communicate with. */
    public enum ApiVersion {
        V3, V4, OAUTH2_CLIENT;
        public String getApiNamespace() {
            return ("/api/" + name().toLowerCase());
    GitLabApiClient apiClient;
    private ApiVersion apiVersion;
    private String gitLabServerUrl;
    private Map<String, Object> clientConfigProperties;
    private int defaultPerPage = DEFAULT_PER_PAGE;
    private Session session;
    private CommitsApi commitsApi;
    private DeployKeysApi deployKeysApi;
    private GroupApi groupApi;
    private IssuesApi issuesApi;
    private MergeRequestApi mergeRequestApi;
    private MilestonesApi milestonesApi;
    private NamespaceApi namespaceApi;
    private PipelineApi pipelineApi;
    private ProjectApi projectApi;
    private RepositoryApi repositoryApi;
    private RepositoryFileApi repositoryFileApi;
    private ServicesApi servicesApi;
    private SessionApi sessionApi;
    private SystemHooksApi systemHooksApi;
    private UserApi userApi;
    private JobApi jobApi;
    private LabelsApi labelsApi;
    private NotesApi notesApi;
    private EventsApi eventsApi;
    /**
     * Create a new GitLabApi instance that is logically a duplicate of this instance, with the exception off sudo state.
     * @return a new GitLabApi instance that is logically a duplicate of this instance, with the exception off sudo state.
    public final GitLabApi duplicate() {
        Integer sudoUserId = this.getSudoAsId();
        GitLabApi gitLabApi = new GitLabApi(apiVersion, gitLabServerUrl,
                getTokenType(), getAuthToken(), getSecretToken(), clientConfigProperties);
        if (sudoUserId != null) {
            gitLabApi.apiClient.setSudoAsId(sudoUserId);
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
} if (getIgnoreCertificateErrors()) { gitLabApi.setIgnoreCertificateErrors(true); } gitLabApi.defaultPerPage = this.defaultPerPage; return (gitLabApi); } /** * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password}, * and creates a new {@code GitLabApi} instance using returned access token.</p> * * @param url GitLab URL * @param username user name for which private token should be obtained * @param password password for a given {@code username} * @return new {@code GitLabApi} instance configured for a user-specific token * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public static GitLabApi oauth2Login(String url, String username, String password) throws GitLabApiException { return (GitLabApi.oauth2Login(ApiVersion.V4, url, username, password, null, null, false)); } /** * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password}, * and creates a new {@code GitLabApi} instance using returned access token.</p> * * @param url GitLab URL * @param username user name for which private token should be obtained * @param password password for a given {@code username} * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors * @return new {@code GitLabApi} instance configured for a user-specific token * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public static GitLabApi oauth2Login(String url, String username, String password, boolean ignoreCertificateErrors) throws GitLabApiException { return (GitLabApi.oauth2Login(ApiVersion.V4, url, username, password, null, null, ignoreCertificateErrors)); } /** * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password}, * and creates a new {@code GitLabApi} instance using returned access token.</p> * * @param url GitLab URL * @param username user name for which private token should be obtained * @param password password for a given {@code username} * @param secretToken use this token to validate received payloads * @param clientConfigProperties Map instance with additional properties for the Jersey client connection * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors * @return new {@code GitLabApi} instance configured for a user-specific token * @throws GitLabApiException GitLabApiException if any exception occurs during execution */ public static GitLabApi oauth2Login(String url, String username, String password, String secretToken, Map<String, Object> clientConfigProperties, boolean ignoreCertificateErrors) throws GitLabApiException { return (GitLabApi.oauth2Login(ApiVersion.V4, url, username, password, secretToken, clientConfigProperties, ignoreCertificateErrors)); } /** * <p>Logs into GitLab using OAuth2 with the provided {@code username} and {@code password}, * and creates a new {@code GitLabApi} instance using returned access token.</p> * * @param url GitLab URL * @param apiVersion the ApiVersion specifying which version of the API to use * @param username user name for which private token should be obtained * @param password password for a given {@code username} * @param secretToken use this token to validate received payloads * @param clientConfigProperties Map instance with additional properties for the Jersey client connection * @param ignoreCertificateErrors if true will set up the Jersey system ignore SSL certificate errors * @return new {@code GitLabApi} instance configured for a user-specific token