从今天获取所有提交 [英] Get all commits from today
问题描述
我使用此代码从Guthub获取所有提交。
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); (RepositoryCommit commit:commitService.getCommits(get))
{
System.out.println(Repository commit:+ commit.getCommit()。getMessage());
System.out.println(Repository commit date:+ commit.getCommit()。getCommitter()。getDate());
$ b有什么办法可以得到仅从今天开始提交?解决方案总是很高兴知道您使用的是哪个库。
Github API具有since和until参数:
https: //developer.github.com/v3/repos/commits/
这些参数也可以在Kohsuke的库中获得:
https://github.com/ kohsuke / github-api / blob / master / src / main / java / org / kohsuke / github / GHCommitQueryBuilder.java $ b 使用since和直到参数将使您免于请求不需要的数据并向服务器发出太多请求。
该库也可在Maven central中获得:
< dependency>
< groupId> org.kohsuke< / groupId>
< artifactId> github-api< / artifactId>
< version> 1.77< / version>
< /依赖关系>
以下是适用于我的示例代码:
Properties props = new Properties();
props.setProperty(login,somebody@somewhere.com);
props.setProperty(password,YourGithubPassword);
GitHub gitHub = GitHubBuilder.fromProperties(道具).build();
GHRepository repository = gitHub.getRepository(your / repo);
日历cal = Calendar.getInstance();
cal.set(2014,0,4);
以来的日期= cal.getTime();
cal.set(2014,0,14);
直到= cal.getTime();
GHCommitQueryBuilder queryBuilder = repository.queryCommits()。since(since).until(until);
PagedIterable< GHCommit>提交= queryBuilder.list();
迭代器< GHCommit> iterator = commits.iterator();
while(iterator.hasNext()){
GHCommit commit = iterator.next();
System.out.println(Commit:+ commit.getSHA1()+,info:+ commit.getCommitShortInfo()。getMessage()+,author:+ commit.getAuthor());
}
I use this code to get all commits from Guthub. I would like to get the commits only from today.
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());
}
}
}
Is there any way to get the commits only from today?
解决方案 Always good to know which library are you using.
Github API has "since" and "until" parameters:
https://developer.github.com/v3/repos/commits/
Also those arguments are available in the Kohsuke's library:
https://github.com/kohsuke/github-api/blob/master/src/main/java/org/kohsuke/github/GHCommitQueryBuilder.java
Using "since" and "until" parameters will save you from requesting unneeded data and making too many requests to the server.
The library is also available in Maven central:
<dependency>
<groupId>org.kohsuke</groupId>
<artifactId>github-api</artifactId>
<version>1.77</version>
</dependency>
Here's the sample code that worked for me:
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());
}
这篇关于从今天获取所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!