编程语言
首页 > 编程语言> > 使用Java API从GitHub获取所有提交

使用Java API从GitHub获取所有提交

作者:互联网

我想使用Java API从GitHub获取所有提交.到目前为止,我设法创建了以下简单代码:

import java.io.IOException;
import java.util.List;
import org.eclipse.egit.github.core.Repository;
import org.eclipse.egit.github.core.client.GitHubClient;
import org.eclipse.egit.github.core.service.RepositoryService;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;

public class GithubImplTest
{
    public void testSomeMethod() throws IOException
    {
        GitHubClient client = new GitHubClient();
        client.setCredentials("sonratestw@gmail.com", "sono");

        RepositoryService service = new RepositoryService(client);

        List<Repository> repositories = service.getRepositories();

        for (int i = 0; i < repositories.size(); i++)
        {
            Repository get = repositories.get(i);
            System.out.println("Repository Name: " + get.getName());
        }
    }
}

如何从该帐户将所有提交提交到存储库中?

解决方法:

使用Eclipse GitHub Java API时,类CommitService提供对存储库提交的访问.可以调用方法getCommits(repository)来检索给定存储库的所有提交的列表.

用于打印存储库的所有提交的示例代码:

CommitService commitService = new CommitService(client);
for (RepositoryCommit commit : commitService.getCommits(repository)) {
    System.out.println(commit.getCommit().getMessage());
}

标签:github,github-api,java
来源: https://codeday.me/bug/20191026/1939436.html