如何使用GithubJavaAPI(org.eclipse.egit.github.*)搜索给定的提交哈希

如何使用GithubJavaAPI(org.eclipse.egit.github.*)搜索给定的提交哈希,java,api,github,github-api,egit,Java,Api,Github,Github Api,Egit,通过调用中找到的github搜索API,可以接收有关给定提交的详细信息,并提供相关的提交哈希,现在我需要使用github java API(org.eclipse.egit.github.*)获得相同的响应,该API可以在中找到。根据他们在中找到的版本2.1.5的文档,在CommitService类中没有只提供提交散列来获取提交信息的方法。是否有一个解决方法可以接触到他们?提前感谢您可以使用CommitService.getCommit(IRepositoryIdProvider,String)

通过调用中找到的
github搜索API
,可以接收有关给定提交的详细信息,并提供相关的提交哈希,现在我需要使用
github java API(org.eclipse.egit.github.*)
获得相同的响应,该API可以在中找到。根据他们在中找到的版本
2.1.5
的文档,在
CommitService类中没有只提供提交散列来获取提交信息的方法。是否有一个解决方法可以接触到他们?提前感谢

您可以使用
CommitService.getCommit(IRepositoryIdProvider,String)
方法,只需再输入一个参数,即搜索提交的存储库。比如说,

GitHubClient client = new GitHubClient(server).setCredentials(login, token);
RepositoryService repoService = new RepositoryService(client);

// If you know which repository to search (you know the owner and repo name)
Repository repository = repoService.getRepository(owner, repoName);

CommitService commitService = new CommitService(client)
Commit commit1 = commitService.getCommit(repository, sha).getCommit();
System.out.println("Author: " + commit1.getAuthor().getName());
System.out.println("Message: " + commit1.getMessage());
System.out.println("URL: " + commit1.getUrl());
List<Repository> repositories = repoService.getRepositories();
Commit commit2 = null;
for (Repository repo : repositories) {
    try {
        commit2 = commitService.getCommit(repo, sha).getCommit();
        System.out.println("Repo: " + repo.getName());
        System.out.println("Author: " + commit2.getAuthor().getName());
        System.out.println("Message: " + commit2.getMessage());
        System.out.println("URL: " + commit2.getUrl());
        break;
    } catch (RequestException re) {
        if (re.getMessage().endsWith("Not Found (404)")) {
            continue;
        } else {
            throw re;
        }
    }
}   
或者,如果您不知道要搜索哪个存储库,您也可以循环遍历从
RepositoryService.getRepositories()
方法返回的每个存储库。比如说,

GitHubClient client = new GitHubClient(server).setCredentials(login, token);
RepositoryService repoService = new RepositoryService(client);

// If you know which repository to search (you know the owner and repo name)
Repository repository = repoService.getRepository(owner, repoName);

CommitService commitService = new CommitService(client)
Commit commit1 = commitService.getCommit(repository, sha).getCommit();
System.out.println("Author: " + commit1.getAuthor().getName());
System.out.println("Message: " + commit1.getMessage());
System.out.println("URL: " + commit1.getUrl());
List<Repository> repositories = repoService.getRepositories();
Commit commit2 = null;
for (Repository repo : repositories) {
    try {
        commit2 = commitService.getCommit(repo, sha).getCommit();
        System.out.println("Repo: " + repo.getName());
        System.out.println("Author: " + commit2.getAuthor().getName());
        System.out.println("Message: " + commit2.getMessage());
        System.out.println("URL: " + commit2.getUrl());
        break;
    } catch (RequestException re) {
        if (re.getMessage().endsWith("Not Found (404)")) {
            continue;
        } else {
            throw re;
        }
    }
}   
List repositories=repoService.getRepositories();
Commit commit2=null;
用于(存储库回购:存储库){
试一试{
commit2=commitService.getCommit(repo,sha).getCommit();
System.out.println(“Repo:+Repo.getName());
System.out.println(“作者:+commit2.getAuthor().getName());
System.out.println(“消息:+commit2.getMessage());
System.out.println(“URL:+commit2.getUrl());
打破
}捕获(请求异常){
if(re.getMessage().endsWith(“找不到(404)”){
继续;
}否则{
投掷re;
}
}
}   

您可以使用CommitService.getCommit(IRepositoryIdProvider,String)
方法,只需再输入一个参数,即搜索提交的存储库。比如说,

GitHubClient client = new GitHubClient(server).setCredentials(login, token);
RepositoryService repoService = new RepositoryService(client);

// If you know which repository to search (you know the owner and repo name)
Repository repository = repoService.getRepository(owner, repoName);

CommitService commitService = new CommitService(client)
Commit commit1 = commitService.getCommit(repository, sha).getCommit();
System.out.println("Author: " + commit1.getAuthor().getName());
System.out.println("Message: " + commit1.getMessage());
System.out.println("URL: " + commit1.getUrl());
List<Repository> repositories = repoService.getRepositories();
Commit commit2 = null;
for (Repository repo : repositories) {
    try {
        commit2 = commitService.getCommit(repo, sha).getCommit();
        System.out.println("Repo: " + repo.getName());
        System.out.println("Author: " + commit2.getAuthor().getName());
        System.out.println("Message: " + commit2.getMessage());
        System.out.println("URL: " + commit2.getUrl());
        break;
    } catch (RequestException re) {
        if (re.getMessage().endsWith("Not Found (404)")) {
            continue;
        } else {
            throw re;
        }
    }
}   
或者,如果您不知道要搜索哪个存储库,您也可以循环遍历从
RepositoryService.getRepositories()
方法返回的每个存储库。比如说,

GitHubClient client = new GitHubClient(server).setCredentials(login, token);
RepositoryService repoService = new RepositoryService(client);

// If you know which repository to search (you know the owner and repo name)
Repository repository = repoService.getRepository(owner, repoName);

CommitService commitService = new CommitService(client)
Commit commit1 = commitService.getCommit(repository, sha).getCommit();
System.out.println("Author: " + commit1.getAuthor().getName());
System.out.println("Message: " + commit1.getMessage());
System.out.println("URL: " + commit1.getUrl());
List<Repository> repositories = repoService.getRepositories();
Commit commit2 = null;
for (Repository repo : repositories) {
    try {
        commit2 = commitService.getCommit(repo, sha).getCommit();
        System.out.println("Repo: " + repo.getName());
        System.out.println("Author: " + commit2.getAuthor().getName());
        System.out.println("Message: " + commit2.getMessage());
        System.out.println("URL: " + commit2.getUrl());
        break;
    } catch (RequestException re) {
        if (re.getMessage().endsWith("Not Found (404)")) {
            continue;
        } else {
            throw re;
        }
    }
}   
List repositories=repoService.getRepositories();
Commit commit2=null;
用于(存储库回购:存储库){
试一试{
commit2=commitService.getCommit(repo,sha).getCommit();
System.out.println(“Repo:+Repo.getName());
System.out.println(“作者:+commit2.getAuthor().getName());
System.out.println(“消息:+commit2.getMessage());
System.out.println(“URL:+commit2.getUrl());
打破
}捕获(请求异常){
if(re.getMessage().endsWith(“找不到(404)”){
继续;
}否则{
投掷re;
}
}
}