代码在休息呼叫期间挂起

时间:2016-08-18 18:52:58

标签: java github github-api

我测试了这段代码,以便今天获得所有GitHub提交:

import org.joda.time.DateTime;
import org.kohsuke.github.GHCommit;
import org.kohsuke.github.GHCommitQueryBuilder;
import org.kohsuke.github.GHRepository;
import org.kohsuke.github.GitHub;
import org.kohsuke.github.GitHubBuilder;
import org.kohsuke.github.PagedIterable;

    public void listCommitsToday(String user_name, String password) throws IOException
        {
            // http://stackoverflow.com/questions/39017648/get-all-commits-from-today
            Properties props = new Properties();
            props.setProperty("login", user_name);
            props.setProperty("password", password);

            GitHub gitHub = GitHubBuilder.fromProperties(props).build();

            List<GHRepository> repositories = gitHub.listAllPublicRepositories().asList();

            for (int i = 0; i < repositories.size(); i++)
            {
                GHRepository repository = repositories.get(i);

                Date currentDate = new Date();
                Date start = new DateTime(DateTimeUtil.getDateBeginning(currentDate)).toDate();
                Date end = new DateTime(DateTimeUtil.getDateEnding(currentDate)).toDate();

                GHCommitQueryBuilder queryBuilder = repository.queryCommits().since(start).until(end);
                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());
                }
            }
        }

import java.util.Calendar;
import java.util.Date;

public class DateTimeUtil
{
    public static Date getDateBeginning(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        calendar.set(Calendar.HOUR_OF_DAY, 0);
        calendar.set(Calendar.MINUTE, 0);
        calendar.set(Calendar.SECOND, 0);
        calendar.set(Calendar.MILLISECOND, 0);

        return calendar.getTime();
    }

    public static Date getDateEnding(Date date)
    {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(date);

        calendar.set(Calendar.HOUR_OF_DAY, 23);
        calendar.set(Calendar.MINUTE, 59);
        calendar.set(Calendar.SECOND, 59);
        calendar.set(Calendar.MILLISECOND, 999);

        return calendar.getTime();
    }
}

但代码挂了。没有打印错误消息。可能原因是我今天没有任何提交。

我如何将问题转化为代码?

0 个答案:

没有答案