GitLabApi.java 5.13 KiB
package com.messners.gitlab.api;
/**
 * 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.
 * 
 * @author Greg Messner <greg@messners.com>
 */
public class GitLabApi {
    GitLabApiClient apiClient;
    private CommitsApi commitsApi;
    private GroupApi groupApi;
    private MergeRequestApi mergeRequestApi;
    private ProjectApi projectApi;
    private RepositoryApi repositoryApi;
    private RepositoryFileApi repositoryFileApi;
    private ServicesApi servicesApi;
    private SessionApi sessoinApi;
    private UserApi userApi;
    /**
     * Logs into GitLab using provided {@code username} and {@code password}, and creates a new {@code GitLabApi} instance using returned private token
     * @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
    static public GitLabApi create(String url, String username, String password) throws GitLabApiException {
        String token = new SessionApi(new GitLabApi(url, null)).login(username, null, password).getPrivateToken();
        return new GitLabApi(url, token);
    /**
     * Constructs a GitLabApi instance set up to interact with the GitLab server
     * specified by hostUrl.
     * @param hostUrl
     * @param privateToken
    public GitLabApi(String hostUrl, String privateToken) {
        apiClient = new GitLabApiClient(hostUrl, privateToken);
        commitsApi = new CommitsApi(this);
        groupApi = new GroupApi(this);
        mergeRequestApi = new MergeRequestApi(this);
        projectApi = new ProjectApi(this);
        repositoryApi = new RepositoryApi(this);
        servicesApi = new ServicesApi(this);
        sessoinApi = new SessionApi(this);
        userApi = new UserApi(this);
        repositoryFileApi = new RepositoryFileApi(this);
    /**
     * Return the GitLabApiClient associated with this instance. This is used by all the sub API classes
     * to communicate with the GitLab API.
     * @return the GitLabApiClient associated with this instance
    GitLabApiClient getApiClient() {
        return (apiClient);
    /**
     * Gets the CommitsApi instance owned by this GitLabApi instance. The CommitsApi is used
     * to perform all commit related API calls.
     * @return the CommitsApi instance owned by this GitLabApi instance
7172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
public CommitsApi getCommitsApi() { return (commitsApi); } /** * Gets the MergeRequestApi instance owned by this GitLabApi instance. The MergeRequestApi is used * to perform all merge request related API calls. * * @return the MergeRequestApi instance owned by this GitLabApi instance */ public MergeRequestApi getMergeRequestApi() { return (mergeRequestApi); } /** * Gets the GroupApi instance owned by this GitLabApi instance. The GroupApi is used * to perform all group related API calls. * * @return the GroupApi instance owned by this GitLabApi instance */ public GroupApi getGroupApi() { return (groupApi); } /** * Gets the ProjectApi instance owned by this GitLabApi instance. The ProjectApi is used * to perform all project related API calls. * * @return the ProjectApi instance owned by this GitLabApi instance */ public ProjectApi getProjectApi() { return (projectApi); } /** * Gets the RepositoryApi instance owned by this GitLabApi instance. The RepositoryApi is used * to perform all repository related API calls. * * @return the RepositoryApi instance owned by this GitLabApi instance */ public RepositoryApi getRepositoryApi() { return (repositoryApi); } /** * Gets the RepositoryFileApi instance owned by this GitLabApi instance. The RepositoryFileApi is used * to perform all repository files related API calls. * * @return the RepositoryFileApi instance owned by this GitLabApi instance */ public RepositoryFileApi getRepositoryFileApi() { return repositoryFileApi; } /** * Gets the ServicesApi instance owned by this GitLabApi instance. The ServicesApi is used * to perform all services related API calls. * * @return the ServicesApi instance owned by this GitLabApi instance */ public ServicesApi getServicesApi() { return (servicesApi); } /** * Gets the SessionApi instance owned by this GitLabApi instance. The SessionApi is used * to perform a login to the GitLab API. * * @return the SessionApi instance owned by this GitLabApi instance */