Java 从今天开始获取所有提交
我使用此代码从Guthub获取所有提交。我只想从今天开始提交Java 从今天开始获取所有提交,java,github,github-api,Java,Github,Github Api,我使用此代码从Guthub获取所有提交。我只想从今天开始提交 public void listCommits(String user_name, String password) throws IOException { GitHubClient client = new GitHubClient(); client.setCredentials(user_name, password); RepositoryService servic
public void listCommits(String user_name, String password) throws IOException
{
GitHubClient client = new GitHubClient();
client.setCredentials(user_name, password);
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());
CommitService commitService = new CommitService(client);
for (RepositoryCommit commit : commitService.getCommits(get))
{
System.out.println("Repository commit: " + commit.getCommit().getMessage());
System.out.println("Repository commit date : " + commit.getCommit().getCommitter().getDate());
}
}
}
public void listCommits(字符串用户名、字符串密码)引发IOException
{
GitHubClient=new GitHubClient();
客户端.setCredentials(用户名、密码);
RepositoryService=新的RepositoryService(客户端);
List repositories=service.getRepositories();
对于(int i=0;i
有没有办法只从今天起获得提交?知道您正在使用哪个库总是很好的。 Github API具有“自”和“直到”参数: Kohsuke图书馆也提供了这些参数: 使用“自”和“直到”参数将避免您请求不需要的数据和向服务器发出过多请求 该库也可在Maven central获得:
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.77</version>
</dependency>
org.kohsuke
GithubAPI
1.77
下面是对我有用的示例代码:
Properties props = new Properties();
props.setProperty("login", "somebody@somewhere.com");
props.setProperty("password", "YourGithubPassword");
GitHub gitHub = GitHubBuilder.fromProperties(props).build();
GHRepository repository = gitHub.getRepository("your/repo");
Calendar cal = Calendar.getInstance();
cal.set(2014, 0, 4);
Date since = cal.getTime();
cal.set(2014, 0, 14);
Date until = cal.getTime();
GHCommitQueryBuilder queryBuilder = repository.queryCommits().since(since).until(until);
PagedIterable<GHCommit> commits = queryBuilder.list();
Iterator<GHCommit> iterator = commits.iterator();
while (iterator.hasNext()) {
GHCommit commit = iterator.next();
System.out.println("Commit: " + commit.getSHA1() + ", info: " + commit.getCommitShortInfo().getMessage() + ", author: " + commit.getAuthor());
}
Properties=newproperties();
props.setProperty(“登录”somebody@somewhere.com");
props.setProperty(“密码”、“YourGithubPassword”);
GitHub GitHub=GitHubBuilder.fromProperties(props.build();
GHRepository repository=gitHub.getRepository(“您的/repo”);
Calendar cal=Calendar.getInstance();
计算集(2014,0,4);
自日期=cal.getTime();
校准集(2014,0,14);
Date until=cal.getTime();
GHCommitQueryBuilder queryBuilder=repository.queryCommits().begin(自).begin(至);
PagedItemerable提交=queryBuilder.list();
迭代器迭代器=提交.Iterator();
while(iterator.hasNext()){
GHCommit commit=iterator.next();
System.out.println(“提交:“+Commit.getSHA1()+”,信息:“+Commit.getCommitShortInfo().getMessage()+”,作者:“+Commit.getAuthor());
}
知道您在使用哪个库总是很好的。
Github API具有“自”和“直到”参数:
Kohsuke图书馆也提供了这些参数:
使用“自”和“直到”参数将避免您请求不需要的数据和向服务器发出过多请求
该库也可在Maven central获得:
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.77</version>
</dependency>
org.kohsuke
GithubAPI
1.77
下面是对我有用的示例代码:
Properties props = new Properties();
props.setProperty("login", "somebody@somewhere.com");
props.setProperty("password", "YourGithubPassword");
GitHub gitHub = GitHubBuilder.fromProperties(props).build();
GHRepository repository = gitHub.getRepository("your/repo");
Calendar cal = Calendar.getInstance();
cal.set(2014, 0, 4);
Date since = cal.getTime();
cal.set(2014, 0, 14);
Date until = cal.getTime();
GHCommitQueryBuilder queryBuilder = repository.queryCommits().since(since).until(until);
PagedIterable<GHCommit> commits = queryBuilder.list();
Iterator<GHCommit> iterator = commits.iterator();
while (iterator.hasNext()) {
GHCommit commit = iterator.next();
System.out.println("Commit: " + commit.getSHA1() + ", info: " + commit.getCommitShortInfo().getMessage() + ", author: " + commit.getAuthor());
}
Properties=newproperties();
props.setProperty(“登录”somebody@somewhere.com");
props.setProperty(“密码”、“YourGithubPassword”);
GitHub GitHub=GitHubBuilder.fromProperties(props.build();
GHRepository repository=gitHub.getRepository(“您的/repo”);
Calendar cal=Calendar.getInstance();
计算集(2014,0,4);
自日期=cal.getTime();
校准集(2014,0,14);
Date until=cal.getTime();
GHCommitQueryBuilder queryBuilder=repository.queryCommits().begin(自).begin(至);
PagedItemerable提交=queryBuilder.list();
迭代器迭代器=提交.Iterator();
while(iterator.hasNext()){
GHCommit commit=iterator.next();
System.out.println(“提交:“+Commit.getSHA1()+”,信息:“+Commit.getCommitShortInfo().getMessage()+”,作者:“+Commit.getAuthor());
}
看起来我无法过滤结果?或者我错了?我没有从egit github库中找到“自”和“直到”参数,但Kohsuke有这些参数:你能给我一些例子说明我如何使用Kohsuke做到这一点吗?还有一个问题:你能实现以这个用户名列出每个repo中的所有提交吗?可能您需要为存储库实现循环。您必须为每个存储库实现循环。API还具有查找每个用户的所有repo的功能。祝你好运!:)看起来我无法过滤结果?或者我错了?我没有从egit github库中找到“自”和“直到”参数,但Kohsuke有这些参数:你能给我一些例子说明我如何使用Kohsuke做到这一点吗?还有一个问题:你能实现以这个用户名列出每个repo中的所有提交吗?可能您需要为存储库实现循环。您必须为每个存储库实现循环。API还具有查找每个用户的所有repo的功能。祝你好运!:)