Antonio Roque
Antonio Roque

Reputation: 325

connect to a gitlab using gitlab java api

I´m very "dummy" about gitlab , my question my sound stupid ... but where it goes ..

I would like to connect to a gitlab repo using java , the idea is just to retrieve the list of "entry´s" of the repository

I have seem some java code, but I´m not sure what will the url the send to "connect" method .

using the web browser the url is something like this https://gitlab.zzz.com/

example :

  public static GitlabSession connect(String hostUrl, String username, String password) throws IOException {
        String tailUrl = GitlabSession.URL;
        GitlabAPI api = connect(**hostUrl**, null, null, null);
        return api.dispatch().with("login", username).with("password", password)
                .to(tailUrl, GitlabSession.class);
    }

Also, I only have the user and password .. no oauth token .. is possible to connect without the token ?

I sorry for my dummy questions, may some of you can give some tips how to start.

Thank you Roque

Upvotes: 2

Views: 14586

Answers (3)

RKumar
RKumar

Reputation: 1

I was able to connect to gitlab using following Java gitlab API.For this, you need to Allow firewall.

@RestController
@RequestMapping("/test")`enter code here`
public class GitlabController {

    @RequestMapping("/hello")
    public String getGitData() throws GitLabApiException {

        System.out.println("going to execute gitlab api..");
        GitLabApi gitLabApi = GitLabApi.login("https://gitlab.<domain>.com/", "USERNAME", "PASSWORD");
        User currentUser = gitLabApi.getUserApi().getCurrentUser();
        System.out.println(currentUser.getUsername());
        return "returning from git Controller";
    }

}

Upvotes: 0

messnerized
messnerized

Reputation: 26

You could use GitLab4J (https://github.com/gmessner/gitlab4j-api) to do this. It allows you to connect with a username and password and internally handles the returned session token.

// Create a GitLabApi instance to communicate with your GitLab server
GitLabApi gitLabApi = GitLabApi.login("http://your.gitlab.server.com", "USERNAME", "PASSWORD");

// Get the list of projects your account has access to
List<Project> projects = gitLabApi.getProjectApi().getProjects();

Upvotes: 0

Abzal Kalimbetov
Abzal Kalimbetov

Reputation: 505

Proper way to get data from Gitlab is through Gitlab API (https://docs.gitlab.com/ee/api/README.html). According to documentation you get token first using your username and password. Further you use this token to access other resources

Upvotes: 0

Related Questions