2014-11-14 81 views
0

我在GitHub上有一個私人回購,我可以通過查看提交圖來估計今年迄今爲止的提交數量約爲611。但是,我無法使用Octokit寶石獲得相同的數字。我不確定我的結果是否受限於速度,或頁面有限,或者兩者兼而有之。如何找到使用Octokit的GitHub倉庫提交數量?

require 'octokit' 

client = Octokit::Client.new(login: 'myuser', password: 'mypassword', auto_traversal: true) 
commits = client.list_commits('my-repo') 

puts commits.size # 30 but should be 611 

commits.each do |c| 
    puts "#{c.commit.committer.date}\t#{c.commit.message}\n" 
end 

另外,auto_traversal似乎沒有任何效果。

回答

0

我不知道是什麼,這筆交易與octokit,不過,我切換到github_api gem和它的作品:

require 'github_api' 


github = Github.new login: 'myuser', password: 'mypassword', auto_pagination: true 
commits = github.repos.commits.all('myrepo-owner', 'myrepo-name') 
ytd_range = (Time.new(2014, 1, 1)..Time.now) 

ytd_commits = commits.select do |c| 
    ytd_range.cover?(Time.parse(c.commit.committer.date)) 
end 

puts ytd_commits.size # 614 
相關問題