这样我拉出了所有的存储库:
public static void getAllCommitUrlReader() throws MalformedURLException, IOException {
HttpURLConnection httpURLConnection = (HttpURLConnection) new URL(
"https://api.github.com/repositories?since="+ page)
.openConnection();
httpURLConnection.addRequestProperty("User-Agent",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36");
BufferedReader in = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String line = "", inputLine;
while ((inputLine = in.readLine()) != null) {
line += "\n" + inputLine;
//System.out.println(inputLine);
}
in.close();
Arrays.stream(line.split("\"full_name\":")).skip(1).map(av-> av.split(",")[0]).forEach(av -> {String owner = av.substring(2, av.indexOf("/")).trim();
String repoName = av.substring(av.indexOf("/")+1,av.length()-1).trim();
searchCommit(owner,repoName);
});
//Arrays.stream(line.split("\"id\":")).skip(1).map(av-> av.split(",")[0]).forEach(av -> {System.out.println(av.valueOf(av.length()));
//;
//});
// int total = Arrays.stream(line.split("\"total\":")).skip(1).mapToInt(av -> Integer.parseInt(av.split(",")[0])).sum();
// System.out.println(total);
}
这样,我从所有存储库中获得了所有提交:
public static void searchCommit(String owner, String repoName) {
final int size = 25;
final RepositoryId repo = new RepositoryId(owner, repoName);
final String message = " {0} by {1} on {2}";
final CommitService service = new CommitService();
int pages = 1;
Calendar cal = Calendar.getInstance();
cal.set(2019, 1, 1);
Date since = cal.getTime();
cal.set(2020, 1, 1);
Date until = cal.getTime();
for (Collection<RepositoryCommit> commits : service.pageCommits(repo,size)) {
System.out.println("Commit Page " + pages++);
for (RepositoryCommit commit : commits) {
String sha = commit.getSha().substring(0, 7);
String author = commit.getCommit().getAuthor().getName();
Date date = commit.getCommit().getAuthor().getDate();
if(date.after(since) && date.after(until)) {
System.out.println(MessageFormat.format(message, sha, author, date));
}
}
}
}
我首先有两个问题 - 以下是如何按人对提交承诺进行排序。所以 x 人已经承诺了 y。第二个问题-> 但这是个好消息:经过身份验证的请求获得更高的速率限制。查看文档以获取更多详细信息。解决方案是什么。泰来帮忙:)