How to find out number of commits to a GitHub repo using Octokit?

414 views Asked by At

I have a private repo on GitHub, which I can estimate the number of commits year-to-date is around 611 by looking at the Commits Graph. However, I cannot get that same number using the Octokit gem. I'm not sure if my results are rate limited, or page limited, or both.

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

Also, auto_traversal doesn't seem to have any effect.

1

There are 1 answers

0
Edward J. Stembler On BEST ANSWER

I'm not sure what the deal was with the octokit, though, I switched to the github_api gem and it works:

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