2

我对 gitlab 非常“愚蠢”,我的问题听起来很愚蠢......但是它去了哪里......

我想使用 java 连接到 gitlab 存储库,这个想法只是检索存储库的“条目”列表

我似乎有一些java代码,但我不确定发送到“connect”方法的url是什么。

使用网络浏览器,网址类似于https://gitlab.zzz.com/

示例: 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); }

另外,我只有用户名和密码..没有oauth令牌..没有令牌可以连接吗?

对于我的愚蠢问题,我很抱歉,也许你们中的一些人可以提供一些如何开始的提示。

谢谢罗克

4

3 回答 3

0

您可以使用 GitLab4J ( https://github.com/gmessner/gitlab4j-api ) 来执行此操作。它允许您使用用户名和密码进行连接,并在内部处理返回的会话令牌。

// 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();
于 2017-08-22T15:36:19.350 回答
0

从 Gitlab 获取数据的正确方法是通过 Gitlab API ( https://docs.gitlab.com/ee/api/README.html )。根据文档,您首先使用您的用户名和密码获得令牌。此外,您使用此令牌访问其他资源

于 2016-12-15T11:08:12.560 回答
0

我能够使用以下 Java gitlab API 连接到 gitlab。为此,您需要允许防火墙。

@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";
    }

}
于 2019-10-12T18:10:09.233 回答